mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Fix so abilities using InputPayManaExecuteCommands work with Auto button
This commit is contained in:
@@ -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) {
|
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();
|
adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard());
|
||||||
if (card != null) {
|
|
||||||
adjustManaCostToAvoidNegEffects(cost, card);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ManaPool manapool = ai.getManaPool();
|
final ManaPool manapool = ai.getManaPool();
|
||||||
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();
|
List<ManaCostShard> unpaidShards = cost.getUnpaidShards();
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ import forge.util.Lang;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HumanPlay {
|
public class HumanPlay {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Write javadoc for Constructor.
|
* TODO: Write javadoc for Constructor.
|
||||||
*/
|
*/
|
||||||
@@ -93,59 +92,57 @@ public class HumanPlay {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sa.setActivatingPlayer(p);
|
sa.setActivatingPlayer(p);
|
||||||
|
|
||||||
final Card source = sa.getSourceCard();
|
final Card source = sa.getSourceCard();
|
||||||
|
|
||||||
source.setSplitStateToPlayAbility(sa);
|
source.setSplitStateToPlayAbility(sa);
|
||||||
|
|
||||||
if (sa.getApi() == ApiType.Charm && !sa.isWrapper()) {
|
if (sa.getApi() == ApiType.Charm && !sa.isWrapper()) {
|
||||||
CharmEffect.makeChoices(sa);
|
CharmEffect.makeChoices(sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
sa = chooseOptionalAdditionalCosts(p, sa);
|
sa = chooseOptionalAdditionalCosts(p, sa);
|
||||||
|
|
||||||
if (sa == null) {
|
if (sa == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to check PayCosts, and Ability + All SubAbilities for Target
|
// Need to check PayCosts, and Ability + All SubAbilities for Target
|
||||||
boolean newAbility = sa.getPayCosts() != null;
|
boolean newAbility = sa.getPayCosts() != null;
|
||||||
SpellAbility ability = sa;
|
SpellAbility ability = sa;
|
||||||
while ((ability != null) && !newAbility) {
|
while ((ability != null) && !newAbility) {
|
||||||
final TargetRestrictions tgt = ability.getTargetRestrictions();
|
final TargetRestrictions tgt = ability.getTargetRestrictions();
|
||||||
|
|
||||||
newAbility |= tgt != null;
|
newAbility |= tgt != null;
|
||||||
ability = ability.getSubAbility();
|
ability = ability.getSubAbility();
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("Playing:" + sa.getDescription() + " of " + sa.getSourceCard() + " new = " + newAbility);
|
// System.out.println("Playing:" + sa.getDescription() + " of " + sa.getSourceCard() + " new = " + newAbility);
|
||||||
if (newAbility) {
|
if (newAbility) {
|
||||||
Cost abCost = sa.getPayCosts() == null ? new Cost("0", sa.isAbility()) : sa.getPayCosts();
|
Cost abCost = sa.getPayCosts() == null ? new Cost("0", sa.isAbility()) : sa.getPayCosts();
|
||||||
CostPayment payment = new CostPayment(abCost, sa);
|
CostPayment payment = new CostPayment(abCost, sa);
|
||||||
|
|
||||||
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
|
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
|
||||||
req.playAbility(true, false, false);
|
req.playAbility(true, false, false);
|
||||||
} else {
|
}
|
||||||
if (payManaCostIfNeeded(p, sa)) {
|
else if (payManaCostIfNeeded(p, sa)) {
|
||||||
if (sa.isSpell() && !source.isCopiedSpell()) {
|
if (sa.isSpell() && !source.isCopiedSpell()) {
|
||||||
sa.setSourceCard(p.getGame().getAction().moveToStack(source));
|
sa.setSourceCard(p.getGame().getAction().moveToStack(source));
|
||||||
}
|
}
|
||||||
p.getGame().getStack().add(sa);
|
p.getGame().getStack().add(sa);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* choose optional additional costs. For HUMAN only
|
* choose optional additional costs. For HUMAN only
|
||||||
* @param activator
|
* @param activator
|
||||||
*
|
*
|
||||||
* @param original
|
* @param original
|
||||||
* the original sa
|
* the original sa
|
||||||
* @return an ArrayList<SpellAbility>.
|
* @return an ArrayList<SpellAbility>.
|
||||||
*/
|
*/
|
||||||
static SpellAbility chooseOptionalAdditionalCosts(Player p, final SpellAbility original) {
|
static SpellAbility chooseOptionalAdditionalCosts(Player p, final SpellAbility original) {
|
||||||
if (!original.isSpell()) {
|
if (!original.isSpell()) {
|
||||||
return original;
|
return original;
|
||||||
}
|
}
|
||||||
@@ -154,17 +151,18 @@ public class HumanPlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean payManaCostIfNeeded(final Player p, final SpellAbility sa) {
|
private static boolean payManaCostIfNeeded(final Player p, final SpellAbility sa) {
|
||||||
final ManaCostBeingPaid manaCost;
|
final ManaCostBeingPaid manaCost;
|
||||||
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
|
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
|
||||||
manaCost = new ManaCostBeingPaid(ManaCost.ZERO);
|
manaCost = new ManaCostBeingPaid(ManaCost.ZERO);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
|
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
|
||||||
manaCost.applySpellCostChange(sa, false);
|
manaCost.applySpellCostChange(sa, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isPaid = manaCost.isPaid();
|
boolean isPaid = manaCost.isPaid();
|
||||||
|
|
||||||
if( !isPaid ) {
|
if (!isPaid) {
|
||||||
InputPayMana inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
|
InputPayMana inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
|
||||||
Singletons.getControl().getInputQueue().setInputAndWait(inputPay);
|
Singletons.getControl().getInputQueue().setInputAndWait(inputPay);
|
||||||
isPaid = inputPay.isPaid();
|
isPaid = inputPay.isPaid();
|
||||||
@@ -180,9 +178,9 @@ public class HumanPlay {
|
|||||||
public static final void playCardWithoutPayingManaCost(Player player, Card c) {
|
public static final void playCardWithoutPayingManaCost(Player player, Card c) {
|
||||||
final List<SpellAbility> choices = c.getBasicSpells();
|
final List<SpellAbility> choices = c.getBasicSpells();
|
||||||
// TODO add Buyback, Kicker, ... , spells here
|
// TODO add Buyback, Kicker, ... , spells here
|
||||||
|
|
||||||
SpellAbility sa = player.getController().getAbilityToPlay(choices);
|
SpellAbility sa = player.getController().getAbilityToPlay(choices);
|
||||||
|
|
||||||
if (sa != null) {
|
if (sa != null) {
|
||||||
sa.setActivatingPlayer(player);
|
sa.setActivatingPlayer(player);
|
||||||
playSaWithoutPayingManaCost(player.getGame(), sa, true);
|
playSaWithoutPayingManaCost(player.getGame(), sa, true);
|
||||||
@@ -200,18 +198,19 @@ public class HumanPlay {
|
|||||||
public static final void playSaWithoutPayingManaCost(final Game game, final SpellAbility sa, boolean mayChooseNewTargets) {
|
public static final void playSaWithoutPayingManaCost(final Game game, final SpellAbility sa, boolean mayChooseNewTargets) {
|
||||||
FThreads.assertExecutedByEdt(false);
|
FThreads.assertExecutedByEdt(false);
|
||||||
final Card source = sa.getSourceCard();
|
final Card source = sa.getSourceCard();
|
||||||
|
|
||||||
source.setSplitStateToPlayAbility(sa);
|
source.setSplitStateToPlayAbility(sa);
|
||||||
|
|
||||||
if (sa.getPayCosts() != null) {
|
if (sa.getPayCosts() != null) {
|
||||||
if (sa.getApi() == ApiType.Charm && !sa.isWrapper() && !sa.isCopied()) {
|
if (sa.getApi() == ApiType.Charm && !sa.isWrapper() && !sa.isCopied()) {
|
||||||
CharmEffect.makeChoices(sa);
|
CharmEffect.makeChoices(sa);
|
||||||
}
|
}
|
||||||
final CostPayment payment = new CostPayment(sa.getPayCosts(), sa);
|
final CostPayment payment = new CostPayment(sa.getPayCosts(), sa);
|
||||||
|
|
||||||
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
|
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, payment);
|
||||||
req.playAbility(mayChooseNewTargets, true, false);
|
req.playAbility(mayChooseNewTargets, true, false);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (sa.isSpell()) {
|
if (sa.isSpell()) {
|
||||||
final Card c = sa.getSourceCard();
|
final Card c = sa.getSourceCard();
|
||||||
if (!c.isCopiedSpell()) {
|
if (!c.isCopiedSpell()) {
|
||||||
@@ -238,21 +237,19 @@ public class HumanPlay {
|
|||||||
|
|
||||||
public final static void playSpellAbilityNoStack(final Player player, final SpellAbility sa, boolean useOldTargets) {
|
public final static void playSpellAbilityNoStack(final Player player, final SpellAbility sa, boolean useOldTargets) {
|
||||||
sa.setActivatingPlayer(player);
|
sa.setActivatingPlayer(player);
|
||||||
|
|
||||||
if (sa.getPayCosts() != null) {
|
if (sa.getPayCosts() != null) {
|
||||||
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, new CostPayment(sa.getPayCosts(), sa));
|
final HumanPlaySpellAbility req = new HumanPlaySpellAbility(sa, new CostPayment(sa.getPayCosts(), sa));
|
||||||
|
|
||||||
req.playAbility(!useOldTargets, false, true);
|
req.playAbility(!useOldTargets, false, true);
|
||||||
} else {
|
}
|
||||||
if (payManaCostIfNeeded(player, sa)) {
|
else if (payManaCostIfNeeded(player, sa)) {
|
||||||
AbilityUtils.resolve(sa);
|
AbilityUtils.resolve(sa);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
private static int getAmountFromPart(CostPart part, Card source, SpellAbility sourceAbility) {
|
private static int getAmountFromPart(CostPart part, Card source, SpellAbility sourceAbility) {
|
||||||
String amountString = part.getAmount();
|
String amountString = part.getAmount();
|
||||||
return StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString) : AbilityUtils.calculateAmount(source, amountString, sourceAbility);
|
return StringUtils.isNumeric(amountString) ? Integer.parseInt(amountString) : AbilityUtils.calculateAmount(source, amountString, sourceAbility);
|
||||||
@@ -285,20 +282,18 @@ public class HumanPlay {
|
|||||||
* a {@link forge.Command} object.
|
* a {@link forge.Command} object.
|
||||||
* @param sourceAbility TODO
|
* @param sourceAbility TODO
|
||||||
*/
|
*/
|
||||||
public static boolean payCostDuringAbilityResolve(final Player p, final Card source, final Cost cost, SpellAbility sourceAbility
|
public static boolean payCostDuringAbilityResolve(final Player p, final Card source, final Cost cost, SpellAbility sourceAbility, String prompt) {
|
||||||
, String prompt) {
|
|
||||||
|
|
||||||
// Only human player pays this way
|
// Only human player pays this way
|
||||||
Card current = null; // Used in spells with RepeatEach effect to distinguish cards, Cut the Tethers
|
Card current = null; // Used in spells with RepeatEach effect to distinguish cards, Cut the Tethers
|
||||||
if (!source.getRemembered().isEmpty()) {
|
if (!source.getRemembered().isEmpty()) {
|
||||||
if (source.getRemembered().get(0) instanceof Card) {
|
if (source.getRemembered().get(0) instanceof Card) {
|
||||||
current = (Card) source.getRemembered().get(0);
|
current = (Card) source.getRemembered().get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!source.getImprinted().isEmpty()) {
|
if (!source.getImprinted().isEmpty()) {
|
||||||
current = source.getImprinted().get(0);
|
current = source.getImprinted().get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<CostPart> parts = cost.getCostParts();
|
final List<CostPart> parts = cost.getCostParts();
|
||||||
ArrayList<CostPart> remainingParts = new ArrayList<CostPart>(cost.getCostParts());
|
ArrayList<CostPart> remainingParts = new ArrayList<CostPart>(cost.getCostParts());
|
||||||
CostPart costPart = null;
|
CostPart costPart = null;
|
||||||
@@ -320,7 +315,7 @@ public class HumanPlay {
|
|||||||
//the following costs do not need inputs
|
//the following costs do not need inputs
|
||||||
for (CostPart part : parts) {
|
for (CostPart part : parts) {
|
||||||
boolean mayRemovePart = true;
|
boolean mayRemovePart = true;
|
||||||
|
|
||||||
if (part instanceof CostPayLife) {
|
if (part instanceof CostPayLife) {
|
||||||
final int amount = getAmountFromPart(part, source, sourceAbility);
|
final int amount = getAmountFromPart(part, source, sourceAbility);
|
||||||
if (!p.canPayLife(amount))
|
if (!p.canPayLife(amount))
|
||||||
@@ -331,7 +326,6 @@ public class HumanPlay {
|
|||||||
|
|
||||||
p.payLife(amount, null);
|
p.payLife(amount, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostDraw) {
|
else if (part instanceof CostDraw) {
|
||||||
final int amount = getAmountFromPart(part, source, sourceAbility);
|
final int amount = getAmountFromPart(part, source, sourceAbility);
|
||||||
List<Player> res = new ArrayList<Player>();
|
List<Player> res = new ArrayList<Player>();
|
||||||
@@ -361,13 +355,11 @@ public class HumanPlay {
|
|||||||
player.drawCards(amount);
|
player.drawCards(amount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostGainLife) {
|
else if (part instanceof CostGainLife) {
|
||||||
if (!part.payHuman(sourceAbility, p.getGame())) {
|
if (!part.payHuman(sourceAbility, p.getGame())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostAddMana) {
|
else if (part instanceof CostAddMana) {
|
||||||
if (!GuiDialog.confirm(source, "Do you want to add "
|
if (!GuiDialog.confirm(source, "Do you want to add "
|
||||||
+ ((CostAddMana) part).toString()
|
+ ((CostAddMana) part).toString()
|
||||||
@@ -378,7 +370,6 @@ public class HumanPlay {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostMill) {
|
else if (part instanceof CostMill) {
|
||||||
final int amount = getAmountFromPart(part, source, sourceAbility);
|
final int amount = getAmountFromPart(part, source, sourceAbility);
|
||||||
final List<Card> list = p.getCardsIn(ZoneType.Library);
|
final List<Card> list = p.getCardsIn(ZoneType.Library);
|
||||||
@@ -388,7 +379,6 @@ public class HumanPlay {
|
|||||||
List<Card> listmill = p.getCardsIn(ZoneType.Library, amount);
|
List<Card> listmill = p.getCardsIn(ZoneType.Library, amount);
|
||||||
((CostMill) part).executePayment(sourceAbility, listmill);
|
((CostMill) part).executePayment(sourceAbility, listmill);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostFlipCoin) {
|
else if (part instanceof CostFlipCoin) {
|
||||||
final int amount = getAmountFromPart(part, source, sourceAbility);
|
final int amount = getAmountFromPart(part, source, sourceAbility);
|
||||||
if (!GuiDialog.confirm(source, "Do you want to flip " + amount + " coin(s)?" + orString))
|
if (!GuiDialog.confirm(source, "Do you want to flip " + amount + " coin(s)?" + orString))
|
||||||
@@ -398,18 +388,16 @@ public class HumanPlay {
|
|||||||
FlipCoinEffect.flipCoinCall(p, sourceAbility, n);
|
FlipCoinEffect.flipCoinCall(p, sourceAbility, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostDamage) {
|
else if (part instanceof CostDamage) {
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
if (!p.canPayLife(amount))
|
if (!p.canPayLife(amount))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (false == GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?"))
|
if (false == GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
p.addDamage(amount, source);
|
p.addDamage(amount, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostPutCounter) {
|
else if (part instanceof CostPutCounter) {
|
||||||
CounterType counterType = ((CostPutCounter) part).getCounter();
|
CounterType counterType = ((CostPutCounter) part).getCounter();
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
@@ -420,7 +408,7 @@ public class HumanPlay {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GuiDialog.confirm(source, "Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + source + "?"))
|
if (!GuiDialog.confirm(source, "Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + source + "?"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
source.addCounter(counterType, amount, false);
|
source.addCounter(counterType, amount, false);
|
||||||
@@ -428,23 +416,21 @@ public class HumanPlay {
|
|||||||
List<Card> list = p.getGame().getCardsIn(ZoneType.Battlefield);
|
List<Card> list = p.getGame().getCardsIn(ZoneType.Battlefield);
|
||||||
list = CardLists.getValidCards(list, part.getType().split(";"), p, source);
|
list = CardLists.getValidCards(list, part.getType().split(";"), p, source);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "add a counter." + orString);
|
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) {
|
else if (part instanceof CostRemoveCounter) {
|
||||||
CounterType counterType = ((CostRemoveCounter) part).getCounter();
|
CounterType counterType = ((CostRemoveCounter) part).getCounter();
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
|
|
||||||
if (!part.canPay(sourceAbility))
|
if (!part.canPay(sourceAbility))
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
source.subtractCounter(counterType, amount);
|
source.subtractCounter(counterType, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostRemoveAnyCounter) {
|
else if (part instanceof CostRemoveAnyCounter) {
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
List<Card> list = new ArrayList<Card>(p.getCardsIn(ZoneType.Battlefield));
|
List<Card> list = new ArrayList<Card>(p.getCardsIn(ZoneType.Battlefield));
|
||||||
@@ -494,12 +480,11 @@ public class HumanPlay {
|
|||||||
amount--;
|
amount--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostExile) {
|
else if (part instanceof CostExile) {
|
||||||
if ("All".equals(part.getType())) {
|
if ("All".equals(part.getType())) {
|
||||||
if (false == GuiDialog.confirm(source, "Do you want to exile all cards in your graveyard?"))
|
if (false == GuiDialog.confirm(source, "Do you want to exile all cards in your graveyard?"))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
List<Card> cards = new ArrayList<Card>(p.getCardsIn(ZoneType.Graveyard));
|
List<Card> cards = new ArrayList<Card>(p.getCardsIn(ZoneType.Graveyard));
|
||||||
for (final Card card : cards) {
|
for (final Card card : cards) {
|
||||||
p.getGame().getAction().exile(card);
|
p.getGame().getAction().exile(card);
|
||||||
@@ -526,13 +511,12 @@ public class HumanPlay {
|
|||||||
final Card c = GuiChoose.oneOrNone("Exile from " + from, list);
|
final Card c = GuiChoose.oneOrNone("Exile from " + from, list);
|
||||||
if (c == null)
|
if (c == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
list.remove(c);
|
list.remove(c);
|
||||||
p.getGame().getAction().exile(c);
|
p.getGame().getAction().exile(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostPutCardToLib) {
|
else if (part instanceof CostPutCardToLib) {
|
||||||
int amount = Integer.parseInt(((CostPutCardToLib) part).getAmount());
|
int amount = Integer.parseInt(((CostPutCardToLib) part).getAmount());
|
||||||
final ZoneType from = ((CostPutCardToLib) part).getFrom();
|
final ZoneType from = ((CostPutCardToLib) part).getFrom();
|
||||||
@@ -577,7 +561,8 @@ public class HumanPlay {
|
|||||||
return false;
|
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);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "put into library." + orString);
|
||||||
if (!hasPaid) {
|
if (!hasPaid) {
|
||||||
return false;
|
return false;
|
||||||
@@ -585,52 +570,57 @@ public class HumanPlay {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostSacrifice) {
|
else if (part instanceof CostSacrifice) {
|
||||||
int amount = Integer.parseInt(((CostSacrifice)part).getAmount());
|
int amount = Integer.parseInt(((CostSacrifice)part).getAmount());
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "sacrifice." + orString);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "sacrifice." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
} else if (part instanceof CostGainControl) {
|
}
|
||||||
|
else if (part instanceof CostGainControl) {
|
||||||
int amount = Integer.parseInt(((CostGainControl)part).getAmount());
|
int amount = Integer.parseInt(((CostGainControl)part).getAmount());
|
||||||
List<Card> list = CardLists.getValidCards(p.getGame().getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
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);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "gain control." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
} else if (part instanceof CostReturn) {
|
}
|
||||||
|
else if (part instanceof CostReturn) {
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "return to hand." + orString);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "return to hand." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
} else if (part instanceof CostDiscard) {
|
}
|
||||||
|
else if (part instanceof CostDiscard) {
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "discard." + orString);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "discard." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
} else if (part instanceof CostReveal) {
|
}
|
||||||
|
else if (part instanceof CostReveal) {
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Hand), part.getType(), p, source);
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "reveal." + orString);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "reveal." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
} else if (part instanceof CostTapType) {
|
}
|
||||||
|
else if (part instanceof CostTapType) {
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(ZoneType.Battlefield), part.getType(), p, source);
|
||||||
list = CardLists.filter(list, Presets.UNTAPPED);
|
list = CardLists.filter(list, Presets.UNTAPPED);
|
||||||
int amount = getAmountFromPartX(part, source, sourceAbility);
|
int amount = getAmountFromPartX(part, source, sourceAbility);
|
||||||
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "tap." + orString);
|
boolean hasPaid = payCostPart(sourceAbility, (CostPartWithList)part, amount, list, "tap." + orString);
|
||||||
if(!hasPaid) return false;
|
if (!hasPaid) return false;
|
||||||
}
|
}
|
||||||
|
else if (part instanceof CostPartMana) {
|
||||||
else if (part instanceof CostPartMana ) {
|
if (!((CostPartMana) part).getManaToPay().isZero()) { // non-zero costs require input
|
||||||
if (!((CostPartMana) part).getManaToPay().isZero()) // non-zero costs require input
|
mayRemovePart = false;
|
||||||
mayRemovePart = false;
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - An unhandled type of cost was met: " + part.getClass());
|
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - An unhandled type of cost was met: " + part.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mayRemovePart )
|
if (mayRemovePart) {
|
||||||
remainingParts.remove(part);
|
remainingParts.remove(part);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (remainingParts.isEmpty()) {
|
if (remainingParts.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -639,30 +629,32 @@ public class HumanPlay {
|
|||||||
}
|
}
|
||||||
costPart = remainingParts.get(0);
|
costPart = remainingParts.get(0);
|
||||||
// check this is a mana cost
|
// 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.");
|
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;
|
|
||||||
}
|
}
|
||||||
InputPayMana toSet = new InputPayManaExecuteCommands(p, prompt, cost.getCostMana().getManaToPay());
|
|
||||||
|
if (prompt == null) {
|
||||||
|
String promptCurrent = current == null ? "" : "Current Card: " + current;
|
||||||
|
prompt = source + "\n" + promptCurrent;
|
||||||
|
}
|
||||||
|
InputPayMana toSet = new InputPayManaExecuteCommands(source, p, prompt, cost.getCostMana().getManaToPay());
|
||||||
Singletons.getControl().getInputQueue().setInputAndWait(toSet);
|
Singletons.getControl().getInputQueue().setInputAndWait(toSet);
|
||||||
return toSet.isPaid();
|
return toSet.isPaid();
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
if (list.size() < amount) return false; // unable to pay (not enough cards)
|
if (list.size() < amount) return false; // unable to pay (not enough cards)
|
||||||
|
|
||||||
InputSelectCards inp = new InputSelectCardsFromList(amount, amount, list);
|
InputSelectCards inp = new InputSelectCardsFromList(amount, amount, list);
|
||||||
inp.setMessage("Select %d " + cpl.getDescriptiveType() + " card(s) to " + actionName);
|
inp.setMessage("Select %d " + cpl.getDescriptiveType() + " card(s) to " + actionName);
|
||||||
inp.setCancelAllowed(true);
|
inp.setCancelAllowed(true);
|
||||||
|
|
||||||
Singletons.getControl().getInputQueue().setInputAndWait(inp);
|
Singletons.getControl().getInputQueue().setInputAndWait(inp);
|
||||||
if( inp.hasCancelled() || inp.getSelected().size() != amount)
|
if (inp.hasCancelled() || inp.getSelected().size() != amount) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
for(Card c : inp.getSelected()) {
|
|
||||||
|
for (Card c : inp.getSelected()) {
|
||||||
cpl.executePayment(sourceAbility, c);
|
cpl.executePayment(sourceAbility, c);
|
||||||
}
|
}
|
||||||
if (sourceAbility != null) {
|
if (sourceAbility != null) {
|
||||||
@@ -670,5 +662,4 @@ public class HumanPlay {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2947,7 +2947,7 @@ public class Player extends GameEntity implements Comparable<Player> {
|
|||||||
* @param proc
|
* @param proc
|
||||||
*/
|
*/
|
||||||
public void runAsAi(Runnable 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
|
proc.run(); //can just run with current controller if it's an AI controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package forge.gui.input;
|
package forge.gui.input;
|
||||||
|
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
|
import forge.game.card.Card;
|
||||||
import forge.game.cost.Cost;
|
import forge.game.cost.Cost;
|
||||||
import forge.game.mana.ManaCostBeingPaid;
|
import forge.game.mana.ManaCostBeingPaid;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -45,36 +46,24 @@ public class InputPayManaExecuteCommands extends InputPayMana {
|
|||||||
private boolean bPaid = false;
|
private boolean bPaid = false;
|
||||||
public boolean isPaid() { return bPaid; }
|
public boolean isPaid() { return bPaid; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Constructor for Input_PayManaCost_Ability.
|
* Constructor for Input_PayManaCost_Ability.
|
||||||
* </p>
|
* </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) {
|
public InputPayManaExecuteCommands(final Card sourceCard, final Player p, final String prompt, final ManaCost manaCost0) {
|
||||||
super(new SpellAbility(null, Cost.Zero) {
|
super(new SpellAbility(sourceCard, Cost.Zero) {
|
||||||
@Override public void resolve() {}
|
@Override public void resolve() {}
|
||||||
@Override public Player getActivatingPlayer() { return p; }
|
@Override public Player getActivatingPlayer() { return p; }
|
||||||
@Override public boolean canPlay() { return false; }
|
@Override public boolean canPlay() { return false; }
|
||||||
});
|
});
|
||||||
this.originalManaCost = manaCost2;
|
this.originalManaCost = manaCost0;
|
||||||
this.phyLifeToLose = 0;
|
this.phyLifeToLose = 0;
|
||||||
this.message = prompt;
|
this.message = prompt;
|
||||||
|
|
||||||
this.manaCost = new ManaCostBeingPaid(this.originalManaCost);
|
this.manaCost = new ManaCostBeingPaid(this.originalManaCost);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectPlayer(final Player selectedPlayer) {
|
public void selectPlayer(final Player selectedPlayer) {
|
||||||
if (player == selectedPlayer) {
|
if (player == selectedPlayer) {
|
||||||
@@ -105,7 +94,7 @@ public class InputPayManaExecuteCommands extends InputPayMana {
|
|||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
protected String getMessage() {
|
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) {
|
if (this.phyLifeToLose > 0) {
|
||||||
msg.append(" (");
|
msg.append(" (");
|
||||||
msg.append(this.phyLifeToLose);
|
msg.append(this.phyLifeToLose);
|
||||||
|
|||||||
Reference in New Issue
Block a user