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.

This commit is contained in:
Myrd
2015-02-15 20:41:31 +00:00
parent babfd2f8bb
commit 3ecb80f8d2
4 changed files with 26 additions and 20 deletions

View File

@@ -894,7 +894,7 @@ public class ComputerUtilMana {
restriction = payCosts.getCostMana().getRestiction(); restriction = payCosts.getCostMana().getRestiction();
} }
ManaCostBeingPaid cost = new ManaCostBeingPaid(mana, restriction); ManaCostBeingPaid cost = new ManaCostBeingPaid(mana, restriction);
ManaCostAdjustment.adjust(cost, sa, test); ManaCostAdjustment.adjust(cost, sa, null, test);
final Card card = sa.getHostCard(); final Card card = sa.getHostCard();
// Tack xMana Payments into mana here if X is a set value // Tack xMana Payments into mana here if X is a set value

View File

@@ -27,7 +27,9 @@ import forge.game.staticability.StaticAbility;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
public class ManaCostAdjustment { 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 Game game = sa.getActivatingPlayer().getGame();
final Card originalCard = sa.getHostCard(); final Card originalCard = sa.getHostCard();
@@ -95,9 +97,11 @@ public class ManaCostAdjustment {
final CardCollectionView toExile = pc.getController().chooseCardsToDelve(cost.getUnpaidShards(ManaCostShard.COLORLESS), mutableGrave); final CardCollectionView toExile = pc.getController().chooseCardsToDelve(cost.getUnpaidShards(ManaCostShard.COLORLESS), mutableGrave);
for (final Card c : toExile) { for (final Card c : toExile) {
cost.decreaseColorlessMana(1); cost.decreaseColorlessMana(1);
if (!test) { if (cardsToDelveOut != null) {
cardsToDelveOut.add(c);
} else if (!test) {
sa.getHostCard().addDelved(c); sa.getHostCard().addDelved(c);
//pc.getGame().getAction().exile(c); pc.getGame().getAction().exile(c);
} }
} }
} }

View File

@@ -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. 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. 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 Known Issues

View File

@@ -101,13 +101,6 @@ public class HumanPlay {
p.getGame().getStack().add(sa); 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 { else {
manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana()); manaCost = new ManaCostBeingPaid(sa.getPayCosts().getTotalMana());
ManaCostAdjustment.adjust(manaCost, sa, false); ManaCostAdjustment.adjust(manaCost, sa, null, false);
} }
boolean isPaid = manaCost.isPaid(); boolean isPaid = manaCost.isPaid();
@@ -674,12 +667,18 @@ public class HumanPlay {
} }
private static boolean handleOfferingAndConvoke(final SpellAbility ability, boolean manaInputCancelled, boolean isPaid) { private static boolean handleOfferingConvokeAndDelve(final SpellAbility ability, CardCollection cardsToDelve, boolean manaInputCancelled) {
boolean done = !manaInputCancelled && isPaid; 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) { if (ability.isOffering() && ability.getSacrificedAsOffering() != null) {
final Card offering = ability.getSacrificedAsOffering(); final Card offering = ability.getSacrificedAsOffering();
offering.setUsedToPay(false); offering.setUsedToPay(false);
if (done) { if (!manaInputCancelled) {
ability.getHostCard().getGame().getAction().sacrifice(offering, ability); ability.getHostCard().getGame().getAction().sacrifice(offering, ability);
} }
ability.resetSacrificedAsOffering(); ability.resetSacrificedAsOffering();
@@ -687,13 +686,13 @@ public class HumanPlay {
if (ability.getTappedForConvoke() != null) { if (ability.getTappedForConvoke() != null) {
for (final Card c : ability.getTappedForConvoke()) { for (final Card c : ability.getTappedForConvoke()) {
c.setTapped(false); c.setTapped(false);
if (done) { if (!manaInputCancelled) {
c.tap(); c.tap();
} }
} }
ability.clearTappedForConvoke(); 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) { 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) { if (isActivatedSa) {
ManaCostAdjustment.adjust(toPay, ability, false); ManaCostAdjustment.adjust(toPay, ability, cardsToDelve, false);
} }
InputPayMana inpPayment; InputPayMana inpPayment;
@@ -740,7 +740,7 @@ public class HumanPlay {
inpPayment.setMessagePrefix(prompt); inpPayment.setMessagePrefix(prompt);
inpPayment.showAndWait(); inpPayment.showAndWait();
if (!inpPayment.isPaid()) { if (!inpPayment.isPaid()) {
return handleOfferingAndConvoke(ability, true, false); return handleOfferingConvokeAndDelve(ability, cardsToDelve, true);
} }
source.setXManaCostPaidByColor(toPay.getXManaCostPaidByColor()); source.setXManaCostPaidByColor(toPay.getXManaCostPaidByColor());
@@ -763,6 +763,6 @@ public class HumanPlay {
} }
ability.clearTappedForConvoke(); ability.clearTappedForConvoke();
} }
return handleOfferingAndConvoke(ability, false, true); return handleOfferingConvokeAndDelve(ability, cardsToDelve, false);
} }
} }