From 7e73cf5d346f659bb154265ac6212af22502d7d4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 28 Apr 2018 00:52:04 +0200 Subject: [PATCH] * Mana Vault - Fixed that it doesn't return mana if payment is cancelled (fixes #4473) --- .../effects/common/DoIfCostPaid.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/effects/common/DoIfCostPaid.java b/Mage/src/main/java/mage/abilities/effects/common/DoIfCostPaid.java index 996f19e597a..e0882ae4466 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DoIfCostPaid.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DoIfCostPaid.java @@ -80,6 +80,7 @@ public class DoIfCostPaid extends OneShotEffect { if (cost.canPay(source, source.getSourceId(), player.getId(), game) && executingEffects.size() > 0 && (!optional || player.chooseUse(executingEffects.get(0).getOutcome(), message, source, game))) { cost.clearPaid(); + int bookmark = game.bookmarkState(); if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { for (Effect effect : executingEffects) { effect.setTargetPointer(this.targetPointer); @@ -90,13 +91,17 @@ public class DoIfCostPaid extends OneShotEffect { } } player.resetStoredBookmark(game); // otherwise you can e.g. undo card drawn with Mentor of the Meek - } else if (!otherwiseEffects.isEmpty()) { - for (Effect effect : otherwiseEffects) { - effect.setTargetPointer(this.targetPointer); - if (effect instanceof OneShotEffect) { - result &= effect.apply(game, source); - } else { - game.addEffect((ContinuousEffect) effect, source); + } else { + // Paying cost was cancels so try to undo payment so far + game.restoreState(bookmark, DoIfCostPaid.class.getName()); + if (!otherwiseEffects.isEmpty()) { + for (Effect effect : otherwiseEffects) { + effect.setTargetPointer(this.targetPointer); + if (effect instanceof OneShotEffect) { + result &= effect.apply(game, source); + } else { + game.addEffect((ContinuousEffect) effect, source); + } } } }