diff --git a/src/main/java/forge/card/ability/AbilityUtils.java b/src/main/java/forge/card/ability/AbilityUtils.java index 8733fd7042e..95df7a8d2d3 100644 --- a/src/main/java/forge/card/ability/AbilityUtils.java +++ b/src/main/java/forge/card/ability/AbilityUtils.java @@ -294,8 +294,6 @@ public class AbilityUtils { if (StringUtils.isBlank(amount)) return 0; final boolean startsWithPlus = amount.charAt(0) == '+'; if(startsWithPlus) amount = amount.substring(1); - - if (StringUtils.isNumeric(amount)) return Integer.parseInt(amount); // Strip and save sign for calculations boolean startsWithMinus = amount.charAt(0) == '-'; @@ -303,6 +301,9 @@ public class AbilityUtils { if(startsWithMinus) amount = amount.substring(1); + // return result soon for plain numbers + if (StringUtils.isNumeric(amount)) return Integer.parseInt(amount) * multiplier; + // These are some special cases - who is implementing them? if (amount.equals("ChosenX") || amount.equals("ChosenY")) { // isn't made yet diff --git a/src/main/java/forge/card/cost/CostPartMana.java b/src/main/java/forge/card/cost/CostPartMana.java index 63bde67ed62..b90fa4696e6 100644 --- a/src/main/java/forge/card/cost/CostPartMana.java +++ b/src/main/java/forge/card/cost/CostPartMana.java @@ -21,6 +21,7 @@ import forge.Card; import forge.FThreads; import forge.card.ability.AbilityUtils; import forge.card.mana.ManaCost; +import forge.card.mana.ManaCostBeingPaid; import forge.card.mana.ManaCostShard; import forge.card.spellability.SpellAbility; import forge.control.input.InputPayManaOfCostPayment; @@ -39,6 +40,20 @@ public class CostPartMana extends CostPart { private ManaCost adjustedCost; private boolean xCantBe0 = false; + /** + * Instantiates a new cost mana. + * + * @param mana + * the mana + * @param amount + * the amount + * @param xCantBe0 TODO + */ + public CostPartMana(final ManaCost cost, boolean xCantBe0) { + this.cost = cost; + this.xCantBe0 = xCantBe0; // TODO: Add 0 to parameter's name. + } + /** * Gets the mana. * @@ -49,20 +64,6 @@ public class CostPartMana extends CostPart { return this.cost; } - /** - * Checks for no x mana cost. - * - * @return true, if successful - */ - public final boolean hasNoXManaCost() { - return getAmountOfX() == 0; - } - - /** - * Gets the x mana. - * - * @return the x mana - */ public final int getAmountOfX() { return this.cost.getShardCount(ManaCostShard.X); } @@ -75,10 +76,11 @@ public class CostPartMana extends CostPart { } /** - * @param xCantBe00 the xCantBe0 to set + * Used to set mana cost after applying static effects that change costs. */ - public void setxCantBe0(boolean xCantBe0) { - this.xCantBe0 = xCantBe0; // TODO: Add 0 to parameter's name. + public void setAdjustedMana(ManaCost manaCost) { + // this is set when static effects of LodeStone Golems or Thalias are applied + adjustedCost = manaCost; } /** @@ -87,12 +89,7 @@ public class CostPartMana extends CostPart { * @return the mana to pay */ public final ManaCost getManaToPay() { - // Only used for Human to pay for non-X cost first - if (this.adjustedCost != null ) { - return this.adjustedCost; - } - - return this.cost; + return adjustedCost == null ? cost : adjustedCost; } @Override @@ -101,37 +98,13 @@ public class CostPartMana extends CostPart { @Override public boolean isUndoable() { return true; } - /** - * Instantiates a new cost mana. - * - * @param mana - * the mana - * @param amount - * the amount - * @param xCantBe0 TODO - */ - public CostPartMana(final ManaCost cost, boolean xCantBe0) { - this.cost = cost; - this.setxCantBe0(xCantBe0); - } - /* - * (non-Javadoc) - * - * @see forge.card.cost.CostPart#toString() - */ @Override public final String toString() { return cost.toString(); } - /* - * (non-Javadoc) - * - * @see - * forge.card.cost.CostPart#canPay(forge.card.spellability.SpellAbility, - * forge.Card, forge.Player, forge.card.cost.Cost) - */ + @Override public final boolean canPay(final SpellAbility ability) { // For now, this will always return true. But this should probably be @@ -139,36 +112,23 @@ public class CostPartMana extends CostPart { return true; } - /* (non-Javadoc) - * @see forge.card.cost.CostPart#payAI(forge.card.cost.PaymentDecision, forge.game.player.AIPlayer, forge.card.spellability.SpellAbility, forge.Card) - */ - @Override - public void payAI(PaymentDecision decision, AIPlayer ai, SpellAbility ability, Card source) { - ComputerUtilMana.payManaCost(ai, ability); - } - - /* - * (non-Javadoc) - * - * @see - * forge.card.cost.CostPart#payHuman(forge.card.spellability.SpellAbility, - * forge.Card, forge.card.cost.Cost_Payment) - */ @Override public final boolean payHuman(final SpellAbility ability, final GameState game) { final Card source = ability.getSourceCard(); - int manaToAdd = 0; - if (!this.hasNoXManaCost()) { + ManaCostBeingPaid toPay = new ManaCostBeingPaid(getManaToPay()); + + if (this.getAmountOfX() > 0) { // if X cost is a defined value, other than xPaid if (!ability.getSVar("X").equals("Count$xPaid")) { // this currently only works for things about Targeted object - manaToAdd += AbilityUtils.calculateAmount(source, "X", ability) * this.getAmountOfX(); + int xCost = AbilityUtils.calculateAmount(source, "X", ability) * this.getAmountOfX(); + toPay.increaseColorlessMana(xCost); } } - - - if (!"0".equals(this.getManaToPay()) || manaToAdd > 0) { - InputPayment inpPayment = new InputPayManaOfCostPayment(game, this, ability, manaToAdd); + + + if (!toPay.isPaid()) { + InputPayment inpPayment = new InputPayManaOfCostPayment(game, toPay, ability); FThreads.setInputAndWait(inpPayment); if(!inpPayment.isPaid()) return false; @@ -186,9 +146,18 @@ public class CostPartMana extends CostPart { } } return true; - + } + /* (non-Javadoc) + * @see forge.card.cost.CostPart#payAI(forge.card.cost.PaymentDecision, forge.game.player.AIPlayer, forge.card.spellability.SpellAbility, forge.Card) + */ + @Override + public void payAI(PaymentDecision decision, AIPlayer ai, SpellAbility ability, Card source) { + ComputerUtilMana.payManaCost(ai, ability); + } + + /* (non-Javadoc) * @see forge.card.cost.CostPart#decideAIPayment(forge.game.player.AIPlayer, forge.card.spellability.SpellAbility, forge.Card) */ @@ -196,13 +165,4 @@ public class CostPartMana extends CostPart { public PaymentDecision decideAIPayment(AIPlayer ai, SpellAbility ability, Card source) { return new PaymentDecision(0); } - - /** - * TODO: Write javadoc for this method. - * @param manaCost - */ - public void setAdjustedMana(ManaCost manaCost) { - // this is set when static effects of LodeStone Golems or Thalias are applied - adjustedCost = manaCost; - } } diff --git a/src/main/java/forge/card/mana/ManaCostBeingPaid.java b/src/main/java/forge/card/mana/ManaCostBeingPaid.java index 839d1eadc4a..cf68569afcd 100644 --- a/src/main/java/forge/card/mana/ManaCostBeingPaid.java +++ b/src/main/java/forge/card/mana/ManaCostBeingPaid.java @@ -97,8 +97,6 @@ public class ManaCostBeingPaid { private final ArrayList manaNeededToAvoidNegativeEffect = new ArrayList(); private final ArrayList manaPaidToAvoidNegativeEffect = new ArrayList(); - private final ManaCost originalCost; - // manaCost can be like "0", "3", "G", "GW", "10", "3 GW", "10 GW" // or "split hybrid mana" like "2/G 2/G", "2/B 2/B 2/B" // "GW" can be paid with either G or W @@ -116,7 +114,6 @@ public class ManaCostBeingPaid { } public ManaCostBeingPaid(ManaCost manaCost) { - originalCost = manaCost; if ( null == manaCost ) return; @@ -703,10 +700,6 @@ public class ManaCostBeingPaid { return this.manaPaidToAvoidNegativeEffect; } - public ManaCost getStartingCost() { - return originalCost; - } - public final void applySpellCostChange(final SpellAbility sa) { final GameState game = sa.getActivatingPlayer().getGame(); // Beached diff --git a/src/main/java/forge/control/input/InputPayManaBase.java b/src/main/java/forge/control/input/InputPayManaBase.java index 1e633147e52..f70fe3a52b8 100644 --- a/src/main/java/forge/control/input/InputPayManaBase.java +++ b/src/main/java/forge/control/input/InputPayManaBase.java @@ -320,7 +320,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I @Override public String toString() { - return String.format("PayManaBase %s (out of %s)", manaCost.toString(), manaCost.getStartingCost() ); + return String.format("PayManaBase %s left", manaCost.toString() ); } protected void handleConvokedCards(boolean isCancelled) { diff --git a/src/main/java/forge/control/input/InputPayManaOfCostPayment.java b/src/main/java/forge/control/input/InputPayManaOfCostPayment.java index 8812c1f3cf6..b3f8cbaddc7 100644 --- a/src/main/java/forge/control/input/InputPayManaOfCostPayment.java +++ b/src/main/java/forge/control/input/InputPayManaOfCostPayment.java @@ -2,7 +2,6 @@ package forge.control.input; import forge.Card; import forge.Singletons; -import forge.card.cost.CostPartMana; import forge.card.mana.ManaCostBeingPaid; import forge.card.spellability.SpellAbility; import forge.game.GameState; @@ -11,10 +10,9 @@ import forge.view.ButtonUtil; public class InputPayManaOfCostPayment extends InputPayManaBase { - public InputPayManaOfCostPayment(final GameState game, CostPartMana costMana, SpellAbility spellAbility, int toAdd) { + public InputPayManaOfCostPayment(final GameState game, ManaCostBeingPaid cost, SpellAbility spellAbility) { super(spellAbility); - manaCost = new ManaCostBeingPaid(costMana.getManaToPay()); - manaCost.increaseColorlessMana(toAdd); + manaCost = cost; } private static final long serialVersionUID = 3467312982164195091L;