mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Prevent AI Triggers from hitting the stack when no legal targets are available
This commit is contained in:
@@ -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")) {
|
||||
|
||||
Reference in New Issue
Block a user