-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathAbstractModifyEnchantmentSpell.java
More file actions
35 lines (31 loc) · 1.2 KB
/
AbstractModifyEnchantmentSpell.java
File metadata and controls
35 lines (31 loc) · 1.2 KB
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
package net.demilich.metastone.game.spells;
import com.hiddenswitch.spellsource.rpc.Spellsource.EntityTypeMessage.EntityType;
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.trigger.Enchantment;
/**
* A base class for spells that modify the enchantments hosted by {@code target} or the {@code target} itself if it is
* an enchantment.
*/
public abstract class AbstractModifyEnchantmentSpell extends Spell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
if (target.getEntityType() == EntityType.ENCHANTMENT) {
var enchantment = (Enchantment) target;
modifyEnchantment(enchantment);
} else {
var triggers = context.getLogic().getActiveTriggers(target.getReference());
for (var trigger : triggers) {
if (trigger instanceof Enchantment) {
var enchantment = (Enchantment) trigger;
modifyEnchantment(enchantment);
}
}
}
}
protected void modifyEnchantment(Enchantment enchantment) {
enchantment.setActivated(false);
}
}