From 8a74175d213251aa346d11b0d2b8e4569eb67f4a Mon Sep 17 00:00:00 2001 From: magenoxx Date: Wed, 26 Oct 2011 14:22:54 +0400 Subject: [PATCH] Reimplemented CastSpellLastTurnWatcher. Possible fix for Issue 337. (but still doesn't work correctly because of wrong behavior in game state copying). --- .../NoSpellsWereCastLastTurnCondition.java | 9 +++++- ...OrMoreSpellsWereCastLastTurnCondition.java | 9 +++++- .../common/CastSpellLastTurnWatcher.java | 30 ++++++++++++++----- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Mage/src/mage/abilities/condition/common/NoSpellsWereCastLastTurnCondition.java b/Mage/src/mage/abilities/condition/common/NoSpellsWereCastLastTurnCondition.java index 102f1ab9b10..61d78f90ed8 100644 --- a/Mage/src/mage/abilities/condition/common/NoSpellsWereCastLastTurnCondition.java +++ b/Mage/src/mage/abilities/condition/common/NoSpellsWereCastLastTurnCondition.java @@ -46,6 +46,13 @@ public class NoSpellsWereCastLastTurnCondition implements Condition { @Override public boolean apply(Game game, Ability source) { CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher"); - return watcher.getAmountOfSpellsCastOnPrevTurn() == 0; + // if any player cast spell, return false + for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) { + if (count > 0) { + return false; + } + } + // no one cast spell this turn + return true; } } diff --git a/Mage/src/mage/abilities/condition/common/TwoOrMoreSpellsWereCastLastTurnCondition.java b/Mage/src/mage/abilities/condition/common/TwoOrMoreSpellsWereCastLastTurnCondition.java index f38e7ea6de5..78d7c096191 100644 --- a/Mage/src/mage/abilities/condition/common/TwoOrMoreSpellsWereCastLastTurnCondition.java +++ b/Mage/src/mage/abilities/condition/common/TwoOrMoreSpellsWereCastLastTurnCondition.java @@ -46,6 +46,13 @@ public class TwoOrMoreSpellsWereCastLastTurnCondition implements Condition { @Override public boolean apply(Game game, Ability source) { CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher"); - return watcher.getAmountOfSpellsCastOnPrevTurn() >= 2; + // if any player cast more than two spells, return true + for (Integer count : watcher.getAmountOfSpellsCastOnPrevTurn().values()) { + if (count >= 2) { + return true; + } + } + // no one cast two or more spells this turn + return false; } } diff --git a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java index 3f98608d26c..dc72951a70f 100644 --- a/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java +++ b/Mage/src/mage/watchers/common/CastSpellLastTurnWatcher.java @@ -33,14 +33,18 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.watchers.WatcherImpl; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + /** * - * @author BetaSteward_at_googlemail.com + * @author nantuko, BetaSteward_at_googlemail.com */ public class CastSpellLastTurnWatcher extends WatcherImpl { - private int amountOfSpellsCastOnPrevTurn; - private int amountOfSpellsCastOnCurrentTurn; + private Map amountOfSpellsCastOnPrevTurn = new HashMap(); + private Map amountOfSpellsCastOnCurrentTurn = new HashMap(); public CastSpellLastTurnWatcher() { super("CastSpellLastTurnWatcher", WatcherScope.GAME); @@ -55,17 +59,29 @@ public class CastSpellLastTurnWatcher extends WatcherImpl getAmountOfSpellsCastOnPrevTurn() { return amountOfSpellsCastOnPrevTurn; }