remove getManaPaid() from SpellAbility because there is already a method getPayingMana()

Remove input/InputPayManaExecuteCommands.java, using Common input instead
This commit is contained in:
Maxmtg
2014-02-18 00:35:45 +00:00
parent 22be9fffb6
commit 42fcd856d0
17 changed files with 53 additions and 148 deletions

1
.gitattributes vendored
View File

@@ -15580,7 +15580,6 @@ forge-gui/src/main/java/forge/gui/input/InputConfirmMulligan.java svneol=native#
forge-gui/src/main/java/forge/gui/input/InputLockUI.java -text forge-gui/src/main/java/forge/gui/input/InputLockUI.java -text
forge-gui/src/main/java/forge/gui/input/InputPassPriority.java svneol=native#text/plain forge-gui/src/main/java/forge/gui/input/InputPassPriority.java svneol=native#text/plain
forge-gui/src/main/java/forge/gui/input/InputPayMana.java -text forge-gui/src/main/java/forge/gui/input/InputPayMana.java -text
forge-gui/src/main/java/forge/gui/input/InputPayManaExecuteCommands.java svneol=native#text/plain
forge-gui/src/main/java/forge/gui/input/InputPayManaOfCostPayment.java -text forge-gui/src/main/java/forge/gui/input/InputPayManaOfCostPayment.java -text
forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java svneol=native#text/plain forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java svneol=native#text/plain
forge-gui/src/main/java/forge/gui/input/InputPayManaX.java -text forge-gui/src/main/java/forge/gui/input/InputPayManaX.java -text

View File

@@ -109,7 +109,7 @@ public class ComputerUtilMana {
} }
else { else {
if ( ai.getManaPool().tryPayCostWithMana(sa, cost, mana) && !test) if ( ai.getManaPool().tryPayCostWithMana(sa, cost, mana) && !test)
sa.getManaPaid().add(mana); sa.getPayingMana().add(mana);
} }
} }
} }

View File

@@ -26,8 +26,8 @@ import forge.game.combat.Combat;
import forge.game.cost.Cost; import forge.game.cost.Cost;
import forge.game.cost.CostPart; import forge.game.cost.CostPart;
import forge.game.cost.CostPartMana; import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana; import forge.game.mana.Mana;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.LobbyPlayer; import forge.game.player.LobbyPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode; import forge.game.player.PlayerActionConfirmMode;
@@ -717,9 +717,9 @@ public class PlayerControllerAi extends PlayerController {
} }
@Override @Override
public boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa) { public boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return ComputerUtilMana.payManaCost(player, sa); return ComputerUtilMana.payManaCost(new ManaCostBeingPaid(toPay), sa, player);
} }
@Override @Override

View File

@@ -216,14 +216,17 @@ public class CostExile extends CostPartWithList {
} }
} }
public static final String HashListKey = "Exiled";
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.cost.CostPartWithList#getHashForList() * @see forge.card.cost.CostPartWithList#getHashForList()
*/ */
@Override @Override
public String getHashForList() { public String getHashForList() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return "Exiled"; return HashListKey;
} }
public <T> T accept(ICostVisitor<T> visitor) { public <T> T accept(ICostVisitor<T> visitor) {
return visitor.visit(this); return visitor.visit(this);

View File

@@ -115,12 +115,20 @@ public class CostPartMana extends CostPart {
return visitor.visit(this); return visitor.visit(this);
} }
public ManaCost getManaCostFor(SpellAbility sa) {
if ( isExiledCreatureCost() && !sa.getPaidList(CostExile.HashListKey).isEmpty()) // back from the brink
return sa.getPaidList(CostExile.HashListKey).get(0).getManaCost();
else
return getManaToPay();
}
@Override @Override
public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) { public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
sa.getManaPaid().clear(); payer.getManaPool().clearManaPaid(sa, false);
return payer.getController().payManaCost(this, pd, sa);
// decision not used here, the whole payment is interactive!
return payer.getController().payManaCost(this, sa);
} }
} }

View File

@@ -171,7 +171,7 @@ public class ManaPool implements Iterable<Mana> {
paidAbs.add(saPayment); // assumes some part on the mana produced by the ability will get used paidAbs.add(saPayment); // assumes some part on the mana produced by the ability will get used
for (final Mana mana : abManaPart.getLastManaProduced()) { for (final Mana mana : abManaPart.getLastManaProduced()) {
if( tryPayCostWithMana(saPaidFor, manaCost, mana) ) if( tryPayCostWithMana(saPaidFor, manaCost, mana) )
saPaidFor.getManaPaid().add(mana); saPaidFor.getPayingMana().add(mana);
} }
} }
@@ -196,7 +196,7 @@ public class ManaPool implements Iterable<Mana> {
boolean result = manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound); boolean result = manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound);
if(result) if(result)
saPaidFor.getManaPaid().add(manaFound); saPaidFor.getPayingMana().add(manaFound);
return result; return result;
} }
@@ -206,7 +206,6 @@ public class ManaPool implements Iterable<Mana> {
return false; return false;
} }
manaCost.payMana(mana, this); manaCost.payMana(mana, this);
sa.getPayingMana().add(mana);
this.removeMana(mana); this.removeMana(mana);
if (mana.addsNoCounterMagic(sa) && sa.getHostCard() != null) { if (mana.addsNoCounterMagic(sa) && sa.getHostCard() != null) {
sa.getHostCard().setCanCounter(false); sa.getHostCard().setCanCounter(false);

View File

@@ -18,7 +18,6 @@ import forge.game.combat.Combat;
import forge.game.cost.Cost; import forge.game.cost.Cost;
import forge.game.cost.CostPart; import forge.game.cost.CostPart;
import forge.game.cost.CostPartMana; import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana; import forge.game.mana.Mana;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.replacement.ReplacementEffect; import forge.game.replacement.ReplacementEffect;
@@ -223,7 +222,10 @@ public abstract class PlayerController {
public List<Card> cheatShuffle(List<Card> list) { return list; } public List<Card> cheatShuffle(List<Card> list) { return list; }
public Collection<? extends PaperCard> complainCardsCantPlayWell(Deck myDeck) { return null; } public Collection<? extends PaperCard> complainCardsCantPlayWell(Deck myDeck) { return null; }
public abstract boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa); public final boolean payManaCost(CostPartMana costPartMana, SpellAbility sa) {
return payManaCost(costPartMana.getManaCostFor(sa), costPartMana, sa);
}
public abstract boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa);
public abstract Map<Card, ManaCostShard> chooseCardsForConvoke(SpellAbility sa, ManaCost manaCost, List<Card> untappedCreats); public abstract Map<Card, ManaCostShard> chooseCardsForConvoke(SpellAbility sa, ManaCost manaCost, List<Card> untappedCreats);

View File

@@ -476,7 +476,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
* *
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public ArrayList<Mana> getPayingMana() { public List<Mana> getPayingMana() {
return this.payingMana; return this.payingMana;
} }
@@ -490,11 +490,6 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
public List<SpellAbility> getPayingManaAbilities() { public List<SpellAbility> getPayingManaAbilities() {
return this.paidAbilities; return this.paidAbilities;
} }
List<Mana> paidMana = new ArrayList<>();
public List<Mana> getManaPaid() {
return paidMana;
}
// Combined PaidLists // Combined PaidLists
/** /**

View File

@@ -44,8 +44,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
private boolean bPaid = false; private boolean bPaid = false;
private Boolean canPayManaCost = null; private Boolean canPayManaCost = null;
protected InputPayMana(SpellAbility saToPayFor) { private boolean locked = false;
this.player = saToPayFor.getActivatingPlayer();
protected InputPayMana(SpellAbility saToPayFor, Player payer) {
this.player = payer;
this.game = player.getGame(); this.game = player.getGame();
this.saPaidFor = saToPayFor; this.saPaidFor = saToPayFor;
} }
@@ -81,6 +83,11 @@ public abstract class InputPayMana extends InputSyncronizedBase {
* @return a {@link forge.game.mana.ManaCostBeingPaid} object. * @return a {@link forge.game.mana.ManaCostBeingPaid} object.
*/ */
protected void activateManaAbility(final Card card, ManaCostBeingPaid manaCost) { protected void activateManaAbility(final Card card, ManaCostBeingPaid manaCost) {
if ( locked ) {
System.err.print("Should wait till previous call to playAbility finishes.");
return;
}
// make sure computer's lands aren't selected // make sure computer's lands aren't selected
if (card.getController() != player) { if (card.getController() != player) {
return; return;
@@ -190,6 +197,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
onStateChanged(); onStateChanged();
} }
}; };
locked = true;
game.getAction().invoke(proc); game.getAction().invoke(proc);
} }
@@ -303,6 +311,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
} }
protected final void updateMessage() { protected final void updateMessage() {
locked = false;
if (supportAutoPay()) { if (supportAutoPay()) {
if (canPayManaCost == null) { if (canPayManaCost == null) {
//use AI utility to determine if mana cost can be paid if that hasn't been determined yet //use AI utility to determine if mana cost can be paid if that hasn't been determined yet

View File

@@ -1,106 +0,0 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.gui.input;
import forge.card.mana.ManaCost;
import forge.game.card.Card;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import java.awt.event.MouseEvent;
//if cost is paid, Command.execute() is called
/**
* <p>
* Input_PayManaCost_Ability class.
* </p>
*
* @author Forge
* @version $Id$
*/
public class InputPayManaExecuteCommands extends InputPayMana {
/**
* Constant <code>serialVersionUID=3836655722696348713L</code>.
*/
private static final long serialVersionUID = 3836655722696348713L;
private ManaCost originalManaCost;
private String message = "";
private boolean bPaid = false;
public boolean isPaid() { return bPaid; }
/**
* <p>
* Constructor for Input_PayManaCost_Ability.
* </p>
*/
public InputPayManaExecuteCommands(final Card sourceCard, final Player p, final String prompt, final ManaCost manaCost0) {
super(new SpellAbility.EmptySa(sourceCard, p));
this.originalManaCost = manaCost0;
this.phyLifeToLose = 0;
this.message = prompt;
this.manaCost = new ManaCostBeingPaid(this.originalManaCost);
}
@Override
protected final void onPlayerSelected(Player selected, final MouseEvent triggerEvent) {
if (player == selected) {
if (player.canPayLife(this.phyLifeToLose + 2) && manaCost.payPhyrexian()) {
this.phyLifeToLose += 2;
}
onStateChanged();
}
}
@Override
protected void done() {
if (this.phyLifeToLose > 0) {
player.payLife(this.phyLifeToLose, null);
}
player.getManaPool().clearManaPaid(this.saPaidFor, false);
bPaid = true;
}
/** {@inheritDoc} */
@Override
protected final void onCancel() {
player.getManaPool().refundManaPaid(this.saPaidFor);
bPaid = false;
this.stop();
}
/** {@inheritDoc} */
@Override
protected String getMessage() {
final StringBuilder msg = new StringBuilder(this.message + "\nPay Mana Cost: " + this.manaCost);
if (this.phyLifeToLose > 0) {
msg.append(" (");
msg.append(this.phyLifeToLose);
msg.append(" life paid for phyrexian mana)");
}
if (this.manaCost.containsPhyrexianMana()) {
msg.append("\n(Click on your life total to pay life for phyrexian mana.)");
}
return msg.toString();
}
}

View File

@@ -8,8 +8,8 @@ import forge.game.spellability.SpellAbility;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
public class InputPayManaOfCostPayment extends InputPayMana { public class InputPayManaOfCostPayment extends InputPayMana {
public InputPayManaOfCostPayment(ManaCostBeingPaid cost, SpellAbility spellAbility) { public InputPayManaOfCostPayment(ManaCostBeingPaid cost, SpellAbility spellAbility, Player payer) {
super(spellAbility); super(spellAbility, payer);
manaCost = cost; manaCost = cost;
} }

View File

@@ -38,7 +38,7 @@ public class InputPayManaSimple extends InputPayMana {
private final ManaCost originalManaCost; private final ManaCost originalManaCost;
public InputPayManaSimple(final Game game, final SpellAbility sa, final ManaCostBeingPaid manaCostToPay) { public InputPayManaSimple(final Game game, final SpellAbility sa, final ManaCostBeingPaid manaCostToPay) {
super(sa); super(sa, sa.getActivatingPlayer());
this.originalManaCost = manaCostToPay.toManaCost(); this.originalManaCost = manaCostToPay.toManaCost();
this.originalCard = sa.getHostCard(); this.originalCard = sa.getHostCard();

View File

@@ -22,7 +22,7 @@ public class InputPayManaX extends InputPayMana {
private boolean canceled = false; private boolean canceled = false;
public InputPayManaX(final SpellAbility sa0, final int amountX, final boolean xCanBe0) { public InputPayManaX(final SpellAbility sa0, final int amountX, final boolean xCanBe0) {
super(sa0); super(sa0, sa0.getActivatingPlayer());
xPaid = 0; xPaid = 0;
if (saPaidFor.hasParam("XColor")) { if (saPaidFor.hasParam("XColor")) {

View File

@@ -626,9 +626,13 @@ public class HumanPlay {
String promptCurrent = current == null ? "" : "Current Card: " + current; String promptCurrent = current == null ? "" : "Current Card: " + current;
prompt = source + "\n" + promptCurrent; prompt = source + "\n" + promptCurrent;
} }
InputPayMana toSet = new InputPayManaExecuteCommands(source, p, prompt, cost.getCostMana().getManaToPay());
toSet.showAndWait(); p.getManaPool().clearManaPaid(sourceAbility, false);
return toSet.isPaid(); boolean paid = p.getController().payManaCost(cost.getCostMana(), sourceAbility);
if (!paid) {
p.getManaPool().refundManaPaid(sourceAbility);
}
return paid;
} }
private static boolean payCostPart(SpellAbility sourceAbility, CostPartWithList cpl, int amount, List<Card> list, String actionName) { private static boolean payCostPart(SpellAbility sourceAbility, CostPartWithList cpl, int amount, List<Card> list, String actionName) {
@@ -704,7 +708,7 @@ public class HumanPlay {
return false; return false;
} }
if (!toPay.isPaid()) { if (!toPay.isPaid()) {
inpPayment = new InputPayManaOfCostPayment(toPay, ability); inpPayment = new InputPayManaOfCostPayment(toPay, ability, activator);
inpPayment.showAndWait(); inpPayment.showAndWait();
if (!inpPayment.isPaid()) { if (!inpPayment.isPaid()) {
return handleOfferingAndConvoke(ability, true, false); return handleOfferingAndConvoke(ability, true, false);

View File

@@ -116,7 +116,6 @@ public class HumanPlaySpellAbility {
} }
else { else {
this.enusureAbilityHasDescription(this.ability); this.enusureAbilityHasDescription(this.ability);
this.ability.getActivatingPlayer().getManaPool().clearManaPaid(this.ability, false);
game.getStack().addAndUnfreeze(this.ability); game.getStack().addAndUnfreeze(this.ability);
} }

View File

@@ -26,7 +26,6 @@ import forge.game.combat.Combat;
import forge.game.cost.Cost; import forge.game.cost.Cost;
import forge.game.cost.CostPart; import forge.game.cost.CostPart;
import forge.game.cost.CostPartMana; import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana; import forge.game.mana.Mana;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.LobbyPlayer; import forge.game.player.LobbyPlayer;
@@ -1063,13 +1062,7 @@ public class PlayerControllerHuman extends PlayerController {
} }
@Override @Override
public boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa) { public boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa) {
ManaCost toPay;
if ( costPartMana.isExiledCreatureCost() ) // back from the brink
toPay = sa.getPaidList("Exiled").get(0).getManaCost();
else
toPay = costPartMana.getManaToPay();
return HumanPlay.payManaCost(toPay, costPartMana, sa, player); return HumanPlay.payManaCost(toPay, costPartMana, sa, player);
} }

View File

@@ -29,8 +29,8 @@ import forge.game.combat.CombatUtil;
import forge.game.cost.Cost; import forge.game.cost.Cost;
import forge.game.cost.CostPart; import forge.game.cost.CostPart;
import forge.game.cost.CostPartMana; import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana; import forge.game.mana.Mana;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.LobbyPlayer; import forge.game.player.LobbyPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode; import forge.game.player.PlayerActionConfirmMode;
@@ -566,9 +566,9 @@ public class PlayerControllerForTests extends PlayerController {
} }
@Override @Override
public boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa) { public boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return ComputerUtilMana.payManaCost(player, sa); return ComputerUtilMana.payManaCost(new ManaCostBeingPaid(toPay), sa, player);
} }
@Override @Override