Fix so abilities using InputPayManaExecuteCommands work with Auto button

This commit is contained in:
drdev
2013-12-04 02:49:26 +00:00
parent fe8af8705d
commit 803b6331f4
4 changed files with 98 additions and 121 deletions

View File

@@ -96,10 +96,7 @@ public class ComputerUtilMana {
}
private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) {
final Card card = sa.getSourceCard();
if (card != null) {
adjustManaCostToAvoidNegEffects(cost, card);
}
adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard());
final ManaPool manapool = ai.getManaPool();
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();

View File

@@ -67,7 +67,6 @@ import forge.util.Lang;
*
*/
public class HumanPlay {
/**
* TODO: Write javadoc for Constructor.
*/
@@ -93,7 +92,6 @@ public class HumanPlay {
return;
}
sa.setActivatingPlayer(p);
final Card source = sa.getSourceCard();
@@ -127,15 +125,14 @@ public class HumanPlay {
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
req.playAbility(true, false, false);
} else {
if (payManaCostIfNeeded(p, sa)) {
}
else if (payManaCostIfNeeded(p, sa)) {
if (sa.isSpell() && !source.isCopiedSpell()) {
sa.setSourceCard(p.getGame().getAction().moveToStack(source));
}
p.getGame().getStack().add(sa);
}
}
}
/**
* choose optional additional costs. For HUMAN only
@@ -157,14 +154,15 @@ public class HumanPlay {
final ManaCostBeingPaid manaCost;
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
manaCost = new ManaCostBeingPaid(ManaCost.ZERO);
} else {
}
else {
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
manaCost.applySpellCostChange(sa, false);
}
boolean isPaid = manaCost.isPaid();
if( !isPaid ) {
if (!isPaid) {
InputPayMana inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
Singletons.getControl().getInputQueue().setInputAndWait(inputPay);
isPaid = inputPay.isPaid();
@@ -211,7 +209,8 @@ public class HumanPlay {
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
req.playAbility(mayChooseNewTargets, true, false);
} else {
}
else {
if (sa.isSpell()) {
final Card c = sa.getSourceCard();
if (!c.isCopiedSpell()) {
@@ -243,11 +242,9 @@ public class HumanPlay {
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, new CostPayment(sa.getPayCosts(), sa));
req.playAbility(!useOldTargets, false, true);
} else {
if (payManaCostIfNeeded(player, sa)) {
AbilityUtils.resolve(sa);
}
else if (payManaCostIfNeeded(player, sa)) {
AbilityUtils.resolve(sa);
}
}
@@ -285,9 +282,7 @@ public class HumanPlay {
* a {@link forge.Command} object.
* @param sourceAbility TODO
*/
public static boolean payCostDuringAbilityResolve(final Player p, final Card source, final Cost cost, SpellAbility sourceAbility
, String prompt) {
public static boolean payCostDuringAbilityResolve(final Player p, final Card source, final Cost cost, SpellAbility sourceAbility, String prompt) {
// Only human player pays this way
Card current = null; // Used in spells with RepeatEach effect to distinguish cards, Cut the Tethers
if (!source.getRemembered().isEmpty()) {
@@ -331,7 +326,6 @@ public class HumanPlay {
p.payLife(amount, null);
}
else if (part instanceof CostDraw) {
final int amount = getAmountFromPart(part, source, sourceAbility);
List<Player> res = new ArrayList<Player>();
@@ -361,13 +355,11 @@ public class HumanPlay {
player.drawCards(amount);
}
}
else if (part instanceof CostGainLife) {
if (!part.payHuman(sourceAbility, p.getGame())) {
return false;
}
}
else if (part instanceof CostAddMana) {
if (!GuiDialog.confirm(source, "Do you want to add "
+ ((CostAddMana) part).toString()
@@ -378,7 +370,6 @@ public class HumanPlay {
return false;
}
}
else if (part instanceof CostMill) {
final int amount = getAmountFromPart(part, source, sourceAbility);
final List<Card> list = p.getCardsIn(ZoneType.Library);
@@ -388,7 +379,6 @@ public class HumanPlay {
List<Card> listmill = p.getCardsIn(ZoneType.Library, amount);
((CostMill) part).executePayment(sourceAbility, listmill);
}
else if (part instanceof CostFlipCoin) {
final int amount = getAmountFromPart(part, source, sourceAbility);
if (!GuiDialog.confirm(source, "Do you want to flip " + amount + " coin(s)?" + orString))
@@ -398,7 +388,6 @@ public class HumanPlay {
FlipCoinEffect.flipCoinCall(p, sourceAbility, n);
}
}
else if (part instanceof CostDamage) {
int amount = getAmountFromPartX(part, source, sourceAbility);
if (!p.canPayLife(amount))
@@ -409,7 +398,6 @@ public class HumanPlay {
p.addDamage(amount, source);
}
else if (part instanceof CostPutCounter) {
CounterType counterType = ((CostPutCounter) part).getCounter();
int amount = getAmountFromPartX(part, source, sourceAbility);
@@ -428,10 +416,9 @@ public class HumanPlay {
List<Card> list = p.getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, part.getType().split(";"), p, source);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "add a counter." + orString);
if(!hasPaid) return false;
if (!hasPaid) return false;
}
}
else if (part instanceof CostRemoveCounter) {
CounterType counterType = ((CostRemoveCounter) part).getCounter();
int amount = getAmountFromPartX(part, source, sourceAbility);
@@ -439,12 +426,11 @@ public class HumanPlay {
if (!part.canPay(sourceAbility))
return false;
if ( false == GuiDialog.confirm(source, "Do you want to remove " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " from " + source + "?"))
if (false == GuiDialog.confirm(source, "Do you want to remove " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " from " + source + "?"))
return false;
source.subtractCounter(counterType, amount);
}
else if (part instanceof CostRemoveAnyCounter) {
int amount = getAmountFromPartX(part, source, sourceAbility);
List<Card> list = new ArrayList<Card>(p.getCardsIn(ZoneType.Battlefield));
@@ -494,7 +480,6 @@ public class HumanPlay {
amount--;
}
}
else if (part instanceof CostExile) {
if ("All".equals(part.getType())) {
if (false == GuiDialog.confirm(source, "Do you want to exile all cards in your graveyard?"))
@@ -532,7 +517,6 @@ public class HumanPlay {
}
}
}
else if (part instanceof CostPutCardToLib) {
int amount = Integer.parseInt(((CostPutCardToLib) part).getAmount());
final ZoneType from = ((CostPutCardToLib) part).getFrom();
@@ -577,7 +561,8 @@ public class HumanPlay {
return false;
}
}
} else if (from == ZoneType.Hand) { // Tainted Specter
}
else if (from == ZoneType.Hand) { // Tainted Specter
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "put into library." + orString);
if (!hasPaid) {
return false;
@@ -585,51 +570,56 @@ public class HumanPlay {
}
return true;
}
else if (part instanceof CostSacrifice) {
int amount = Integer.parseInt(((CostSacrifice)part).getAmount());
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "sacrifice." + orString);
if(!hasPaid) return false;
} else if (part instanceof CostGainControl) {
if (!hasPaid) return false;
}
else if (part instanceof CostGainControl) {
int amount = Integer.parseInt(((CostGainControl)part).getAmount());
List<Card> list = CardLists.getValidCards(p.getGame().getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "gain control." + orString);
if(!hasPaid) return false;
} else if (part instanceof CostReturn) {
if (!hasPaid) return false;
}
else if (part instanceof CostReturn) {
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
int amount = getAmountFromPartX(part, source, sourceAbility);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "return to hand." + orString);
if(!hasPaid) return false;
} else if (part instanceof CostDiscard) {
if (!hasPaid) return false;
}
else if (part instanceof CostDiscard) {
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
int amount = getAmountFromPartX(part, source, sourceAbility);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "discard." + orString);
if(!hasPaid) return false;
} else if (part instanceof CostReveal) {
if (!hasPaid) return false;
}
else if (part instanceof CostReveal) {
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
int amount = getAmountFromPartX(part, source, sourceAbility);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "reveal." + orString);
if(!hasPaid) return false;
} else if (part instanceof CostTapType) {
if (!hasPaid) return false;
}
else if (part instanceof CostTapType) {
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
list = CardLists.filter(list, Presets.UNTAPPED);
int amount = getAmountFromPartX(part, source, sourceAbility);
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "tap." + orString);
if(!hasPaid) return false;
if (!hasPaid) return false;
}
else if (part instanceof CostPartMana ) {
if (!((CostPartMana) part).getManaToPay().isZero()) // non-zero costs require input
else if (part instanceof CostPartMana) {
if (!((CostPartMana) part).getManaToPay().isZero()) { // non-zero costs require input
mayRemovePart = false;
} else {
}
}
else {
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - An unhandled type of cost was met: " + part.getClass());
}
if( mayRemovePart )
if (mayRemovePart) {
remainingParts.remove(part);
}
}
if (remainingParts.isEmpty()) {
return true;
@@ -639,14 +629,15 @@ public class HumanPlay {
}
costPart = remainingParts.get(0);
// check this is a mana cost
if (!(costPart instanceof CostPartMana ))
if (!(costPart instanceof CostPartMana)) {
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - The remaining payment type is not Mana.");
}
if (prompt == null) {
String promptCurrent = current == null ? "" : "Current Card: " + current + "\r\n";
prompt = source + "\r\n" + promptCurrent;
String promptCurrent = current == null ? "" : "Current Card: " + current;
prompt = source + "\n" + promptCurrent;
}
InputPayMana toSet = new InputPayManaExecuteCommands(p, prompt, cost.getCostMana().getManaToPay());
InputPayMana toSet = new InputPayManaExecuteCommands(source, p, prompt, cost.getCostMana().getManaToPay());
Singletons.getControl().getInputQueue().setInputAndWait(toSet);
return toSet.isPaid();
}
@@ -659,10 +650,11 @@ public class HumanPlay {
inp.setCancelAllowed(true);
Singletons.getControl().getInputQueue().setInputAndWait(inp);
if( inp.hasCancelled() || inp.getSelected().size() != amount)
if (inp.hasCancelled() || inp.getSelected().size() != amount) {
return false;
}
for(Card c : inp.getSelected()) {
for (Card c : inp.getSelected()) {
cpl.executePayment(sourceAbility, c);
}
if (sourceAbility != null) {
@@ -670,5 +662,4 @@ public class HumanPlay {
}
return true;
}
}

View File

@@ -2947,7 +2947,7 @@ public class Player extends GameEntity implements Comparable<Player> {
* @param proc
*/
public void runAsAi(Runnable proc) {
if (PlayerControllerAi.class.isInstance(controller)) {
if (controller instanceof PlayerControllerAi) {
proc.run(); //can just run with current controller if it's an AI controller
return;
}

View File

@@ -18,6 +18,7 @@
package forge.gui.input;
import forge.card.mana.ManaCost;
import forge.game.card.Card;
import forge.game.cost.Cost;
import forge.game.mana.ManaCostBeingPaid;
import forge.game.player.Player;
@@ -45,36 +46,24 @@ public class InputPayManaExecuteCommands extends InputPayMana {
private boolean bPaid = false;
public boolean isPaid() { return bPaid; }
/**
* <p>
* Constructor for Input_PayManaCost_Ability.
* </p>
*
* @param m
* a {@link java.lang.String} object.
* @param manaCost2
* a {@link java.lang.String} object.
* @param paidCommand2
* a {@link forge.Command} object.
* @param unpaidCommand2
* a {@link forge.Command} object.
*/
public InputPayManaExecuteCommands(final Player p, final String prompt, final ManaCost manaCost2) {
super(new SpellAbility(null, Cost.Zero) {
public InputPayManaExecuteCommands(final Card sourceCard, final Player p, final String prompt, final ManaCost manaCost0) {
super(new SpellAbility(sourceCard, Cost.Zero) {
@Override public void resolve() {}
@Override public Player getActivatingPlayer() { return p; }
@Override public boolean canPlay() { return false; }
});
this.originalManaCost = manaCost2;
this.originalManaCost = manaCost0;
this.phyLifeToLose = 0;
this.message = prompt;
this.manaCost = new ManaCostBeingPaid(this.originalManaCost);
}
@Override
public void selectPlayer(final Player selectedPlayer) {
if (player == selectedPlayer) {
@@ -105,7 +94,7 @@ public class InputPayManaExecuteCommands extends InputPayMana {
/** {@inheritDoc} */
@Override
protected String getMessage() {
final StringBuilder msg = new StringBuilder(this.message + "Pay Mana Cost: " + this.manaCost);
final StringBuilder msg = new StringBuilder(this.message + "\n\nPay Mana Cost: " + this.manaCost);
if (this.phyLifeToLose > 0) {
msg.append(" (");
msg.append(this.phyLifeToLose);