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

View File

@@ -44,8 +44,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
private boolean bPaid = false;
private Boolean canPayManaCost = null;
protected InputPayMana(SpellAbility saToPayFor) {
this.player = saToPayFor.getActivatingPlayer();
private boolean locked = false;
protected InputPayMana(SpellAbility saToPayFor, Player payer) {
this.player = payer;
this.game = player.getGame();
this.saPaidFor = saToPayFor;
}
@@ -81,6 +83,11 @@ public abstract class InputPayMana extends InputSyncronizedBase {
* @return a {@link forge.game.mana.ManaCostBeingPaid} object.
*/
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
if (card.getController() != player) {
return;
@@ -190,6 +197,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
onStateChanged();
}
};
locked = true;
game.getAction().invoke(proc);
}
@@ -303,6 +311,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
}
protected final void updateMessage() {
locked = false;
if (supportAutoPay()) {
if (canPayManaCost == null) {
//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;
public class InputPayManaOfCostPayment extends InputPayMana {
public InputPayManaOfCostPayment(ManaCostBeingPaid cost, SpellAbility spellAbility) {
super(spellAbility);
public InputPayManaOfCostPayment(ManaCostBeingPaid cost, SpellAbility spellAbility, Player payer) {
super(spellAbility, payer);
manaCost = cost;
}

View File

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

View File

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

View File

@@ -626,9 +626,13 @@ public class HumanPlay {
String promptCurrent = current == null ? "" : "Current Card: " + current;
prompt = source + "\n" + promptCurrent;
}
InputPayMana toSet = new InputPayManaExecuteCommands(source, p, prompt, cost.getCostMana().getManaToPay());
toSet.showAndWait();
return toSet.isPaid();
p.getManaPool().clearManaPaid(sourceAbility, false);
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) {
@@ -704,7 +708,7 @@ public class HumanPlay {
return false;
}
if (!toPay.isPaid()) {
inpPayment = new InputPayManaOfCostPayment(toPay, ability);
inpPayment = new InputPayManaOfCostPayment(toPay, ability, activator);
inpPayment.showAndWait();
if (!inpPayment.isPaid()) {
return handleOfferingAndConvoke(ability, true, false);

View File

@@ -116,7 +116,6 @@ public class HumanPlaySpellAbility {
}
else {
this.enusureAbilityHasDescription(this.ability);
this.ability.getActivatingPlayer().getManaPool().clearManaPaid(this.ability, false);
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.CostPart;
import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana;
import forge.game.phase.PhaseType;
import forge.game.player.LobbyPlayer;
@@ -1063,13 +1062,7 @@ public class PlayerControllerHuman extends PlayerController {
}
@Override
public boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa) {
ManaCost toPay;
if ( costPartMana.isExiledCreatureCost() ) // back from the brink
toPay = sa.getPaidList("Exiled").get(0).getManaCost();
else
toPay = costPartMana.getManaToPay();
public boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa) {
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.CostPart;
import forge.game.cost.CostPartMana;
import forge.game.cost.PaymentDecision;
import forge.game.mana.Mana;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.LobbyPlayer;
import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode;
@@ -566,9 +566,9 @@ public class PlayerControllerForTests extends PlayerController {
}
@Override
public boolean payManaCost(CostPartMana costPartMana, PaymentDecision pd, SpellAbility sa) {
public boolean payManaCost(ManaCost toPay, CostPartMana costPartMana, SpellAbility sa) {
// TODO Auto-generated method stub
return ComputerUtilMana.payManaCost(player, sa);
return ComputerUtilMana.payManaCost(new ManaCostBeingPaid(toPay), sa, player);
}
@Override