-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDestroySpell.java
80 lines (71 loc) · 2.82 KB
/
DestroySpell.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.entities.Actor;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.logic.GameLogic;
import net.demilich.metastone.game.cards.Attribute;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import net.demilich.metastone.game.targeting.EntityReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.function.Predicate;
/**
* Destroys the {@code target} {@link Actor}.
* <p>
* Actors that are destroyed in this way do not get their hitpoints reduced to zero and are not dealt any damage. They
* receive the {@link Attribute#DESTROYED} attribute, and during an {@link GameLogic#endOfSequence()}, they are moved to
* the {@link com.hiddenswitch.spellsource.rpc.Spellsource.ZonesMessage.Zones#GRAVEYARD} "not peacefully" (i.e., deathrattles will
* trigger).
* <p>
* For example, to destroy all frozen minions:
* <pre>
* {
* "class": "DestroySpell",
* "target": "ALL_MINIONS",
* "filter": {
* "class": "AttributeFilter",
* "attribute": "FROZEN",
* "operation": "HAS"
* }
* }
* </pre>
*
* @see GameLogic#markAsDestroyed(Actor, Entity) for the underlying effect that adds the {@link Attribute#DESTROYED} attribute.
* @see GameLogic#endOfSequence() for more about how minions, heroes and weapons are removed from play.
*/
public class DestroySpell extends Spell {
public static Logger logger = LoggerFactory.getLogger(DestroySpell.class);
public static SpellDesc create() {
return create(null);
}
public static SpellDesc create(EntityReference target) {
return create(target, false);
}
public static SpellDesc create(EntityReference target, boolean randomTarget) {
return create(target, null, randomTarget);
}
public static SpellDesc create(EntityReference target, Predicate<Entity> targetFilter, boolean randomTarget) {
Map<SpellArg, Object> arguments = new SpellDesc(DestroySpell.class);
arguments.put(SpellArg.TARGET, target);
arguments.put(SpellArg.RANDOM_TARGET, randomTarget);
if (targetFilter != null) {
arguments.put(SpellArg.FILTER, targetFilter);
}
return new SpellDesc(arguments);
}
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
checkArguments(logger, context, source, desc);
if (target == null) {
throw new UnsupportedOperationException("must specify a target");
}
// Give the source a kill if the target isn't already destroyed
if (!target.isDestroyed()) {
source.modifyAttribute(Attribute.TOTAL_KILLS, 1);
}
context.getLogic().markAsDestroyed((Actor) target, source);
}
}