-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathFirstConditionalSpell.java
More file actions
26 lines (23 loc) · 1001 Bytes
/
FirstConditionalSpell.java
File metadata and controls
26 lines (23 loc) · 1001 Bytes
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
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;
/**
* Like {@link ConditionalSpell}, except executes the first matching condition.
*/
public final class FirstConditionalSpell extends ConditionalSpell {
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
Condition[] conditions = (Condition[]) desc.get(SpellArg.CONDITIONS);
SpellDesc[] spells = (SpellDesc[]) desc.get(SpellArg.SPELLS);
for (int i = 0; i < conditions.length; i++) {
if (conditions[i].isFulfilled(context, player, source, target)) {
SpellUtils.castChildSpell(context, player, spells[i], source, target);
return;
}
}
}
}