-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathEitherOrSpell.java
64 lines (59 loc) · 2.12 KB
/
EitherOrSpell.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
package net.demilich.metastone.game.spells;
import net.demilich.metastone.game.GameContext;
import net.demilich.metastone.game.Player;
import net.demilich.metastone.game.entities.Entity;
import net.demilich.metastone.game.spells.desc.SpellArg;
import net.demilich.metastone.game.spells.desc.SpellDesc;
import net.demilich.metastone.game.spells.desc.condition.Condition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Casts {@link SpellArg#SPELL1} if {@link SpellArg#CONDITION} is fulfilled, otherwise, casts {@link SpellArg#SPELL2}.
* <p>
* The condition is evaluated with respect to the {@code target}.
* <p>
* For example, to implement the text, "Deal 8 damage to a minion. If it's a friendly Demon, give it +8/+8 instead.":
* <pre>
* {
* "class": "EitherOrSpell",
* "condition": {
* "class": "AndCondition",
* "conditions": [
* {
* "class": "OwnedByPlayerCondition",
* "targetPlayer": "SELF"
* },
* {
* "class": "RaceCondition",
* "race": "DEMON"
* }
* ]
* },
* "spell1": {
* "class": "BuffSpell",
* "attackBonus": 8,
* "hpBonus": 8
* },
* "spell2": {
* "class": "DamageSpell",
* "value": 8
* }
* }
* </pre>
*/
public class EitherOrSpell extends Spell {
private static Logger logger = LoggerFactory.getLogger(EitherOrSpell.class);
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
checkArguments(logger, context, source, desc, SpellArg.CONDITION, SpellArg.SPELL1, SpellArg.SPELL2);
Condition condition = (Condition) desc.get(SpellArg.CONDITION);
SpellDesc either = (SpellDesc) desc.get(SpellArg.SPELL1);
SpellDesc or = (SpellDesc) desc.get(SpellArg.SPELL2);
if (desc.containsKey(SpellArg.CARD)) {
either.put(SpellArg.CARD, desc.get(SpellArg.CARD));
or.put(SpellArg.CARD, desc.get(SpellArg.CARD));
}
SpellDesc spellToCast = condition.isFulfilled(context, player, source, target) ? either : or;
SpellUtils.castChildSpell(context, player, spellToCast, source, target);
}
}