diff --git a/src/main/java/forge/StaticEffects.java b/src/main/java/forge/StaticEffects.java index 0ddbb669f96..3f54e1effdb 100644 --- a/src/main/java/forge/StaticEffects.java +++ b/src/main/java/forge/StaticEffects.java @@ -25,6 +25,7 @@ import java.util.List; import com.esotericsoftware.minlog.Log; +import forge.card.TriggerReplacementBase; import forge.card.replacement.ReplacementEffect; import forge.card.spellability.SpellAbility; import forge.card.staticability.StaticAbility; @@ -236,7 +237,7 @@ public class StaticEffects { stA.setTemporarilySuppressed(false); } final ArrayList replacementEffects = affectedCard.getReplacementEffects(); - for (final ReplacementEffect rE : replacementEffects) { + for (final TriggerReplacementBase rE : replacementEffects) { rE.setTemporarilySuppressed(false); } } diff --git a/src/main/java/forge/card/TriggerReplacementBase.java b/src/main/java/forge/card/TriggerReplacementBase.java index 1ab478a4d51..1b4e7a713db 100644 --- a/src/main/java/forge/card/TriggerReplacementBase.java +++ b/src/main/java/forge/card/TriggerReplacementBase.java @@ -1,13 +1,22 @@ package forge.card; +import java.util.ArrayList; import java.util.EnumSet; +import java.util.List; +import java.util.Map; import forge.Card; +import forge.CardLists; +import forge.CardUtil; import forge.GameEntity; +import forge.Singletons; +import forge.card.ability.AbilityUtils; import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.SpellAbility; +import forge.game.player.Player; import forge.game.zone.Zone; import forge.game.zone.ZoneType; +import forge.util.Expressions; /** * Base class for Triggers and ReplacementEffects. @@ -144,4 +153,174 @@ public abstract class TriggerReplacementBase { public final boolean isSuppressed() { return (this.suppressed || this.temporarilySuppressed); } + + protected boolean meetsCommonRequirements(Map params) { + + Player hostController = this.getHostCard().getController(); + + if ("True".equalsIgnoreCase(params.get("Metalcraft")) && !hostController.hasMetalcraft()) return false; + if ("True".equalsIgnoreCase(params.get("Threshold")) && !hostController.hasThreshold()) return false; + if ("True".equalsIgnoreCase(params.get("Hellbent")) && !hostController.hasHellbent()) return false; + if ("True".equalsIgnoreCase(params.get("Bloodthirst")) && !hostController.hasBloodthirst()) return false; + if ("True".equalsIgnoreCase(params.get("FatefulHour")) && hostController.getLife() > 5) return false; + + if ("You".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getPoisonCounters() == 0) return false; + if ("Opponent".equalsIgnoreCase(params.get("PlayersPoisoned")) && hostController.getOpponent().getPoisonCounters() == 0) return false; + if ("Each".equalsIgnoreCase(params.get("PlayersPoisoned"))) { + for( Player p : Singletons.getModel().getGame().getPlayers()) + if( p.getPoisonCounters() == 0 ) + return false; + } + + if (params.containsKey("LifeTotal")) { + final String player = params.get("LifeTotal"); + String lifeCompare = "GE1"; + int life = 1; + + if (player.equals("You")) { + life = hostController.getLife(); + } + if (player.equals("Opponent")) { + life = hostController.getOpponent().getLife(); + } + + if (params.containsKey("LifeAmount")) { + lifeCompare = params.get("LifeAmount"); + } + + int right = 1; + final String rightString = lifeCompare.substring(2); + try { + right = Integer.parseInt(rightString); + } catch (final NumberFormatException nfe) { + right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar(rightString)); + } + + if (!Expressions.compare(life, lifeCompare, right)) { + return false; + } + } + + + if (params.containsKey("IsPresent")) { + final String sIsPresent = params.get("IsPresent"); + String presentCompare = "GE1"; + ZoneType presentZone = ZoneType.Battlefield; + String presentPlayer = "Any"; + if (params.containsKey("PresentCompare")) { + presentCompare = params.get("PresentCompare"); + } + if (params.containsKey("PresentZone")) { + presentZone = ZoneType.smartValueOf(params.get("PresentZone")); + } + if (params.containsKey("PresentPlayer")) { + presentPlayer = params.get("PresentPlayer"); + } + List list = new ArrayList(); + if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { + list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); + } + if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { + list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); + } + + list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); + + int right = 1; + final String rightString = presentCompare.substring(2); + if (rightString.equals("X")) { + right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); + } else { + right = Integer.parseInt(presentCompare.substring(2)); + } + final int left = list.size(); + + if (!Expressions.compare(left, presentCompare, right)) { + return false; + } + + } + + if (params.containsKey("IsPresent2")) { + final String sIsPresent = params.get("IsPresent2"); + String presentCompare = "GE1"; + ZoneType presentZone = ZoneType.Battlefield; + String presentPlayer = "Any"; + if (params.containsKey("PresentCompare2")) { + presentCompare = params.get("PresentCompare2"); + } + if (params.containsKey("PresentZone2")) { + presentZone = ZoneType.smartValueOf(params.get("PresentZone2")); + } + if (params.containsKey("PresentPlayer2")) { + presentPlayer = params.get("PresentPlayer2"); + } + List list = new ArrayList(); + if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { + list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); + } + if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { + list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); + } + + list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); + + int right = 1; + final String rightString = presentCompare.substring(2); + if (rightString.equals("X")) { + right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); + } else { + right = Integer.parseInt(presentCompare.substring(2)); + } + final int left = list.size(); + + if (!Expressions.compare(left, presentCompare, right)) { + return false; + } + + } + + if (params.containsKey("CheckSVar")) { + final int sVar = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), params.get("CheckSVar"), null); + String comparator = "GE1"; + if (params.containsKey("SVarCompare")) { + comparator = params.get("SVarCompare"); + } + final String svarOperator = comparator.substring(0, 2); + final String svarOperand = comparator.substring(2); + final int operandValue = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), + svarOperand, null); + if (!Expressions.compare(sVar, svarOperator, operandValue)) { + return false; + } + } + + if (params.containsKey("ManaSpent")) { + if (!this.getHostCard().getColorsPaid().contains(params.get("ManaSpent"))) { + return false; + } + } + + if (params.containsKey("ManaNotSpent")) { + if (this.getHostCard().getColorsPaid().contains(params.get("ManaNotSpent"))) { + return false; + } + } + + if (params.containsKey("WerewolfTransformCondition")) { + if (CardUtil.getLastTurnCast("Card", this.getHostCard()).size() > 0) { + return false; + } + } + + if (params.containsKey("WerewolfUntransformCondition")) { + final List you = CardUtil.getLastTurnCast("Card.YouCtrl", this.getHostCard()); + final List opp = CardUtil.getLastTurnCast("Card.YouDontCtrl", this.getHostCard()); + if (!((you.size() > 1) || (opp.size() > 1))) { + return false; + } + } + + return true; + } } diff --git a/src/main/java/forge/card/ability/effects/AnimateAllEffect.java b/src/main/java/forge/card/ability/effects/AnimateAllEffect.java index ed715ec7bad..79eb919bc8b 100644 --- a/src/main/java/forge/card/ability/effects/AnimateAllEffect.java +++ b/src/main/java/forge/card/ability/effects/AnimateAllEffect.java @@ -10,6 +10,7 @@ import forge.CardLists; import forge.CardUtil; import forge.Command; import forge.Singletons; +import forge.card.TriggerReplacementBase; import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityUtils; import forge.card.replacement.ReplacementEffect; @@ -234,7 +235,7 @@ public class AnimateAllEffect extends AnimateEffectBase { } // give back suppressed replacement effects - for (final ReplacementEffect re : removedReplacements) { + for (final TriggerReplacementBase re : removedReplacements) { re.setTemporarilySuppressed(false); } } diff --git a/src/main/java/forge/card/ability/effects/AnimateEffect.java b/src/main/java/forge/card/ability/effects/AnimateEffect.java index 6617731251f..34600c9e16b 100644 --- a/src/main/java/forge/card/ability/effects/AnimateEffect.java +++ b/src/main/java/forge/card/ability/effects/AnimateEffect.java @@ -9,6 +9,7 @@ import forge.Card; import forge.CardUtil; import forge.Command; import forge.Singletons; +import forge.card.TriggerReplacementBase; import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityUtils; import forge.card.replacement.ReplacementEffect; @@ -255,7 +256,7 @@ public class AnimateEffect extends AnimateEffectBase { } // give back suppressed replacement effects - for (final ReplacementEffect re : removedReplacements) { + for (final TriggerReplacementBase re : removedReplacements) { re.setTemporarilySuppressed(false); } } diff --git a/src/main/java/forge/card/replacement/ReplacementEffect.java b/src/main/java/forge/card/replacement/ReplacementEffect.java index bd15431911d..6e35ad5008f 100644 --- a/src/main/java/forge/card/replacement/ReplacementEffect.java +++ b/src/main/java/forge/card/replacement/ReplacementEffect.java @@ -17,13 +17,11 @@ */ package forge.card.replacement; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import forge.Card; -import forge.CardLists; -import forge.CardUtil; import forge.Singletons; import forge.card.TriggerReplacementBase; import forge.card.ability.AbilityUtils; @@ -31,7 +29,6 @@ import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.SpellAbility; import forge.game.phase.PhaseType; import forge.game.player.AIPlayer; -import forge.game.zone.ZoneType; import forge.util.Expressions; /** @@ -175,46 +172,24 @@ public abstract class ReplacementEffect extends TriggerReplacementBase { * @return a boolean. */ public boolean requirementsCheck() { + return this.requirementsCheck(this.getMapParams()); + } + + public boolean requirementsCheck(Map params) { if (this.isSuppressed()) { return false; // Effect removed by effect } - if (this.getMapParams().containsKey("Metalcraft")) { - if (this.getMapParams().get("Metalcraft").equals("True") - && !this.getHostCard().getController().hasMetalcraft()) { + if (params.containsKey("PlayerTurn")) { + if (params.get("PlayerTurn").equals("True") && !Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(this.getHostCard().getController())) { return false; } } - if (this.getMapParams().containsKey("Threshold")) { - if (this.getMapParams().get("Threshold").equals("True") - && !this.getHostCard().getController().hasThreshold()) { - return false; - } - } - - if (this.getMapParams().containsKey("Hellbent")) { - if (this.getMapParams().get("Hellbent").equals("True") && !this.getHostCard().getController().hasHellbent()) { - return false; - } - } - - if (this.getMapParams().containsKey("Bloodthirst")) { - if (this.getMapParams().get("Bloodthirst").equals("True") && !this.getHostCard().getController().hasBloodthirst()) { - return false; - } - } - - if (this.getMapParams().containsKey("PlayerTurn")) { - if (this.getMapParams().get("PlayerTurn").equals("True") && !Singletons.getModel().getGame().getPhaseHandler().isPlayerTurn(this.getHostCard().getController())) { - return false; - } - } - - if (this.getMapParams().containsKey("ActivePhases")) { + if (params.containsKey("ActivePhases")) { boolean isPhase = false; - List aPhases = PhaseType.parseRange(this.getMapParams().get("ActivePhases")); + List aPhases = PhaseType.parseRange(params.get("ActivePhases")); final PhaseType currPhase = Singletons.getModel().getGame().getPhaseHandler().getPhase(); for (final PhaseType s : aPhases) { if (s == currPhase) { @@ -226,171 +201,7 @@ public abstract class ReplacementEffect extends TriggerReplacementBase { return isPhase; } - if (this.getMapParams().containsKey("PlayersPoisoned")) { - if (this.getMapParams().get("PlayersPoisoned").equals("You") - && (this.getHostCard().getController().getPoisonCounters() == 0)) { - return false; - } else if (this.getMapParams().get("PlayersPoisoned").equals("Opponent") - && (this.getHostCard().getController().getOpponent().getPoisonCounters() == 0)) { - return false; - } else if (this.getMapParams().get("PlayersPoisoned").equals("Each") - && !((this.getHostCard().getController().getPoisonCounters() != 0) && (this.getHostCard() - .getController().getPoisonCounters() != 0))) { - return false; - } - } - - if (this.getMapParams().containsKey("LifeTotal")) { - final String player = this.getMapParams().get("LifeTotal"); - String lifeCompare = "GE1"; - int life = 1; - - if (player.equals("You")) { - life = this.getHostCard().getController().getLife(); - } - if (player.equals("Opponent")) { - life = this.getHostCard().getController().getOpponent().getLife(); - } - - if (this.getMapParams().containsKey("LifeAmount")) { - lifeCompare = this.getMapParams().get("LifeAmount"); - } - - int right = 1; - final String rightString = lifeCompare.substring(2); - try { - right = Integer.parseInt(rightString); - } catch (final NumberFormatException nfe) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar(rightString)); - } - - if (!Expressions.compare(life, lifeCompare, right)) { - return false; - } - - } - - if (this.getMapParams().containsKey("IsPresent")) { - final String sIsPresent = this.getMapParams().get("IsPresent"); - String presentCompare = "GE1"; - ZoneType presentZone = ZoneType.Battlefield; - String presentPlayer = "Any"; - if (this.getMapParams().containsKey("PresentCompare")) { - presentCompare = this.getMapParams().get("PresentCompare"); - } - if (this.getMapParams().containsKey("PresentZone")) { - presentZone = ZoneType.smartValueOf(this.getMapParams().get("PresentZone")); - } - if (this.getMapParams().containsKey("PresentPlayer")) { - presentPlayer = this.getMapParams().get("PresentPlayer"); - } - List list = new ArrayList(); - if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); - } - if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); - } - - list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); - - int right = 1; - final String rightString = presentCompare.substring(2); - if (rightString.equals("X")) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); - } else { - right = Integer.parseInt(presentCompare.substring(2)); - } - final int left = list.size(); - - if (!Expressions.compare(left, presentCompare, right)) { - return false; - } - - } - - if (this.getMapParams().containsKey("IsPresent2")) { - final String sIsPresent = this.getMapParams().get("IsPresent2"); - String presentCompare = "GE1"; - ZoneType presentZone = ZoneType.Battlefield; - String presentPlayer = "Any"; - if (this.getMapParams().containsKey("PresentCompare2")) { - presentCompare = this.getMapParams().get("PresentCompare2"); - } - if (this.getMapParams().containsKey("PresentZone2")) { - presentZone = ZoneType.smartValueOf(this.getMapParams().get("PresentZone2")); - } - if (this.getMapParams().containsKey("PresentPlayer2")) { - presentPlayer = this.getMapParams().get("PresentPlayer2"); - } - List list = new ArrayList(); - if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); - } - if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); - } - - list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); - - int right = 1; - final String rightString = presentCompare.substring(2); - if (rightString.equals("X")) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); - } else { - right = Integer.parseInt(presentCompare.substring(2)); - } - final int left = list.size(); - - if (!Expressions.compare(left, presentCompare, right)) { - return false; - } - - } - - if (this.getMapParams().containsKey("CheckSVar")) { - final int sVar = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), this - .getMapParams().get("CheckSVar"), null); - String comparator = "GE1"; - if (this.getMapParams().containsKey("SVarCompare")) { - comparator = this.getMapParams().get("SVarCompare"); - } - final String svarOperator = comparator.substring(0, 2); - final String svarOperand = comparator.substring(2); - final int operandValue = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), - svarOperand, null); - if (!Expressions.compare(sVar, svarOperator, operandValue)) { - return false; - } - } - - if (this.getMapParams().containsKey("ManaSpent")) { - if (!this.getHostCard().getColorsPaid().contains(this.getMapParams().get("ManaSpent"))) { - return false; - } - } - - if (this.getMapParams().containsKey("ManaNotSpent")) { - if (this.getHostCard().getColorsPaid().contains(this.getMapParams().get("ManaNotSpent"))) { - return false; - } - } - - if (this.getMapParams().containsKey("WerewolfTransformCondition")) { - if (CardUtil.getLastTurnCast("Card", this.getHostCard()).size() > 0) { - return false; - } - } - - if (this.getMapParams().containsKey("WerewolfUntransformCondition")) { - final List you = CardUtil.getLastTurnCast("Card.YouCtrl", this.getHostCard()); - final List opp = CardUtil.getLastTurnCast("Card.YouDontCtrl", this.getHostCard()); - if (!((you.size() > 1) || (opp.size() > 1))) { - return false; - } - } - - return true; + return meetsCommonRequirements(params); } /** diff --git a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java index 7b689b093c9..71e8894d120 100644 --- a/src/main/java/forge/card/staticability/StaticAbilityContinuous.java +++ b/src/main/java/forge/card/staticability/StaticAbilityContinuous.java @@ -30,6 +30,7 @@ import forge.CardUtil; import forge.StaticEffect; import forge.StaticEffects; import forge.card.CardType; +import forge.card.TriggerReplacementBase; import forge.card.ability.AbilityFactory; import forge.card.ability.AbilityUtils; import forge.card.cardfactory.CardFactoryUtil; @@ -436,7 +437,7 @@ public class StaticAbilityContinuous { stA.setTemporarilySuppressed(true); } final ArrayList replacementEffects = affectedCard.getReplacementEffects(); - for (final ReplacementEffect rE : replacementEffects) { + for (final TriggerReplacementBase rE : replacementEffects) { rE.setTemporarilySuppressed(true); } } diff --git a/src/main/java/forge/card/trigger/Trigger.java b/src/main/java/forge/card/trigger/Trigger.java index 354b35c2ab8..4a49542f52a 100644 --- a/src/main/java/forge/card/trigger/Trigger.java +++ b/src/main/java/forge/card/trigger/Trigger.java @@ -24,19 +24,14 @@ import java.util.Map; import forge.Card; -import forge.CardLists; -import forge.CardUtil; import forge.Singletons; import forge.card.TriggerReplacementBase; -import forge.card.ability.AbilityUtils; -import forge.card.cardfactory.CardFactoryUtil; import forge.card.spellability.Ability; import forge.card.spellability.SpellAbility; import forge.game.phase.PhaseHandler; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.zone.ZoneType; -import forge.util.Expressions; /** *

@@ -276,77 +271,7 @@ public abstract class Trigger extends TriggerReplacementBase { * a {@link java.util.HashMap} object. * @return a boolean. */ - public final boolean requirementsCheck(final java.util.Map runParams2) { - if (this.getMapParams().containsKey("FatefulHour")) { - if (this.getMapParams().get("FatefulHour").equals("True") - && !(this.getHostCard().getController().getLife() <= 5)) { - return false; - } - } - - if (this.getMapParams().containsKey("Metalcraft")) { - if (this.getMapParams().get("Metalcraft").equals("True") - && !this.getHostCard().getController().hasMetalcraft()) { - return false; - } - } - - if (this.getMapParams().containsKey("Threshold")) { - if (this.getMapParams().get("Threshold").equals("True") - && !this.getHostCard().getController().hasThreshold()) { - return false; - } - } - - if (this.getMapParams().containsKey("Hellbent")) { - if (this.getMapParams().get("Hellbent").equals("True") && !this.getHostCard().getController().hasHellbent()) { - return false; - } - } - - if (this.getMapParams().containsKey("PlayersPoisoned")) { - if (this.getMapParams().get("PlayersPoisoned").equals("You") - && (this.getHostCard().getController().getPoisonCounters() == 0)) { - return false; - } else if (this.getMapParams().get("PlayersPoisoned").equals("Opponent") - && (this.getHostCard().getController().getOpponent().getPoisonCounters() == 0)) { - return false; - } else if (this.getMapParams().get("PlayersPoisoned").equals("Each") - && !((this.getHostCard().getController().getPoisonCounters() != 0) && (this.getHostCard() - .getController().getPoisonCounters() != 0))) { - return false; - } - } - - if (this.getMapParams().containsKey("LifeTotal")) { - final String player = this.getMapParams().get("LifeTotal"); - String lifeCompare = "GE1"; - int life = 1; - - if (player.equals("You")) { - life = this.getHostCard().getController().getLife(); - } - if (player.equals("Opponent")) { - life = this.getHostCard().getController().getOpponent().getLife(); - } - - if (this.getMapParams().containsKey("LifeAmount")) { - lifeCompare = this.getMapParams().get("LifeAmount"); - } - - int right = 1; - final String rightString = lifeCompare.substring(2); - try { - right = Integer.parseInt(rightString); - } catch (final NumberFormatException nfe) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar(rightString)); - } - - if (!Expressions.compare(life, lifeCompare, right)) { - return false; - } - - } + public final boolean requirementsCheck(final Map runParams2) { if (this.getMapParams().containsKey("APlayerHasMoreLifeThanEachOther")) { int highestLife = -50; // Negative base just in case a few Lich's or Platinum Angels are running around @@ -387,126 +312,9 @@ public abstract class Trigger extends TriggerReplacementBase { return false; } } - - if (this.getMapParams().containsKey("IsPresent")) { - final String sIsPresent = this.getMapParams().get("IsPresent"); - String presentCompare = "GE1"; - ZoneType presentZone = ZoneType.Battlefield; - String presentPlayer = "Any"; - if (this.getMapParams().containsKey("PresentCompare")) { - presentCompare = this.getMapParams().get("PresentCompare"); - } - if (this.getMapParams().containsKey("PresentZone")) { - presentZone = ZoneType.smartValueOf(this.getMapParams().get("PresentZone")); - } - if (this.getMapParams().containsKey("PresentPlayer")) { - presentPlayer = this.getMapParams().get("PresentPlayer"); - } - List list = new ArrayList(); - if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); - } - if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); - } - - list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); - - int right = 1; - final String rightString = presentCompare.substring(2); - if (rightString.equals("X")) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); - } else { - right = Integer.parseInt(presentCompare.substring(2)); - } - final int left = list.size(); - - if (!Expressions.compare(left, presentCompare, right)) { - return false; - } - - } - - if (this.getMapParams().containsKey("IsPresent2")) { - final String sIsPresent = this.getMapParams().get("IsPresent2"); - String presentCompare = "GE1"; - ZoneType presentZone = ZoneType.Battlefield; - String presentPlayer = "Any"; - if (this.getMapParams().containsKey("PresentCompare2")) { - presentCompare = this.getMapParams().get("PresentCompare2"); - } - if (this.getMapParams().containsKey("PresentZone2")) { - presentZone = ZoneType.smartValueOf(this.getMapParams().get("PresentZone2")); - } - if (this.getMapParams().containsKey("PresentPlayer2")) { - presentPlayer = this.getMapParams().get("PresentPlayer2"); - } - List list = new ArrayList(); - if (presentPlayer.equals("You") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getCardsIn(presentZone)); - } - if (presentPlayer.equals("Opponent") || presentPlayer.equals("Any")) { - list.addAll(this.getHostCard().getController().getOpponent().getCardsIn(presentZone)); - } - - list = CardLists.getValidCards(list, sIsPresent.split(","), this.getHostCard().getController(), this.getHostCard()); - - int right = 1; - final String rightString = presentCompare.substring(2); - if (rightString.equals("X")) { - right = CardFactoryUtil.xCount(this.getHostCard(), this.getHostCard().getSVar("X")); - } else { - right = Integer.parseInt(presentCompare.substring(2)); - } - final int left = list.size(); - - if (!Expressions.compare(left, presentCompare, right)) { - return false; - } - - } - - if (this.getMapParams().containsKey("CheckSVar")) { - final int sVar = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), this - .getMapParams().get("CheckSVar"), null); - String comparator = "GE1"; - if (this.getMapParams().containsKey("SVarCompare")) { - comparator = this.getMapParams().get("SVarCompare"); - } - final String svarOperator = comparator.substring(0, 2); - final String svarOperand = comparator.substring(2); - final int operandValue = AbilityUtils.calculateAmount(Singletons.getModel().getGame().getCardState(this.getHostCard()), - svarOperand, null); - if (!Expressions.compare(sVar, svarOperator, operandValue)) { - return false; - } - } - - if (this.getMapParams().containsKey("ManaSpent")) { - if (!this.getHostCard().getColorsPaid().contains(this.getMapParams().get("ManaSpent"))) { - return false; - } - } - - if (this.getMapParams().containsKey("ManaNotSpent")) { - if (this.getHostCard().getColorsPaid().contains(this.getMapParams().get("ManaNotSpent"))) { - return false; - } - } - - if (this.getMapParams().containsKey("WerewolfTransformCondition")) { - if (CardUtil.getLastTurnCast("Card", this.getHostCard()).size() > 0) { - return false; - } - } - - if (this.getMapParams().containsKey("WerewolfUntransformCondition")) { - final List you = CardUtil.getLastTurnCast("Card.YouCtrl", this.getHostCard()); - final List opp = CardUtil.getLastTurnCast("Card.YouDontCtrl", this.getHostCard()); - if (!((you.size() > 1) || (opp.size() > 1))) { - return false; - } - } + + if ( !meetsCommonRequirements(getMapParams())) + return false; if (this.getMapParams().containsKey("EvolveCondition")) { if (this.getMapParams().get("EvolveCondition").equals("True")) { diff --git a/src/main/java/forge/game/GameAction.java b/src/main/java/forge/game/GameAction.java index 6f1937d9ab0..d2be61d4351 100644 --- a/src/main/java/forge/game/GameAction.java +++ b/src/main/java/forge/game/GameAction.java @@ -35,11 +35,11 @@ import forge.CounterType; import forge.GameEntity; import forge.card.CardSplitType; import forge.card.CardType; +import forge.card.TriggerReplacementBase; import forge.card.ability.effects.AttachEffect; import forge.card.cardfactory.CardFactory; import forge.card.cost.Cost; import forge.card.mana.ManaCost; -import forge.card.replacement.ReplacementEffect; import forge.card.replacement.ReplacementResult; import forge.card.spellability.Ability; import forge.card.spellability.AbilityActivated; @@ -164,7 +164,7 @@ public class GameAction { for (final Trigger trigger : copied.getTriggers()) { trigger.setHostCard(copied); } - for (final ReplacementEffect repl : copied.getReplacementEffects()) { + for (final TriggerReplacementBase repl : copied.getReplacementEffects()) { repl.setHostCard(copied); } if (c.getName().equals("Skullbriar, the Walking Grave")) {