mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +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;
|
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()) {
|
if (sp.isSpell()) {
|
||||||
source.setController(activator, 0);
|
source.setController(activator, 0);
|
||||||
final Spell spell = (Spell) sp;
|
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) {
|
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
|
// Check if the spellability is a trigger that was invalidated with fizzleTriggersOnStackTargeting
|
||||||
if (sa.getSVar("TriggerFizzled").equals("True")) {
|
if (sa.getSVar("TriggerFizzled").equals("True")) {
|
||||||
|
|||||||
Reference in New Issue
Block a user