-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathModifyWitherAttributeSpell.java
63 lines (58 loc) · 2.65 KB
/
ModifyWitherAttributeSpell.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
package net.demilich.metastone.game.spells;
import com.google.common.base.Objects;
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.SpellDesc;
import net.demilich.metastone.game.spells.desc.trigger.EnchantmentDesc;
import net.demilich.metastone.game.spells.desc.trigger.EventTriggerArg;
import net.demilich.metastone.game.spells.desc.trigger.EventTriggerDesc;
import net.demilich.metastone.game.spells.trigger.DamageCausedTrigger;
import net.demilich.metastone.game.spells.trigger.Enchantment;
import net.demilich.metastone.game.spells.trigger.Trigger;
import net.demilich.metastone.game.targeting.EntityReference;
import net.demilich.metastone.game.targeting.TargetType;
import java.util.List;
/**
* Gives a minion {@link net.demilich.metastone.game.cards.Attribute#WITHER} and the appropriate trigger if it does not
* already have it.
*/
public final class ModifyWitherAttributeSpell extends ModifyAttributeSpell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
super.onCast(context, player, desc, source, target);
List<Trigger> triggers = context.getLogic().getActiveTriggers(target.getReference());
/*
* {
* "eventTrigger": {
* "class": "DamageCausedTrigger",
* "hostTargetType": "IGNORE_OTHER_SOURCES"
* },
* "spell": {
* "class": "WitherSpell",
* "target": "EVENT_TARGET"
* }
* }
*/
for (Trigger trigger : triggers) {
if (isWitherEnchantment(trigger)) {
return;
}
}
EnchantmentDesc witherEnchantment = new EnchantmentDesc();
witherEnchantment.setEventTrigger(new EventTriggerDesc(DamageCausedTrigger.class));
witherEnchantment.getEventTrigger().put(EventTriggerArg.HOST_TARGET_TYPE, TargetType.IGNORE_OTHER_SOURCES);
witherEnchantment.setSpell(new SpellDesc(WitherSpell.class, EntityReference.EVENT_TARGET, null, false));
SpellUtils.castChildSpell(context, player, AddEnchantmentSpell.create(witherEnchantment), source, target);
}
private boolean isWitherEnchantment(Trigger trigger) {
if (!(trigger instanceof Enchantment)) {
return false;
}
Enchantment enchantment = (Enchantment) trigger;
return enchantment.getTriggers().size() == 1
&& enchantment.getTriggers().get(0).getClass().equals(DamageCausedTrigger.class)
&& Objects.equal(enchantment.getTriggers().get(0).getDesc().get(EventTriggerArg.HOST_TARGET_TYPE), TargetType.IGNORE_OTHER_SOURCES)
&& enchantment.getSpell() != null && enchantment.getSpell().getDescClass().equals(WitherSpell.class);
}
}