From 3ecb80f8d2ea8b1be950e183a097fad6be53143d Mon Sep 17 00:00:00 2001 From: Myrd Date: Sun, 15 Feb 2015 20:41:31 +0000 Subject: [PATCH] Slightly better fix for make canceling Delve refund exiled cards. I think this fixes a bug in the previous fix where AI would never exile the cards they chose to delve. --- .../main/java/forge/ai/ComputerUtilMana.java | 2 +- .../forge/game/mana/ManaCostAdjustment.java | 10 ++++-- forge-gui/CHANGES.txt | 2 ++ .../src/main/java/forge/player/HumanPlay.java | 32 +++++++++---------- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index 707cdb6cfd3..17f2effd8f8 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -894,7 +894,7 @@ public class ComputerUtilMana { restriction = payCosts.getCostMana().getRestiction(); } ManaCostBeingPaid cost = new ManaCostBeingPaid(mana, restriction); - ManaCostAdjustment.adjust(cost, sa, test); + ManaCostAdjustment.adjust(cost, sa, null, test); final Card card = sa.getHostCard(); // Tack xMana Payments into mana here if X is a set value diff --git a/forge-game/src/main/java/forge/game/mana/ManaCostAdjustment.java b/forge-game/src/main/java/forge/game/mana/ManaCostAdjustment.java index 7d6166cff8b..ee6c0353074 100644 --- a/forge-game/src/main/java/forge/game/mana/ManaCostAdjustment.java +++ b/forge-game/src/main/java/forge/game/mana/ManaCostAdjustment.java @@ -27,7 +27,9 @@ import forge.game.staticability.StaticAbility; import forge.game.zone.ZoneType; public class ManaCostAdjustment { - public static final void adjust(ManaCostBeingPaid cost, final SpellAbility sa, boolean test) { + // If cardsToDelveOut is null, will immediately exile the delved cards and remember them on the host card. + // Otherwise, will return them in cardsToDelveOut and the caller is responsible for doing the above. + public static final void adjust(ManaCostBeingPaid cost, final SpellAbility sa, CardCollection cardsToDelveOut, boolean test) { final Game game = sa.getActivatingPlayer().getGame(); final Card originalCard = sa.getHostCard(); @@ -95,9 +97,11 @@ public class ManaCostAdjustment { final CardCollectionView toExile = pc.getController().chooseCardsToDelve(cost.getUnpaidShards(ManaCostShard.COLORLESS), mutableGrave); for (final Card c : toExile) { cost.decreaseColorlessMana(1); - if (!test) { + if (cardsToDelveOut != null) { + cardsToDelveOut.add(c); + } else if (!test) { sa.getHostCard().addDelved(c); - //pc.getGame().getAction().exile(c); + pc.getGame().getAction().exile(c); } } } diff --git a/forge-gui/CHANGES.txt b/forge-gui/CHANGES.txt index 1436bfd7e76..2cec1be3633 100644 --- a/forge-gui/CHANGES.txt +++ b/forge-gui/CHANGES.txt @@ -13,6 +13,8 @@ On the Constructed screen, you can now select a new Net Decks category from the Contains all decks from gos's Forge Decks subforums, broken up by the column/event they were taken from. Won't cause startup to be slower since they are loaded on the fly. +- Canceling Delve now refunds exiled cards - +If you cancel casting a spell after selecting cards to Delve, the selected cards will no longer get exiled. ------------ Known Issues diff --git a/forge-gui/src/main/java/forge/player/HumanPlay.java b/forge-gui/src/main/java/forge/player/HumanPlay.java index 1ab6650b855..1008b6fd783 100644 --- a/forge-gui/src/main/java/forge/player/HumanPlay.java +++ b/forge-gui/src/main/java/forge/player/HumanPlay.java @@ -101,13 +101,6 @@ public class HumanPlay { p.getGame().getStack().add(sa); } - - if(sa.isDelve()) { - for(Card c : sa.getHostCard().getDelved()) { - p.getGame().getAction().exile(c); - } - sa.getHostCard().clearDelved(); - } } /** @@ -133,7 +126,7 @@ public class HumanPlay { } else { manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana()); - ManaCostAdjustment.adjust(manaCost, sa, false); + ManaCostAdjustment.adjust(manaCost, sa, null, false); } boolean isPaid = manaCost.isPaid(); @@ -674,12 +667,18 @@ public class HumanPlay { } - private static boolean handleOfferingAndConvoke(final SpellAbility ability, boolean manaInputCancelled, boolean isPaid) { - boolean done = !manaInputCancelled && isPaid; + private static boolean handleOfferingConvokeAndDelve(final SpellAbility ability, CardCollection cardsToDelve, boolean manaInputCancelled) { + if (!manaInputCancelled && !cardsToDelve.isEmpty()) { + Card hostCard = ability.getHostCard(); + for (final Card c : cardsToDelve) { + hostCard.addDelved(c); + hostCard.getGame().getAction().exile(c); + } + } if (ability.isOffering() && ability.getSacrificedAsOffering() != null) { final Card offering = ability.getSacrificedAsOffering(); offering.setUsedToPay(false); - if (done) { + if (!manaInputCancelled) { ability.getHostCard().getGame().getAction().sacrifice(offering, ability); } ability.resetSacrificedAsOffering(); @@ -687,13 +686,13 @@ public class HumanPlay { if (ability.getTappedForConvoke() != null) { for (final Card c : ability.getTappedForConvoke()) { c.setTapped(false); - if (done) { + if (!manaInputCancelled) { c.tap(); } } ability.clearTappedForConvoke(); } - return done; + return !manaInputCancelled; } public static boolean payManaCost(final PlayerControllerHuman controller, final ManaCost realCost, final CostPartMana mc, final SpellAbility ability, final Player activator, String prompt, boolean isActivatedSa) { @@ -726,8 +725,9 @@ public class HumanPlay { } } + CardCollection cardsToDelve = new CardCollection(); if (isActivatedSa) { - ManaCostAdjustment.adjust(toPay, ability, false); + ManaCostAdjustment.adjust(toPay, ability, cardsToDelve, false); } InputPayMana inpPayment; @@ -740,7 +740,7 @@ public class HumanPlay { inpPayment.setMessagePrefix(prompt); inpPayment.showAndWait(); if (!inpPayment.isPaid()) { - return handleOfferingAndConvoke(ability, true, false); + return handleOfferingConvokeAndDelve(ability, cardsToDelve, true); } source.setXManaCostPaidByColor(toPay.getXManaCostPaidByColor()); @@ -763,6 +763,6 @@ public class HumanPlay { } ability.clearTappedForConvoke(); } - return handleOfferingAndConvoke(ability, false, true); + return handleOfferingConvokeAndDelve(ability, cardsToDelve, false); } }