-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathMisdirectSpell.java
43 lines (39 loc) · 1.84 KB
/
MisdirectSpell.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
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.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;
/**
* Misdirection overrides the {@link EntityReference#ATTACKER}'s current target to another random target within {@link
* SpellArg#SECONDARY_TARGET}.
* <p>
* By default, another character is chosen from {@link EntityReference#ALL_CHARACTERS}.
* <p>
* The attacker itself is always excluded from the possible misdirection.
*
* @see OverrideTargetSpell for a more general target override function.
* @see FightSpell to cause an actor to attack a target generally.
*/
public class MisdirectSpell extends Spell {
private static Logger logger = LoggerFactory.getLogger(MisdirectSpell.class);
@Override
protected void onCast(GameContext context, Player player, SpellDesc desc, Entity source, Entity target) {
Actor attacker = (Actor) context.resolveSingleTarget(context.getAttackerReferenceStack().peek());
if (attacker == null) {
logger.warn("onCast: Cannot misdirect a null attacker.");
return;
}
if (attacker.isDestroyed()) {
logger.debug("onCast: The attack who was selected to misdirect is already destroyed.");
return;
}
EntityReference secondaryTarget = desc.containsKey(SpellArg.SECONDARY_TARGET) ? (EntityReference) desc.get(SpellArg.SECONDARY_TARGET) : EntityReference.ALL_CHARACTERS;
Actor randomTarget = context.getLogic().getAnotherRandomTarget(player, attacker, (Actor) target, secondaryTarget);
context.setTargetOverride(randomTarget.getReference());
}
}