diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index 73414353a1f..9c9c0d714da 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -98,7 +98,8 @@ public class AiAttackController { } for (SpellAbility sa : c.getSpellAbilities()) { if (sa.getApi() == ApiType.Animate) { - if (ComputerUtilCost.canPayCost(sa, this.defendingOpponent)) { + if (ComputerUtilCost.canPayCost(sa, this.defendingOpponent) + && sa.getRestrictions().checkOtherRestrictions(c, sa, this.defendingOpponent)) { Card animatedCopy = CardFactory.getCard(c.getPaperCard(), this.defendingOpponent); AnimateAi.becomeAnimated(animatedCopy, sa); this.oppList.add(animatedCopy); diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java index 13eec0f85b9..860238e066e 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java @@ -291,68 +291,11 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { return false; } - - /** - *
- * canPlay. - *
- * - * @param c - * a {@link forge.game.card.Card} object. - * @param sa - * a {@link forge.game.spellability.SpellAbility} object. - * @return a boolean. - */ - public final boolean canPlay(final Card c, final SpellAbility sa) { - if (c.isPhasedOut() || c.isUsedToPay()) { - return false; - } - - Player activator = sa.getActivatingPlayer(); - if (activator == null) { - activator = c.getController(); - sa.setActivatingPlayer(activator); - System.out.println(c.getName() + " Did not have activator set in SpellAbilityRestriction.canPlay()"); - } + + public final boolean checkOtherRestrictions(final Card c, final SpellAbility sa, final Player activator) { final Game game = activator.getGame(); - if (this.isSorcerySpeed() && !activator.canCastSorcery()) { - return false; - } - - if (!checkTimingRestrictions(c, sa)) { - return false; - } - - if (!checkActivatorRestrictions(c, sa)) { - return false; - } - - if (!checkZoneRestrictions(c, sa)) { - return false; - } - - if (this.getLimitToCheck() != null) { - String limit = this.getLimitToCheck(); - int activationLimit = AbilityUtils.calculateAmount(c, limit, sa); - this.setActivationLimit(activationLimit); - - if ((this.getActivationLimit() != -1) && (this.getNumberTurnActivations() >= this.getActivationLimit())) { - return false; - } - } - - if (this.getGameLimitToCheck() != null) { - String limit = this.getGameLimitToCheck(); - int gameActivationLimit = AbilityUtils.calculateAmount(c, limit, sa); - this.setGameActivationLimit(gameActivationLimit); - - if ((this.getGameActivationLimit() != -1) && (this.getNumberGameActivations() >= this.getGameActivationLimit())) { - return false; - } - } - if (this.getCardsInHand() != -1) { if (activator.getCardsIn(ZoneType.Hand).size() != this.getCardsInHand()) { return false; @@ -430,7 +373,6 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { } if (this.isPwAbility()) { - for (final SpellAbility pwAbs : c.getAllSpellAbilities()) { // check all abilities on card that have their planeswalker // restriction set to confirm they haven't been activated @@ -460,6 +402,71 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { } } + return true; + } + + /** + *+ * canPlay. + *
+ * + * @param c + * a {@link forge.game.card.Card} object. + * @param sa + * a {@link forge.game.spellability.SpellAbility} object. + * @return a boolean. + */ + public final boolean canPlay(final Card c, final SpellAbility sa) { + if (c.isPhasedOut() || c.isUsedToPay()) { + return false; + } + + Player activator = sa.getActivatingPlayer(); + if (activator == null) { + activator = c.getController(); + sa.setActivatingPlayer(activator); + System.out.println(c.getName() + " Did not have activator set in SpellAbilityRestriction.canPlay()"); + } + + if (this.isSorcerySpeed() && !activator.canCastSorcery()) { + return false; + } + + if (!checkTimingRestrictions(c, sa)) { + return false; + } + + if (!checkActivatorRestrictions(c, sa)) { + return false; + } + + if (!checkZoneRestrictions(c, sa)) { + return false; + } + + if (!checkOtherRestrictions(c, sa, activator)) { + return false; + } + + if (this.getLimitToCheck() != null) { + String limit = this.getLimitToCheck(); + int activationLimit = AbilityUtils.calculateAmount(c, limit, sa); + this.setActivationLimit(activationLimit); + + if ((this.getActivationLimit() != -1) && (this.getNumberTurnActivations() >= this.getActivationLimit())) { + return false; + } + } + + if (this.getGameLimitToCheck() != null) { + String limit = this.getGameLimitToCheck(); + int gameActivationLimit = AbilityUtils.calculateAmount(c, limit, sa); + this.setGameActivationLimit(gameActivationLimit); + + if ((this.getGameActivationLimit() != -1) && (this.getNumberGameActivations() >= this.getGameActivationLimit())) { + return false; + } + } return true; } // canPlay()