From aca519c0f01d3022524adc2e986fabfc1f9e66b0 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Tue, 14 May 2013 05:57:56 +0000 Subject: [PATCH] InputPayManaX - bugfix + some improved code --- .../forge/control/input/InputPayManaX.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/forge/control/input/InputPayManaX.java b/src/main/java/forge/control/input/InputPayManaX.java index 1d866336dd2..e56b2ed2f4b 100644 --- a/src/main/java/forge/control/input/InputPayManaX.java +++ b/src/main/java/forge/control/input/InputPayManaX.java @@ -1,5 +1,10 @@ package forge.control.input; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + import forge.Card; import forge.card.mana.ManaCostBeingPaid; import forge.card.spellability.SpellAbility; @@ -8,9 +13,8 @@ import forge.view.ButtonUtil; public class InputPayManaX extends InputPayManaBase { private static final long serialVersionUID = -6900234444347364050L; private int xPaid = 0; - private final String colorX; - private final String strX; private String colorsPaid; + private final String manaCostStr; private final boolean xCanBe0; private boolean canceled = false; @@ -18,14 +22,25 @@ public class InputPayManaX extends InputPayManaBase { public InputPayManaX(final SpellAbility sa0, final int amountX, final boolean xCanBe0) { super(sa0); - xPaid = 0; - colorX = saPaidFor.hasParam("XColor") ? saPaidFor.getParam("XColor") : ""; - colorsPaid = saPaidFor.getSourceCard().getColorsPaid(); - - strX = Integer.toString(amountX); - manaCost = new ManaCostBeingPaid(strX); - this.xCanBe0 = xCanBe0; + if (saPaidFor.hasParam("XColor") ) + { + String xColor = saPaidFor.getParam("XColor"); + if( amountX == 1 ) + manaCostStr = xColor; + else { + List list = new ArrayList(amountX); + for(int i = 0; i < amountX; i++) + list.add(xColor); + manaCostStr = StringUtils.join(list, ' '); + } + } else { + manaCostStr = Integer.toString(amountX); + } + manaCost = new ManaCostBeingPaid(manaCostStr); + + this.xCanBe0 = xCanBe0; + colorsPaid = saPaidFor.getSourceCard().getColorsPaid(); // for effects like sunburst } /* (non-Javadoc) @@ -35,7 +50,7 @@ public class InputPayManaX extends InputPayManaBase { public boolean isPaid() { //return !( xPaid == 0 && !costMana.canXbe0() || this.colorX.equals("") && !this.manaCost.toString().equals(strX) ); // return !( xPaid == 0 && !costMana.canXbe0()) && !(this.colorX.equals("") && !this.manaCost.toString().equals(strX)); - return ( !canceled && (xPaid > 0 || xCanBe0) && (!this.colorX.equals("") || this.manaCost.toString().equals(strX))); + return !canceled && (xPaid > 0 || xCanBe0); } @Override @@ -63,7 +78,7 @@ public class InputPayManaX extends InputPayManaBase { @Override protected void onCardSelected(Card card) { // don't allow here the cards that produce only wrong colors - activateManaAbility(card, this.colorX.isEmpty() ? this.manaCost : new ManaCostBeingPaid(this.colorX)); + activateManaAbility(card, this.manaCost); } @@ -73,7 +88,7 @@ public class InputPayManaX extends InputPayManaBase { if (!this.colorsPaid.contains(this.manaCost.getColorsPaid())) { this.colorsPaid += this.manaCost.getColorsPaid(); } - this.manaCost = new ManaCostBeingPaid(strX); + this.manaCost = new ManaCostBeingPaid(manaCostStr); this.xPaid++; } } @@ -92,7 +107,7 @@ public class InputPayManaX extends InputPayManaBase { @Override public void selectManaPool(byte colorCode) { - useManaFromPool(colorCode, this.colorX.isEmpty() ? this.manaCost : new ManaCostBeingPaid(this.colorX)); + useManaFromPool(colorCode, this.manaCost); }