diff --git a/src/forge/card/abilityFactory/AbilityFactory_AlterLife.java b/src/forge/card/abilityFactory/AbilityFactory_AlterLife.java index d858bc828b9..3907bfc1bf9 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_AlterLife.java +++ b/src/forge/card/abilityFactory/AbilityFactory_AlterLife.java @@ -129,15 +129,16 @@ public class AbilityFactory_AlterLife { } public static String gainLifeStackDescription(AbilityFactory af, SpellAbility sa){ + HashMap params = af.getMapParams(); StringBuilder sb = new StringBuilder(); - int amount = AbilityFactory.calculateAmount(af.getHostCard(), af.getMapParams().get("LifeAmount"), sa); + int amount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("LifeAmount"), sa); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard().getName()).append(" - "); else sb.append(" "); - String conditionDesc = af.getMapParams().get("ConditionDescription"); + String conditionDesc = params.get("ConditionDescription"); if (conditionDesc != null) sb.append(conditionDesc).append(" "); @@ -147,7 +148,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); for(Player player : tgtPlayers) sb.append(player).append(" "); @@ -169,7 +170,7 @@ public class AbilityFactory_AlterLife { final Card source = sa.getSourceCard(); int life = AllZone.ComputerPlayer.getLife(); int lifeAmount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("LifeAmount"), sa); - String amountStr = af.getMapParams().get("LifeAmount"); + String amountStr = params.get("LifeAmount"); //don't use it if no life to gain if (lifeAmount <= 0) return false; @@ -248,6 +249,8 @@ public class AbilityFactory_AlterLife { public static boolean gainLifeDoTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory){ if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory return false; + + HashMap params = af.getMapParams(); // If the Target is gaining life, target self. // if the Target is modifying how much life is gained, this needs to be handled better @@ -261,7 +264,7 @@ public class AbilityFactory_AlterLife { } Card source = sa.getSourceCard(); - String amountStr = af.getMapParams().get("LifeAmount"); + String amountStr = params.get("LifeAmount"); if (amountStr.equals("X") && source.getSVar(amountStr).equals("Count$xPaid")){ // Set PayX here to maximum value. int xPay = ComputerUtil.determineLeftoverMana(sa); @@ -398,15 +401,16 @@ public class AbilityFactory_AlterLife { } static String loseLifeStackDescription(AbilityFactory af, SpellAbility sa) { + HashMap params = af.getMapParams(); StringBuilder sb = new StringBuilder(); - int amount = AbilityFactory.calculateAmount(af.getHostCard(), af.getMapParams().get("LifeAmount"), sa); + int amount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("LifeAmount"), sa); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard().getName()).append(" - "); else sb.append(" "); - String conditionDesc = af.getMapParams().get("ConditionDescription"); + String conditionDesc = params.get("ConditionDescription"); if (conditionDesc != null) sb.append(conditionDesc).append(" "); @@ -415,7 +419,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); for(Player player : tgtPlayers) sb.append(player).append(" "); @@ -507,17 +511,19 @@ public class AbilityFactory_AlterLife { return (randomReturn && chance); } - public static boolean loseLifeDoTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory){ + public static boolean loseLifeDoTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory) { if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory return false; + HashMap params = af.getMapParams(); + Target tgt = sa.getTarget(); if (tgt != null){ tgt.addTarget(AllZone.HumanPlayer); } Card source = sa.getSourceCard(); - String amountStr = af.getMapParams().get("LifeAmount"); + String amountStr = params.get("LifeAmount"); int amount = 0; if (amountStr.equals("X") && source.getSVar(amountStr).equals("Count$xPaid")){ // Set PayX here to maximum value. @@ -532,7 +538,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); if (tgtPlayers.contains(AllZone.ComputerPlayer)){ @@ -561,7 +567,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); for(Player p : tgtPlayers) if (tgt == null || p.canTarget(af.getHostCard())) @@ -671,23 +677,25 @@ public class AbilityFactory_AlterLife { if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory return false; - Target tgt = sa.getTarget(); - if (tgt != null){ - tgt.addTarget(AllZone.HumanPlayer); - } - else{ - ArrayList players = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); - for(Player p : players) - if (!mandatory && p.isComputer() && p.getPoisonCounters() > p.getOpponent().getPoisonCounters()) - return false; - } - + HashMap params = af.getMapParams(); + + Target tgt = sa.getTarget(); + if (tgt != null){ + tgt.addTarget(AllZone.HumanPlayer); + } + else{ + ArrayList players = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); + for(Player p : players) + if (!mandatory && p.isComputer() && p.getPoisonCounters() > p.getOpponent().getPoisonCounters()) + return false; + } + // check SubAbilities DoTrigger? Ability_Sub abSub = sa.getSubAbility(); if (abSub != null) { return abSub.doTrigger(mandatory); } - + return true; } @@ -701,7 +709,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); for(Player p : tgtPlayers) if (tgt == null || p.canTarget(af.getHostCard())) @@ -709,15 +717,16 @@ public class AbilityFactory_AlterLife { } private static String poisonStackDescription(AbilityFactory af, SpellAbility sa){ + HashMap params = af.getMapParams(); StringBuilder sb = new StringBuilder(); - int amount = AbilityFactory.calculateAmount(af.getHostCard(), af.getMapParams().get("Num"), sa); + int amount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("Num"), sa); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard()).append(" - "); else sb.append(" "); - String conditionDesc = af.getMapParams().get("ConditionDescription"); + String conditionDesc = params.get("ConditionDescription"); if (conditionDesc != null) sb.append(conditionDesc).append(" "); @@ -727,7 +736,7 @@ public class AbilityFactory_AlterLife { if (tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); if(tgtPlayers.size() > 0) { Iterator it = tgtPlayers.iterator(); @@ -898,15 +907,16 @@ public class AbilityFactory_AlterLife { } private static String setLifeStackDescription(AbilityFactory af, SpellAbility sa) { + HashMap params = af.getMapParams(); StringBuilder sb = new StringBuilder(); - int amount = AbilityFactory.calculateAmount(af.getHostCard(), af.getMapParams().get("LifeAmount"), sa); + int amount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("LifeAmount"), sa); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard()).append(" -"); else sb.append(" "); - String conditionDesc = af.getMapParams().get("ConditionDescription"); + String conditionDesc = params.get("ConditionDescription"); if (conditionDesc != null) sb.append(conditionDesc).append(" "); @@ -916,7 +926,7 @@ public class AbilityFactory_AlterLife { if(tgt != null) tgtPlayers = tgt.getTargetPlayers(); else - tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa); for(Player player : tgtPlayers) sb.append(player).append(" "); @@ -1001,7 +1011,8 @@ public class AbilityFactory_AlterLife { int life = AllZone.ComputerPlayer.getLife(); int hlife = AllZone.HumanPlayer.getLife(); Card source = sa.getSourceCard(); - String amountStr = af.getMapParams().get("LifeAmount"); + HashMap params = af.getMapParams(); + String amountStr = params.get("LifeAmount"); if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory return false; diff --git a/src/forge/card/abilityFactory/AbilityFactory_Animate.java b/src/forge/card/abilityFactory/AbilityFactory_Animate.java index 83b6188cab4..a37da0506eb 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_Animate.java +++ b/src/forge/card/abilityFactory/AbilityFactory_Animate.java @@ -136,7 +136,7 @@ public class AbilityFactory_Animate { if (tgt != null) tgts = tgt.getTargetCards(); else - tgts = AbilityFactory.getDefinedCards(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgts = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa); for(Card c : tgts) { sb.append(c).append(" "); @@ -194,7 +194,7 @@ public class AbilityFactory_Animate { return false; if(null == tgt) { - ArrayList defined = AbilityFactory.getDefinedCards(source, af.getMapParams().get("Defined"), sa); + ArrayList defined = AbilityFactory.getDefinedCards(source, params.get("Defined"), sa); boolean bFlag = false; for(Card c : defined) { diff --git a/src/forge/card/abilityFactory/AbilityFactory_Copy.java b/src/forge/card/abilityFactory/AbilityFactory_Copy.java index 71cbb67f0d3..0280c989b6f 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_Copy.java +++ b/src/forge/card/abilityFactory/AbilityFactory_Copy.java @@ -113,6 +113,7 @@ public class AbilityFactory_Copy { private static String copyPermanentStackDescription(AbilityFactory af, SpellAbility sa) { StringBuilder sb = new StringBuilder(); + HashMap params = af.getMapParams(); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard()).append(" - "); @@ -125,7 +126,7 @@ public class AbilityFactory_Copy { if (tgt != null) tgtCards = tgt.getTargetCards(); else - tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa); sb.append("Copy "); Iterator it = tgtCards.iterator(); @@ -449,6 +450,7 @@ public class AbilityFactory_Copy { private static String copySpellStackDescription(AbilityFactory af, SpellAbility sa) { StringBuilder sb = new StringBuilder(); + HashMap params = af.getMapParams(); if (!(sa instanceof Ability_Sub)) sb.append(sa.getSourceCard().getName()).append(" - "); @@ -461,7 +463,7 @@ public class AbilityFactory_Copy { if (tgt != null) tgtSpells = tgt.getTargetSAs(); else - tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), params.get("Defined"), sa); sb.append("Copy "); Iterator it = tgtSpells.iterator(); @@ -497,7 +499,7 @@ public class AbilityFactory_Copy { } private static void copySpellResolve(final AbilityFactory af, final SpellAbility sa) { - //final HashMap params = af.getMapParams(); + final HashMap params = af.getMapParams(); Card card = af.getHostCard(); ArrayList tgtSpells; @@ -506,7 +508,7 @@ public class AbilityFactory_Copy { if (tgt != null) tgtSpells = tgt.getTargetSAs(); else - tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); + tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), params.get("Defined"), sa); for(SpellAbility tgtSA: tgtSpells) { if (tgt == null || CardFactoryUtil.canTarget(card, tgtSA.getSourceCard())) {