mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
payment code slightly unified.
added immediate return if player can't pay
This commit is contained in:
@@ -414,95 +414,88 @@ public final class GameActionUtil {
|
|||||||
return GuiDialog.confirm(source, "Do you want to pay 0?" + orString);
|
return GuiDialog.confirm(source, "Do you want to pay 0?" + orString);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasPaid = true;
|
|
||||||
//the following costs do not need inputs
|
//the following costs do not need inputs
|
||||||
for (CostPart part : parts) {
|
for (CostPart part : parts) {
|
||||||
boolean dontRemove = false;
|
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) && GuiDialog.confirm(source, "Do you want to pay " + amount + " life?" + orString)) {
|
if (!p.canPayLife(amount))
|
||||||
p.payLife(amount, null);
|
return false;
|
||||||
} else {
|
|
||||||
hasPaid = false;
|
if (false == GuiDialog.confirm(source, "Do you want to pay " + amount + " life?" + orString))
|
||||||
break;
|
return false;
|
||||||
}
|
|
||||||
|
p.payLife(amount, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) && GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?")) {
|
if (!p.canPayLife(amount))
|
||||||
p.addDamage(amount, source);
|
return false;
|
||||||
} else {
|
|
||||||
hasPaid = false;
|
if (false == GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?"))
|
||||||
break;
|
return false;
|
||||||
}
|
|
||||||
|
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);
|
||||||
String plural = amount > 1 ? "s" : "";
|
|
||||||
if (GuiDialog.confirm(source, "Do you want to put " + amount + " " + counterType.getName()
|
if (false == source.canHaveCountersPlacedOnIt(counterType)) {
|
||||||
+ " counter" + plural + " on " + source + "?")) {
|
String message = String.format("Won't be able to pay upkeep for %s but it can't have %s counters put on it.", source, counterType.getName());
|
||||||
if (source.canHaveCountersPlacedOnIt(counterType)) {
|
p.getGame().getGameLog().add("ResolveStack", message, 2);
|
||||||
source.addCounter(counterType, amount, false);
|
return false;
|
||||||
} else {
|
|
||||||
hasPaid = false;
|
|
||||||
p.getGame().getGameLog().add("ResolveStack", "Trying to pay upkeep for " + source + " but it can't have "
|
|
||||||
+ counterType.getName() + " counters put on it.", 2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hasPaid = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String plural = amount > 1 ? "s" : "";
|
||||||
|
if (false == GuiDialog.confirm(source, "Do you want to put " + amount + " " + counterType.getName() + " counter" + plural + " on " + source + "?"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
source.addCounter(counterType, amount, 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);
|
||||||
String plural = amount > 1 ? "s" : "";
|
String plural = amount > 1 ? "s" : "";
|
||||||
if (part.canPay(sourceAbility, source, p, cost, game)
|
|
||||||
&& GuiDialog.confirm(source, "Do you want to remove " + amount + " " + counterType.getName()
|
if (!part.canPay(sourceAbility, source, p, cost, game))
|
||||||
+ " counter" + plural + " from " + source + "?")) {
|
return false;
|
||||||
source.subtractCounter(counterType, amount);
|
|
||||||
} else {
|
if ( false == GuiDialog.confirm(source, "Do you want to remove " + amount + " " + counterType.getName() + " counter" + plural + " from " + source + "?"))
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
source.subtractCounter(counterType, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostExile) {
|
else if (part instanceof CostExile) {
|
||||||
if ("All".equals(part.getType())) {
|
if ("All".equals(part.getType())) {
|
||||||
if (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?"))
|
||||||
List<Card> cards = new ArrayList<Card>(p.getCardsIn(ZoneType.Graveyard));
|
return false;
|
||||||
for (final Card card : cards) {
|
|
||||||
p.getGame().getAction().exile(card);
|
List<Card> cards = new ArrayList<Card>(p.getCardsIn(ZoneType.Graveyard));
|
||||||
}
|
for (final Card card : cards) {
|
||||||
} else {
|
p.getGame().getAction().exile(card);
|
||||||
hasPaid = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
CostExile costExile = (CostExile) part;
|
CostExile costExile = (CostExile) part;
|
||||||
ZoneType from = costExile.getFrom();
|
ZoneType from = costExile.getFrom();
|
||||||
List<Card> list = CardLists.getValidCards(p.getCardsIn(from), part.getType().split(";"), p, source);
|
List<Card> list = CardLists.getValidCards(p.getCardsIn(from), part.getType().split(";"), p, source);
|
||||||
final int nNeeded = AbilityUtils.calculateAmount(source, part.getAmount(), ability);
|
final int nNeeded = AbilityUtils.calculateAmount(source, part.getAmount(), ability);
|
||||||
if (list.size() < nNeeded) {
|
if (list.size() < nNeeded)
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
// replace this with input
|
||||||
|
|
||||||
for (int i = 0; i < nNeeded; i++) {
|
for (int i = 0; i < nNeeded; i++) {
|
||||||
final Card c = GuiChoose.oneOrNone("Exile from " + from, list);
|
final Card c = GuiChoose.oneOrNone("Exile from " + from, list);
|
||||||
if (c != null) {
|
if (c == null)
|
||||||
list.remove(c);
|
return false;
|
||||||
p.getGame().getAction().exile(c);
|
|
||||||
} else {
|
list.remove(c);
|
||||||
hasPaid = false;
|
p.getGame().getAction().exile(c);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,23 +508,21 @@ public final class GameActionUtil {
|
|||||||
|
|
||||||
if (list.size() < amount) {
|
if (list.size() < amount) {
|
||||||
// unable to pay (not enough cards)
|
// unable to pay (not enough cards)
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiUtils.clearPanelSelections();
|
GuiUtils.clearPanelSelections();
|
||||||
GuiUtils.setPanelSelection(source);
|
GuiUtils.setPanelSelection(source);
|
||||||
|
|
||||||
List<Card> toSac = p.getController().choosePermanentsToSacrifice(list, amount, ability, false, true);
|
List<Card> toSac = p.getController().choosePermanentsToSacrifice(list, amount, ability, false, true);
|
||||||
if ( toSac.size() != amount ) {
|
if ( toSac.size() != amount )
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
CostPartWithList cpl = (CostPartWithList)part;
|
CostPartWithList cpl = (CostPartWithList)part;
|
||||||
for(Card c : toSac) {
|
for(Card c : toSac) {
|
||||||
cpl.executePayment(ability, c);
|
cpl.executePayment(sourceAbility, c);
|
||||||
}
|
}
|
||||||
cpl.addListToHash(ability);
|
cpl.addListToHash(sourceAbility);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostReturn) {
|
else if (part instanceof CostReturn) {
|
||||||
@@ -543,15 +534,14 @@ public final class GameActionUtil {
|
|||||||
inp.setCancelWithSelectedAllowed(true);
|
inp.setCancelWithSelectedAllowed(true);
|
||||||
|
|
||||||
FThreads.setInputAndWait(inp);
|
FThreads.setInputAndWait(inp);
|
||||||
if( inp.hasCancelled() || inp.getSelected().size() != amount) {
|
if( inp.hasCancelled() || inp.getSelected().size() != amount)
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
CostPartWithList cpl = (CostPartWithList)part;
|
CostPartWithList cpl = (CostPartWithList)part;
|
||||||
for(Card c : inp.getSelected()) {
|
for(Card c : inp.getSelected()) {
|
||||||
cpl.executePayment(ability, c);
|
cpl.executePayment(sourceAbility, c);
|
||||||
}
|
}
|
||||||
cpl.addListToHash(ability);
|
cpl.addListToHash(sourceAbility);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostDiscard) {
|
else if (part instanceof CostDiscard) {
|
||||||
@@ -563,32 +553,26 @@ public final class GameActionUtil {
|
|||||||
inp.setCancelWithSelectedAllowed(true);
|
inp.setCancelWithSelectedAllowed(true);
|
||||||
|
|
||||||
FThreads.setInputAndWait(inp);
|
FThreads.setInputAndWait(inp);
|
||||||
if( inp.hasCancelled() || inp.getSelected().size() != amount) {
|
if( inp.hasCancelled() || inp.getSelected().size() != amount)
|
||||||
hasPaid = false;
|
return false;
|
||||||
break;
|
|
||||||
}
|
|
||||||
CostPartWithList cpl = (CostPartWithList)part;
|
CostPartWithList cpl = (CostPartWithList)part;
|
||||||
for(Card c : inp.getSelected()) {
|
for(Card c : inp.getSelected()) {
|
||||||
cpl.executePayment(ability, c);
|
cpl.executePayment(sourceAbility, c);
|
||||||
}
|
}
|
||||||
cpl.addListToHash(ability);
|
cpl.addListToHash(sourceAbility);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (part instanceof CostPartMana ) {
|
else if (part instanceof CostPartMana ) {
|
||||||
if (!((CostPartMana) part).getManaToPay().equals("0")) // non-zero costs require input
|
if (!((CostPartMana) part).getManaToPay().equals("0")) // non-zero costs require input
|
||||||
dontRemove = true;
|
mayRemovePart = false;
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - An unhandled type of cost has ocurred: " + part.getClass());
|
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - An unhandled type of cost has ocurred: " + part.getClass());
|
||||||
|
|
||||||
|
if( mayRemovePart )
|
||||||
if ( !hasPaid )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if( !dontRemove )
|
|
||||||
remainingParts.remove(part);
|
remainingParts.remove(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuiUtils.clearPanelSelections();
|
|
||||||
|
|
||||||
if (remainingParts.isEmpty()) {
|
if (remainingParts.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user