- Prevent AI Triggers from hitting the stack when no legal targets are available

This commit is contained in:
Sol
2016-06-02 12:35:39 +00:00
parent f469196f99
commit c760b425e4

View File

@@ -232,6 +232,11 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
return;
}
if (!hasLegalTargeting(sp, source)) {
game.getGameLog().add(GameLogEntryType.STACK_ADD, source + " - [Couldn't add to stack, failed to target] - " + sp.getDescription());
return;
}
if (sp.isSpell()) {
source.setController(activator, 0);
final Spell spell = (Spell) sp;
@@ -627,6 +632,20 @@ public class MagicStack /* extends MyObservable */ implements Iterable<SpellAbil
}
}
public final boolean hasLegalTargeting(final SpellAbility sa, final Card source) {
if (sa == null) {
return true;
}
TargetRestrictions tgt = sa.getTargetRestrictions();
if (tgt != null) {
int numTargets = sa.getTargets().getNumTargeted();
if (tgt.getMinTargets(source, sa) > numTargets || (tgt.getMaxTargets(source, sa) < numTargets)) {
return false;
}
}
return hasLegalTargeting(sa.getSubAbility(), source);
}
private final boolean hasFizzled(final SpellAbility sa, final Card source, final Boolean parentFizzled) {
// Check if the spellability is a trigger that was invalidated with fizzleTriggersOnStackTargeting
if (sa.getSVar("TriggerFizzled").equals("True")) {