cleanup regarding params in a couple AFs

This commit is contained in:
jendave
2011-08-07 01:43:30 +00:00
parent ec8b9c9c83
commit e34ca1edf2
3 changed files with 51 additions and 38 deletions

View File

@@ -129,15 +129,16 @@ public class AbilityFactory_AlterLife {
} }
public static String gainLifeStackDescription(AbilityFactory af, SpellAbility sa){ public static String gainLifeStackDescription(AbilityFactory af, SpellAbility sa){
HashMap<String,String> params = af.getMapParams();
StringBuilder sb = new StringBuilder(); 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)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard().getName()).append(" - "); sb.append(sa.getSourceCard().getName()).append(" - ");
else else
sb.append(" "); sb.append(" ");
String conditionDesc = af.getMapParams().get("ConditionDescription"); String conditionDesc = params.get("ConditionDescription");
if (conditionDesc != null) if (conditionDesc != null)
sb.append(conditionDesc).append(" "); sb.append(conditionDesc).append(" ");
@@ -147,7 +148,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
for(Player player : tgtPlayers) for(Player player : tgtPlayers)
sb.append(player).append(" "); sb.append(player).append(" ");
@@ -169,7 +170,7 @@ public class AbilityFactory_AlterLife {
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
int life = AllZone.ComputerPlayer.getLife(); int life = AllZone.ComputerPlayer.getLife();
int lifeAmount = AbilityFactory.calculateAmount(af.getHostCard(), params.get("LifeAmount"), sa); 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 //don't use it if no life to gain
if (lifeAmount <= 0) return false; if (lifeAmount <= 0) return false;
@@ -248,6 +249,8 @@ public class AbilityFactory_AlterLife {
public static boolean gainLifeDoTriggerAI(AbilityFactory af, SpellAbility sa, boolean mandatory){ 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 if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory
return false; return false;
HashMap<String,String> params = af.getMapParams();
// If the Target is gaining life, target self. // If the Target is gaining life, target self.
// if the Target is modifying how much life is gained, this needs to be handled better // 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(); 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")){ if (amountStr.equals("X") && source.getSVar(amountStr).equals("Count$xPaid")){
// Set PayX here to maximum value. // Set PayX here to maximum value.
int xPay = ComputerUtil.determineLeftoverMana(sa); int xPay = ComputerUtil.determineLeftoverMana(sa);
@@ -398,15 +401,16 @@ public class AbilityFactory_AlterLife {
} }
static String loseLifeStackDescription(AbilityFactory af, SpellAbility sa) { static String loseLifeStackDescription(AbilityFactory af, SpellAbility sa) {
HashMap<String,String> params = af.getMapParams();
StringBuilder sb = new StringBuilder(); 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)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard().getName()).append(" - "); sb.append(sa.getSourceCard().getName()).append(" - ");
else else
sb.append(" "); sb.append(" ");
String conditionDesc = af.getMapParams().get("ConditionDescription"); String conditionDesc = params.get("ConditionDescription");
if (conditionDesc != null) if (conditionDesc != null)
sb.append(conditionDesc).append(" "); sb.append(conditionDesc).append(" ");
@@ -415,7 +419,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
for(Player player : tgtPlayers) for(Player player : tgtPlayers)
sb.append(player).append(" "); sb.append(player).append(" ");
@@ -507,17 +511,19 @@ public class AbilityFactory_AlterLife {
return (randomReturn && chance); 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 if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory
return false; return false;
HashMap<String,String> params = af.getMapParams();
Target tgt = sa.getTarget(); Target tgt = sa.getTarget();
if (tgt != null){ if (tgt != null){
tgt.addTarget(AllZone.HumanPlayer); tgt.addTarget(AllZone.HumanPlayer);
} }
Card source = sa.getSourceCard(); Card source = sa.getSourceCard();
String amountStr = af.getMapParams().get("LifeAmount"); String amountStr = params.get("LifeAmount");
int amount = 0; int amount = 0;
if (amountStr.equals("X") && source.getSVar(amountStr).equals("Count$xPaid")){ if (amountStr.equals("X") && source.getSVar(amountStr).equals("Count$xPaid")){
// Set PayX here to maximum value. // Set PayX here to maximum value.
@@ -532,7 +538,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else 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)){ if (tgtPlayers.contains(AllZone.ComputerPlayer)){
@@ -561,7 +567,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
for(Player p : tgtPlayers) for(Player p : tgtPlayers)
if (tgt == null || p.canTarget(af.getHostCard())) 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 if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory
return false; return false;
Target tgt = sa.getTarget(); HashMap<String,String> params = af.getMapParams();
if (tgt != null){
tgt.addTarget(AllZone.HumanPlayer); Target tgt = sa.getTarget();
} if (tgt != null){
else{ tgt.addTarget(AllZone.HumanPlayer);
ArrayList<Player> players = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); }
for(Player p : players) else{
if (!mandatory && p.isComputer() && p.getPoisonCounters() > p.getOpponent().getPoisonCounters()) ArrayList<Player> players = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
return false; for(Player p : players)
} if (!mandatory && p.isComputer() && p.getPoisonCounters() > p.getOpponent().getPoisonCounters())
return false;
}
// check SubAbilities DoTrigger? // check SubAbilities DoTrigger?
Ability_Sub abSub = sa.getSubAbility(); Ability_Sub abSub = sa.getSubAbility();
if (abSub != null) { if (abSub != null) {
return abSub.doTrigger(mandatory); return abSub.doTrigger(mandatory);
} }
return true; return true;
} }
@@ -701,7 +709,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
for(Player p : tgtPlayers) for(Player p : tgtPlayers)
if (tgt == null || p.canTarget(af.getHostCard())) if (tgt == null || p.canTarget(af.getHostCard()))
@@ -709,15 +717,16 @@ public class AbilityFactory_AlterLife {
} }
private static String poisonStackDescription(AbilityFactory af, SpellAbility sa){ private static String poisonStackDescription(AbilityFactory af, SpellAbility sa){
HashMap<String,String> params = af.getMapParams();
StringBuilder sb = new StringBuilder(); 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)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard()).append(" - "); sb.append(sa.getSourceCard()).append(" - ");
else else
sb.append(" "); sb.append(" ");
String conditionDesc = af.getMapParams().get("ConditionDescription"); String conditionDesc = params.get("ConditionDescription");
if (conditionDesc != null) if (conditionDesc != null)
sb.append(conditionDesc).append(" "); sb.append(conditionDesc).append(" ");
@@ -727,7 +736,7 @@ public class AbilityFactory_AlterLife {
if (tgt != null) if (tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
if(tgtPlayers.size() > 0) { if(tgtPlayers.size() > 0) {
Iterator<Player> it = tgtPlayers.iterator(); Iterator<Player> it = tgtPlayers.iterator();
@@ -898,15 +907,16 @@ public class AbilityFactory_AlterLife {
} }
private static String setLifeStackDescription(AbilityFactory af, SpellAbility sa) { private static String setLifeStackDescription(AbilityFactory af, SpellAbility sa) {
HashMap<String,String> params = af.getMapParams();
StringBuilder sb = new StringBuilder(); 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)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard()).append(" -"); sb.append(sa.getSourceCard()).append(" -");
else else
sb.append(" "); sb.append(" ");
String conditionDesc = af.getMapParams().get("ConditionDescription"); String conditionDesc = params.get("ConditionDescription");
if (conditionDesc != null) if (conditionDesc != null)
sb.append(conditionDesc).append(" "); sb.append(conditionDesc).append(" ");
@@ -916,7 +926,7 @@ public class AbilityFactory_AlterLife {
if(tgt != null) if(tgt != null)
tgtPlayers = tgt.getTargetPlayers(); tgtPlayers = tgt.getTargetPlayers();
else else
tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtPlayers = AbilityFactory.getDefinedPlayers(sa.getSourceCard(), params.get("Defined"), sa);
for(Player player : tgtPlayers) for(Player player : tgtPlayers)
sb.append(player).append(" "); sb.append(player).append(" ");
@@ -1001,7 +1011,8 @@ public class AbilityFactory_AlterLife {
int life = AllZone.ComputerPlayer.getLife(); int life = AllZone.ComputerPlayer.getLife();
int hlife = AllZone.HumanPlayer.getLife(); int hlife = AllZone.HumanPlayer.getLife();
Card source = sa.getSourceCard(); Card source = sa.getSourceCard();
String amountStr = af.getMapParams().get("LifeAmount"); HashMap<String,String> params = af.getMapParams();
String amountStr = params.get("LifeAmount");
if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory if (!ComputerUtil.canPayCost(sa) && !mandatory) // If there is a cost payment it's usually not mandatory
return false; return false;

View File

@@ -136,7 +136,7 @@ public class AbilityFactory_Animate {
if (tgt != null) if (tgt != null)
tgts = tgt.getTargetCards(); tgts = tgt.getTargetCards();
else else
tgts = AbilityFactory.getDefinedCards(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgts = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
for(Card c : tgts) { for(Card c : tgts) {
sb.append(c).append(" "); sb.append(c).append(" ");
@@ -194,7 +194,7 @@ public class AbilityFactory_Animate {
return false; return false;
if(null == tgt) { if(null == tgt) {
ArrayList<Card> defined = AbilityFactory.getDefinedCards(source, af.getMapParams().get("Defined"), sa); ArrayList<Card> defined = AbilityFactory.getDefinedCards(source, params.get("Defined"), sa);
boolean bFlag = false; boolean bFlag = false;
for(Card c : defined) { for(Card c : defined) {

View File

@@ -113,6 +113,7 @@ public class AbilityFactory_Copy {
private static String copyPermanentStackDescription(AbilityFactory af, SpellAbility sa) { private static String copyPermanentStackDescription(AbilityFactory af, SpellAbility sa) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
HashMap<String,String> params = af.getMapParams();
if (!(sa instanceof Ability_Sub)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard()).append(" - "); sb.append(sa.getSourceCard()).append(" - ");
@@ -125,7 +126,7 @@ public class AbilityFactory_Copy {
if (tgt != null) if (tgt != null)
tgtCards = tgt.getTargetCards(); tgtCards = tgt.getTargetCards();
else else
tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtCards = AbilityFactory.getDefinedCards(sa.getSourceCard(), params.get("Defined"), sa);
sb.append("Copy "); sb.append("Copy ");
Iterator<Card> it = tgtCards.iterator(); Iterator<Card> it = tgtCards.iterator();
@@ -449,6 +450,7 @@ public class AbilityFactory_Copy {
private static String copySpellStackDescription(AbilityFactory af, SpellAbility sa) { private static String copySpellStackDescription(AbilityFactory af, SpellAbility sa) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
HashMap<String,String> params = af.getMapParams();
if (!(sa instanceof Ability_Sub)) if (!(sa instanceof Ability_Sub))
sb.append(sa.getSourceCard().getName()).append(" - "); sb.append(sa.getSourceCard().getName()).append(" - ");
@@ -461,7 +463,7 @@ public class AbilityFactory_Copy {
if (tgt != null) if (tgt != null)
tgtSpells = tgt.getTargetSAs(); tgtSpells = tgt.getTargetSAs();
else else
tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), params.get("Defined"), sa);
sb.append("Copy "); sb.append("Copy ");
Iterator<SpellAbility> it = tgtSpells.iterator(); Iterator<SpellAbility> it = tgtSpells.iterator();
@@ -497,7 +499,7 @@ public class AbilityFactory_Copy {
} }
private static void copySpellResolve(final AbilityFactory af, final SpellAbility sa) { private static void copySpellResolve(final AbilityFactory af, final SpellAbility sa) {
//final HashMap<String,String> params = af.getMapParams(); final HashMap<String,String> params = af.getMapParams();
Card card = af.getHostCard(); Card card = af.getHostCard();
ArrayList<SpellAbility> tgtSpells; ArrayList<SpellAbility> tgtSpells;
@@ -506,7 +508,7 @@ public class AbilityFactory_Copy {
if (tgt != null) if (tgt != null)
tgtSpells = tgt.getTargetSAs(); tgtSpells = tgt.getTargetSAs();
else else
tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), af.getMapParams().get("Defined"), sa); tgtSpells = AbilityFactory.getDefinedSpellAbilities(sa.getSourceCard(), params.get("Defined"), sa);
for(SpellAbility tgtSA: tgtSpells) { for(SpellAbility tgtSA: tgtSpells) {
if (tgt == null || CardFactoryUtil.canTarget(card, tgtSA.getSourceCard())) { if (tgt == null || CardFactoryUtil.canTarget(card, tgtSA.getSourceCard())) {