From de62867a5da8f14cf682fcf2734a3a0d608b6945 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 24 Aug 2017 23:19:15 +0200 Subject: [PATCH] * Collective Voyage - Undo mana payment if mana payment is canceled (fixes #3850). --- .../src/mage/cards/c/CollectiveVoyage.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java b/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java index 7518e2b2060..178cd63f69a 100644 --- a/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java +++ b/Mage.Sets/src/mage/cards/c/CollectiveVoyage.java @@ -27,6 +27,8 @@ */ package mage.cards.c; +import java.util.Objects; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.mana.GenericManaCost; @@ -42,9 +44,6 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInLibrary; -import java.util.Objects; -import java.util.UUID; - /** * * @author LevelX2 @@ -52,8 +51,7 @@ import java.util.UUID; public class CollectiveVoyage extends CardImpl { public CollectiveVoyage(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{G}"); - + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{G}"); // Join forces - Starting with you, each player may pay any amount of mana. Each player searches his or her library for up to X basic land cards, where X is the total amount of mana paid this way, puts them onto the battlefield tapped, then shuffles his or her library. this.getSpellAbility().addEffect(new CollectiveVoyageEffect()); @@ -91,7 +89,7 @@ class CollectiveVoyageEffect extends OneShotEffect { if (controller != null) { int xSum = 0; xSum += playerPaysXGenericMana(controller, source, game); - for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { if (!Objects.equals(playerId, controller.getId())) { Player player = game.getPlayer(playerId); if (player != null) { @@ -100,7 +98,7 @@ class CollectiveVoyageEffect extends OneShotEffect { } } } - for(UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { + for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { TargetCardInLibrary target = new TargetCardInLibrary(0, xSum, StaticFilters.FILTER_BASIC_LAND_CARD); @@ -128,6 +126,8 @@ class CollectiveVoyageEffect extends OneShotEffect { int xValue = 0; boolean payed = false; while (player.canRespond() && !payed) { + int bookmark = game.bookmarkState(); + player.resetStoredBookmark(game); xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); @@ -135,9 +135,14 @@ class CollectiveVoyageEffect extends OneShotEffect { } else { payed = true; } + if (!payed) { + game.restoreState(bookmark, "Collective Voyage"); + game.fireUpdatePlayersEvent(); + } else { + game.removeBookmark(bookmark); + } } game.informPlayers(new StringBuilder(player.getLogName()).append(" pays {").append(xValue).append("}.").toString()); return xValue; } } -