From 794c7c7d494c709671a51984941b069c0fa3ecea Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 5 Mar 2015 18:01:56 +0100 Subject: [PATCH] * Storm - Fixed a bug that the number of copies for storm were calculated wrong if a card was cast multiple times in one turn (e.g. by Yawgmoth's Will). --- .../src/mage/abilities/keyword/StormAbility.java | 16 ++++++++++------ .../common/CastSpellLastTurnWatcher.java | 9 +++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Mage/src/mage/abilities/keyword/StormAbility.java b/Mage/src/mage/abilities/keyword/StormAbility.java index 05d1d8a8eab..372fb4bd2d8 100644 --- a/Mage/src/mage/abilities/keyword/StormAbility.java +++ b/Mage/src/mage/abilities/keyword/StormAbility.java @@ -102,12 +102,16 @@ class StormEffect extends OneShotEffect { if (spell != null) { CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher"); - for (int i = 0; i < watcher.getSpellOrder(spell) - 1; i++) { - Spell copy = spell.copySpell(); - copy.setControllerId(source.getControllerId()); - copy.setCopiedSpell(true); - game.getStack().push(copy); - copy.chooseNewTargets(game, source.getControllerId()); + int stormCount = watcher.getSpellOrder(spell) - 1; + if (stormCount > 0) { + game.informPlayers("Storm: " + spell.getName() + " will be copied " + stormCount + " time" + (stormCount > 1 ?"s":"")); + for (int i = 0; i < stormCount; i++) { + Spell copy = spell.copySpell(); + copy.setControllerId(source.getControllerId()); + copy.setCopiedSpell(true); + game.getStack().push(copy); + copy.chooseNewTargets(game, source.getControllerId()); + } } return true; } diff --git a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java index a0b6e4cb301..bfa93d16777 100644 --- a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java +++ b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; +import mage.MageObjectReference; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; @@ -48,7 +49,7 @@ public class CastSpellLastTurnWatcher extends Watcher { private final Map amountOfSpellsCastOnPrevTurn = new HashMap<>(); private final Map amountOfSpellsCastOnCurrentTurn = new HashMap<>(); - private final List spellsCastThisTurnInOrder = new ArrayList<>(); + private final List spellsCastThisTurnInOrder = new ArrayList<>(); public CastSpellLastTurnWatcher() { super("CastSpellLastTurnWatcher", WatcherScope.GAME); @@ -67,7 +68,7 @@ public class CastSpellLastTurnWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.SPELL_CAST) { - spellsCastThisTurnInOrder.add(event.getTargetId()); + spellsCastThisTurnInOrder.add(new MageObjectReference(event.getSourceId(), game)); UUID playerId = event.getPlayerId(); if (playerId != null) { Integer amount = amountOfSpellsCastOnCurrentTurn.get(playerId); @@ -116,9 +117,9 @@ public class CastSpellLastTurnWatcher extends Watcher { public int getSpellOrder(Spell spell) { int index = 0; - for (UUID uuid : spellsCastThisTurnInOrder) { + for (MageObjectReference mor : spellsCastThisTurnInOrder) { index++; - if (spell.getId().equals(uuid)) { + if (mor.refersTo(spell)) { return index; } }