diff --git a/Mage.Client/src/main/java/mage/client/util/PhaseManager.java b/Mage.Client/src/main/java/mage/client/util/PhaseManager.java index 890c4d5fa88..e5984055d49 100644 --- a/Mage.Client/src/main/java/mage/client/util/PhaseManager.java +++ b/Mage.Client/src/main/java/mage/client/util/PhaseManager.java @@ -1,12 +1,38 @@ +/* +* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are +* permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright notice, this list of +* conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright notice, this list +* of conditions and the following disclaimer in the documentation and/or other materials +* provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR +* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +* The views and conclusions contained in the software and documentation are those of the +* authors and should not be interpreted as representing official policies, either expressed +* or implied, of BetaSteward_at_googlemail.com. +*/ + package mage.client.util; import java.util.HashMap; import java.util.Map; -import java.util.UUID; import java.util.prefs.Preferences; import mage.client.MageFrame; import mage.view.GameView; -import mage.view.PlayerView; public class PhaseManager { @@ -32,6 +58,8 @@ public class PhaseManager { public static String MAIN_2_OTHERS = "main2Others"; public static String END_OF_TURN_OTHERS = "endOfTurnOthers"; + private static final Preferences prefs = MageFrame.getPreferences(); + private static Map mapYou = new HashMap() {{ put("Upkeep - play instants and activated abilities.", UPKEEP_YOU); put("Draw - play instants and activated abilities.", DRAW_YOU); @@ -57,29 +85,22 @@ public class PhaseManager { } public boolean isSkip(GameView gameView, String message) { + // no skipping if stack is not empty if (GameManager.getInstance().getStackSize() > 0) { return false; } - UUID activePlayer = null; - Map map = mapOthers; - for (PlayerView playerView : gameView.getPlayers()) { - if (playerView.isActive()) { - activePlayer = playerView.getPlayerId(); - if (activePlayer.equals(GameManager.getInstance().getCurrentPlayerUUID())) { - map = mapYou; - } - } - } - if (activePlayer == null) { + if (gameView.getActivePlayerId() == null) { throw new IllegalStateException("No active player found."); } - - for (Map.Entry entry : map.entrySet()) { - if (message.equals(entry.getKey())) { - Preferences prefs = MageFrame.getPreferences(); - String prop = prefs.get(entry.getValue(), PHASE_ON); - return !prop.equals(PHASE_ON); - } + String prefKey; + if (gameView.getActivePlayerId().equals(GameManager.getInstance().getCurrentPlayerUUID())) { + prefKey = mapYou.get(message); + } else { + prefKey = mapOthers.get(message); + } + if (prefKey != null) { + String prop = prefs.get(prefKey, PHASE_ON); + return !prop.equals(PHASE_ON); } return false; } diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 9d14e723fae..642b5664788 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -71,6 +71,7 @@ public class GameView implements Serializable { private List combat = new ArrayList(); private TurnPhase phase; private PhaseStep step; + private UUID activePlayerId; private String activePlayerName = ""; private String priorityPlayerName = ""; private int turn; @@ -140,6 +141,7 @@ public class GameView implements Serializable { this.phase = state.getTurn().getPhaseType(); this.step = state.getTurn().getStepType(); this.turn = state.getTurnNum(); + this.activePlayerId = state.getActivePlayerId(); if (state.getActivePlayerId() != null) { this.activePlayerName = state.getPlayer(state.getActivePlayerId()).getName(); } else { @@ -269,4 +271,8 @@ public class GameView implements Serializable { return priorityTime; } + public UUID getActivePlayerId() { + return activePlayerId; + } + }