From aa842efacc20a68a6c7027087d45015df9db991b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 24 Sep 2014 16:55:51 +0200 Subject: [PATCH] Added F5 button to skip priority until end step of opponent. Added PlayerAction handling. --- .../java/mage/client/game/FeedbackPanel.java | 3 +- .../main/java/mage/client/game/GamePanel.java | 24 +++++- .../java/mage/client/game/PlayAreaPanel.java | 22 +++-- .../client/remote/CallbackClientImpl.java | 3 +- .../java/mage/client/util/PhaseManager.java | 4 +- .../src/mage/interfaces/MageServer.java | 11 +-- Mage.Common/src/mage/remote/SessionImpl.java | 82 +------------------ .../src/mage/remote/interfaces/GamePlay.java | 44 ++-------- .../src/mage/player/human/HumanPlayer.java | 5 ++ .../main/java/mage/server/MageServerImpl.java | 81 ++---------------- .../java/mage/server/game/GameController.java | 42 +++++----- .../java/mage/server/game/GameManager.java | 44 ++-------- Mage/src/mage/constants/PlayerAction.java | 44 ++++++++++ Mage/src/mage/game/Game.java | 7 +- Mage/src/mage/game/GameImpl.java | 25 ++---- Mage/src/mage/players/Player.java | 7 +- Mage/src/mage/players/PlayerImpl.java | 64 +++++++++------ 17 files changed, 185 insertions(+), 327 deletions(-) create mode 100644 Mage/src/mage/constants/PlayerAction.java diff --git a/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java b/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java index 84c47246b5..23a273a694 100644 --- a/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java @@ -48,6 +48,7 @@ import mage.client.components.MageTextArea; import mage.client.dialog.MageDialog; import mage.client.util.audio.AudioManager; import mage.client.util.gui.ArrowBuilder; +import mage.constants.PlayerAction; import mage.remote.Session; import org.apache.log4j.Logger; @@ -304,7 +305,7 @@ public class FeedbackPanel extends javax.swing.JPanel { }//GEN-LAST:event_btnSpecialActionPerformed private void btnUndoActionPerformed(java.awt.event.ActionEvent evt) { - session.undo(gameId); + session.sendPlayerAction(PlayerAction.UNDO, gameId); } public void setHelperPanel(HelperPanel helper) { diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index b882eba2e8..2c23fd5c4c 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -66,6 +66,7 @@ import java.util.*; import java.util.List; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; +import mage.constants.PlayerAction; /** * @@ -942,6 +943,15 @@ public final class GamePanel extends javax.swing.JPanel { } }); + ks = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0); + this.getInputMap(c).put(ks, "F5_PRESS"); + this.getActionMap().put("F5_PRESS", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent actionEvent) { + btnUntilEndOfTurnActionPerformed(null); + } + }); + KeyStroke ks9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0); this.getInputMap(c).put(ks9, "F9_PRESS"); this.getActionMap().put("F9_PRESS", new AbstractAction() { @@ -1345,25 +1355,31 @@ public final class GamePanel extends javax.swing.JPanel { private void btnConcedeActionPerformed(java.awt.event.ActionEvent evt) { if (modalQuestion("Are you sure you want to concede?", "Confirm concede") == JOptionPane.YES_OPTION) { - session.concedeGame(gameId); + session.sendPlayerAction(PlayerAction.CONCEDE, gameId); } } private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) { if (feedbackPanel != null && FeedbackMode.SELECT.equals(feedbackPanel.getMode())) { - session.passTurnPriority(gameId); + session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId); + } + } + + private void btnUntilEndOfTurnActionPerformed(java.awt.event.ActionEvent evt) { + if (feedbackPanel != null && FeedbackMode.SELECT.equals(feedbackPanel.getMode())) { + session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_OPPONENTS_TURN_END_STEP, gameId); } } private void btnPassPriorityUntilNextYourTurnActionPerformed(java.awt.event.ActionEvent evt) { if (feedbackPanel != null && FeedbackMode.SELECT.equals(feedbackPanel.getMode())) { - session.passPriorityUntilNextYourTurn(gameId); + session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId); } } private void restorePriorityActionPerformed(java.awt.event.ActionEvent evt) { if (feedbackPanel != null) { - session.restorePriority(gameId); + session.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId); } } diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java index e08067e967..b7cf8e2a8d 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -50,6 +50,7 @@ import javax.swing.event.ChangeListener; import mage.cards.decks.importer.DeckImporterUtil; import mage.client.MageFrame; import mage.client.cards.BigCard; +import mage.constants.PlayerAction; import mage.view.PlayerView; /** @@ -149,7 +150,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - gamePanel.getSession().restorePriority(gameId); + gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId); } }); @@ -162,7 +163,18 @@ public class PlayAreaPanel extends javax.swing.JPanel { menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - gamePanel.getSession().passTurnPriority(gameId); + gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId); + } + }); + + menuItem = new JMenuItem("F5 - Skip phases until opponent's end step (stop on stack/attack/block)"); + popupMenu.add(menuItem); + + // Skip to next end step of turn (F5) + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_OPPONENTS_TURN_END_STEP, gameId); } }); @@ -173,7 +185,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - gamePanel.getSession().passPriorityUntilNextYourTurn(gameId); + gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId); } }); @@ -190,7 +202,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { public void actionPerformed(ActionEvent e) { boolean manaPoolAutomatic = ((JCheckBoxMenuItem)e.getSource()).getState(); gamePanel.setMenuStates(manaPoolAutomatic); - gamePanel.getSession().setManaPoolMode(manaPoolAutomatic, gameId); + gamePanel.getSession().sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON: PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId); } }); @@ -204,7 +216,7 @@ public class PlayAreaPanel extends javax.swing.JPanel { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the game?", "Confirm concede game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - MageFrame.getSession().concedeGame(gameId); + MageFrame.getSession().sendPlayerAction(PlayerAction.CONCEDE, gameId); } } }); diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index 82f7482a7d..02277a155e 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -374,8 +374,9 @@ public class CallbackClientImpl implements CallbackClient { .append("
Turn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over") .append("
F2 - Confirm \"Ok\", \"Yes\" or \"Done\" button") .append("
F4 - Skip current turn but stop on declare attackers/blockers and something on the stack") + .append("
F5 - Skip to next end step of opponent's turn but stop on declare attackers/blockers and something on the stack") .append("
F9 - Skip everything until your next turn") - .append("
F3 - Undo F4/F9").toString(), + .append("
F3 - Undo F4/F5/F9").toString(), null, MessageType.USER_INFO, ChatMessage.MessageColor.ORANGE); break; case TOURNAMENT: 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 0e866b4d8c..ae91a181fa 100644 --- a/Mage.Client/src/main/java/mage/client/util/PhaseManager.java +++ b/Mage.Client/src/main/java/mage/client/util/PhaseManager.java @@ -63,7 +63,7 @@ public class PhaseManager { private static final Preferences prefs = MageFrame.getPreferences(); - private static Map mapYou = new HashMap() {{ + private static final Map mapYou = new HashMap() {{ put("Upkeep - play instants and activated abilities.", UPKEEP_YOU); put("Draw - play instants and activated abilities.", DRAW_YOU); put("Precombat Main - play spells and abilities.", MAIN_YOU); @@ -73,7 +73,7 @@ public class PhaseManager { put("End Turn - play instants and activated abilities.", END_OF_TURN_YOU); }}; - private static Map mapOthers = new HashMap() {{ + private static final Map mapOthers = new HashMap() {{ put("Upkeep - play instants and activated abilities.", UPKEEP_OTHERS); put("Draw - play instants and activated abilities.", DRAW_OTHERS); put("Precombat Main - play instants and activated abilities.", MAIN_OTHERS); diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index 41ebd87139..380dbe7159 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -35,6 +35,7 @@ import mage.cards.decks.DeckCardLists; import mage.cards.repository.CardInfo; import mage.cards.repository.ExpansionInfo; import mage.constants.ManaType; +import mage.constants.PlayerAction; import mage.game.GameException; import mage.game.match.MatchOptions; import mage.game.tournament.TournamentOptions; @@ -115,16 +116,10 @@ public interface MageServer { void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException; void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException; void sendPlayerManaType(UUID gameId, UUID playerId, String sessionId, ManaType data) throws MageException; - void concedeGame(UUID gameId, String sessionId) throws MageException; void quitMatch(UUID gameId, String sessionId) throws MageException; - void undo(UUID gameId, String sessionId) throws MageException; - void setManaPoolMode(UUID gameId, String sessionId, boolean autoPayment) throws MageException; GameView getGameView(UUID gameId, String sessionId, UUID playerId) throws MageException; - - //priority methods - void passPriorityUntilNextYourTurn(UUID gameId, String sessionId) throws MageException; - void passTurnPriority(UUID gameId, String sessionId) throws MageException; - void restorePriority(UUID gameId, String sessionId) throws MageException; + // priority, undo, concede, mana pool + void sendPlayerAction(PlayerAction playerAction, UUID gameId, String sessionId) throws MageException; //tournament methods boolean startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException; diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index afbd044caa..d4e18b5a42 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -51,6 +51,7 @@ import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; import mage.constants.Constants.SessionState; import mage.constants.ManaType; +import mage.constants.PlayerAction; import mage.game.GameException; import mage.game.match.MatchOptions; import mage.game.tournament.TournamentOptions; @@ -1054,21 +1055,6 @@ public class SessionImpl implements Session { return false; } - @Override - public boolean concedeGame(UUID gameId) { - try { - if (isConnected()) { - server.concedeGame(gameId, sessionId); - return true; - } - } catch (MageException ex) { - handleMageException(ex); - } catch (Throwable t) { - handleThrowable(t); - } - return false; - } - @Override public boolean quitMatch(UUID gameId) { try { @@ -1113,10 +1099,10 @@ public class SessionImpl implements Session { } @Override - public boolean undo(UUID gameId) { + public boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId) { try { if (isConnected()) { - server.undo(gameId, sessionId); + server.sendPlayerAction(passPriorityAction, gameId, sessionId); return true; } } catch (MageException ex) { @@ -1126,52 +1112,7 @@ public class SessionImpl implements Session { } return false; } - - @Override - public boolean passPriorityUntilNextYourTurn(UUID gameId) { - try { - if (isConnected()) { - server.passPriorityUntilNextYourTurn(gameId, sessionId); - return true; - } - } catch (MageException ex) { - handleMageException(ex); - } catch (Throwable t) { - handleThrowable(t); - } - return false; - } - - @Override - public boolean passTurnPriority(UUID gameId) { - try { - if (isConnected()) { - server.passTurnPriority(gameId, sessionId); - return true; - } - } catch (MageException ex) { - handleMageException(ex); - } catch (Throwable t) { - handleThrowable(t); - } - return false; - } - - @Override - public boolean restorePriority(UUID gameId) { - try { - if (isConnected()) { - server.restorePriority(gameId, sessionId); - return true; - } - } catch (MageException ex) { - handleMageException(ex); - } catch (Throwable t) { - handleThrowable(t); - } - return false; - } - + @Override public boolean stopWatching(UUID gameId) { try { @@ -1262,21 +1203,6 @@ public class SessionImpl implements Session { return false; } - @Override - public boolean setManaPoolMode(boolean autoPayment, UUID gameId) { - try { - if (isConnected()) { - server.setManaPoolMode(gameId, sessionId, autoPayment); - return true; - } - } catch (MageException ex) { - handleMageException(ex); - } catch (Throwable t) { - handleThrowable(t); - } - return false; - } - @Override public boolean cheat(UUID gameId, UUID playerId, DeckCardLists deckList) { try { diff --git a/Mage.Common/src/mage/remote/interfaces/GamePlay.java b/Mage.Common/src/mage/remote/interfaces/GamePlay.java index 14af9f96cb..eb387c4206 100644 --- a/Mage.Common/src/mage/remote/interfaces/GamePlay.java +++ b/Mage.Common/src/mage/remote/interfaces/GamePlay.java @@ -30,6 +30,7 @@ package mage.remote.interfaces; import java.util.UUID; import mage.cards.decks.DeckCardLists; import mage.constants.ManaType; +import mage.constants.PlayerAction; import mage.view.DraftPickView; /** @@ -53,8 +54,6 @@ public interface GamePlay { boolean sendPlayerManaType(UUID gameId, UUID playerId, ManaType data); - boolean concedeGame(UUID gameId); - boolean quitMatch(UUID gameId); boolean quitTournament(UUID tournamentId); @@ -67,47 +66,18 @@ public interface GamePlay { DraftPickView sendCardPick(UUID draftId, UUID cardId); - boolean undo(UUID gameId); - - /*** Separate methods for priority handling ***/ /** * magenoxx: * it should be done separately as sendPlayer* methods calls are injected into the game flow * - this is similar to concedeGame method - */ - - /** - * Pass priority until next your turn. - * Don't stop at all even if something happens. - * - * @param gameId - * @return - */ - boolean passPriorityUntilNextYourTurn(UUID gameId); - - /** - * Passes current turn but stop on pre combat phase. - * - * @param gameId - * @return - */ - boolean passTurnPriority(UUID gameId); - - /** - * This method cancels all other calls made before. - * - * @param gameId - * @return - */ - boolean restorePriority(UUID gameId); - - /** - * This method toggles usage of mana pool * - * @param automatic true mana in pool will be used automatically + * This method sends player actions for a game + * priority handling, undo + * + * @param passPriorityAction * @param gameId - * @return + * @return */ - boolean setManaPoolMode(boolean automatic, UUID gameId); + boolean sendPlayerAction(PlayerAction passPriorityAction, UUID gameId); } diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index f4765e26c5..4e253deb74 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -444,6 +444,11 @@ public class HumanPlayer extends PlayerImpl { pass(game); return false; } + if (passedUntilEndOfTurn && game.getStack().isEmpty() && + (!game.getTurn().getStepType().equals(PhaseStep.END_TURN) || playerId.equals(game.getActivePlayerId()))) { + pass(game); + return false; + } updateGameStatePriority("priority", game); game.firePriorityEvent(playerId); waitForResponse(game); diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index ddeb36888c..eaeb5a2538 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -66,6 +66,7 @@ import java.util.Locale; import java.util.UUID; import java.util.concurrent.ExecutorService; import mage.constants.ManaType; +import mage.constants.PlayerAction; import mage.constants.TableState; /** @@ -663,32 +664,6 @@ public class MageServerImpl implements MageServer { }); } - @Override - public void setManaPoolMode(final UUID gameId, final String sessionId, final boolean autoPayment) throws MageException { - execute("setManaPoolMode", sessionId, new Action() { - @Override - public void execute() { - UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); - GameManager.getInstance().setManaPoolMode(gameId, userId, autoPayment); - } - }); - } - - @Override - public void concedeGame(final UUID gameId, final String sessionId) throws MageException { - execute("concedeGame", sessionId, new Action() { - @Override - public void execute() { - Session session = SessionManager.getInstance().getSession(sessionId); - if (session != null) { - GameManager.getInstance().concedeGame(gameId, session.getUserId()); - } else{ - logger.error("Session not found sessionId: "+ sessionId + " gameId:" +gameId); - } - } - }); - } - @Override public void quitMatch(final UUID gameId, final String sessionId) throws MageException { execute("quitMatch", sessionId, new Action() { @@ -740,8 +715,8 @@ public class MageServerImpl implements MageServer { } @Override - public void undo(final UUID gameId, final String sessionId) throws MageException { - execute("undo", sessionId, new Action() { + public void sendPlayerAction(final PlayerAction playerAction, final UUID gameId, final String sessionId) throws MageException { + execute("setdPlayerAction", sessionId, new Action() { @Override public void execute() { Session session = SessionManager.getInstance().getSession(sessionId); @@ -749,57 +724,11 @@ public class MageServerImpl implements MageServer { logger.error("Session not found sessionId: "+ sessionId + " gameId:" + gameId); return; } - GameManager.getInstance().undo(gameId, session.getUserId()); + GameManager.getInstance().sendPlayerAction(playerAction, gameId, session.getUserId()); } }); } - - @Override - public void passPriorityUntilNextYourTurn(final UUID gameId, final String sessionId) throws MageException { - execute("passPriorityUntilNextYourTurn", sessionId, new Action() { - @Override - public void execute() { - Session session = SessionManager.getInstance().getSession(sessionId); - if (session == null) { - logger.error("Session not found sessionId: "+ sessionId + " gameId:" + gameId); - return; - } - GameManager.getInstance().passPriorityUntilNextYourTurn(gameId, session.getUserId()); - } - }); - } - - @Override - public void passTurnPriority(final UUID gameId, final String sessionId) throws MageException { - execute("passTurnPriority", sessionId, new Action() { - @Override - public void execute() { - Session session = SessionManager.getInstance().getSession(sessionId); - if (session == null) { - logger.error("Session not found sessionId: "+ sessionId + " gameId:" + gameId); - return; - } - GameManager.getInstance().passTurnPriority(gameId, session.getUserId()); - } - }); - } - - @Override - public void restorePriority(final UUID gameId, final String sessionId) throws MageException { - execute("restorePriority", sessionId, new Action() { - @Override - public void execute() { - Session session = SessionManager.getInstance().getSession(sessionId); - if (session == null) { - logger.error("Session not found sessionId: "+ sessionId + " gameId:" + gameId); - return; - } - GameManager.getInstance().restorePriority(gameId, session.getUserId()); - } - }); - } - - + @Override public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException { return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() { diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index b91a12732c..581d9dbe04 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -65,6 +65,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.zip.GZIPOutputStream; +import mage.constants.PlayerAction; /** * @@ -359,14 +360,6 @@ public class GameController implements GameCallback { } } - public void concede(UUID userId) { - game.concede(getPlayerId(userId)); - } - - public void setManaPoolMode(UUID userId, boolean autoPayment) { - game.setManaPoolMode(getPlayerId(userId), autoPayment); - } - // public void removeUser(UUID userId) { // UUID playerId = userPlayerMap.get(userId); // if (playerId != null) { @@ -389,22 +382,25 @@ public class GameController implements GameCallback { game.quit(getPlayerId(userId)); } - public void undo(UUID userId) { - game.undo(getPlayerId(userId)); + public void sendPlayerAction(PlayerAction playerAction, UUID userId) { + switch(playerAction) { + case UNDO: + game.undo(getPlayerId(userId)); + break; + case CONCEDE: + game.concede(getPlayerId(userId)); + break; + case MANA_AUTO_PAYMENT_OFF: + game.setManaPoolMode(getPlayerId(userId), false); + break; + case MANA_AUTO_PAYMENT_ON: + game.setManaPoolMode(getPlayerId(userId), true); + break; + default: + game.sendPlayerAction(playerAction, getPlayerId(userId)); + } } - - public void passPriorityUntilNextYourTurn(UUID userId) { - game.passPriorityUntilNextYourTurn(getPlayerId(userId)); - } - - public void passTurnPriority(UUID userId) { - game.passTurnPriority(getPlayerId(userId)); - } - - public void restorePriority(UUID userId) { - game.restorePriority(getPlayerId(userId)); - } - + public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) { Deck deck; diff --git a/Mage.Server/src/main/java/mage/server/game/GameManager.java b/Mage.Server/src/main/java/mage/server/game/GameManager.java index 9fd8f61374..fd3acc8e08 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameManager.java +++ b/Mage.Server/src/main/java/mage/server/game/GameManager.java @@ -32,6 +32,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import mage.cards.decks.DeckCardLists; import mage.constants.ManaType; +import mage.constants.PlayerAction; import mage.game.Game; import mage.view.GameView; @@ -106,52 +107,17 @@ public class GameManager { } } - public void setManaPoolMode(UUID gameId, UUID userId, boolean autoPayment) { - GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.setManaPoolMode(userId, autoPayment); - } - } - - public void concedeGame(UUID gameId, UUID userId) { - GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.concede(userId); - } - } - public void quitMatch(UUID gameId, UUID userId) { GameController gameController = gameControllers.get(gameId); if (gameController != null) { gameController.quitMatch(userId); } } - - public void undo(UUID gameId, UUID userId) { + + public void sendPlayerAction(PlayerAction playerAction, UUID gameId, UUID userId) { GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.undo(userId); - } - } - - public void passPriorityUntilNextYourTurn(UUID gameId, UUID userId) { - GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.passPriorityUntilNextYourTurn(userId); - } - } - - public void passTurnPriority(UUID gameId, UUID userId) { - GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.passTurnPriority(userId); - } - } - - public void restorePriority(UUID gameId, UUID userId) { - GameController gameController = gameControllers.get(gameId); - if (gameController != null) { - gameController.restorePriority(userId); + if (gameController != null) { + gameController.sendPlayerAction(playerAction, userId); } } diff --git a/Mage/src/mage/constants/PlayerAction.java b/Mage/src/mage/constants/PlayerAction.java new file mode 100644 index 0000000000..eb7b6b0e0c --- /dev/null +++ b/Mage/src/mage/constants/PlayerAction.java @@ -0,0 +1,44 @@ +/* + * 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.constants; + +/** + * Defines player actions for a game + * + * @author LevelX2 + */ +public enum PlayerAction { + PASS_PRIORITY_UNTIL_MY_NEXT_TURN, + PASS_PRIORITY_UNTIL_OPPONENTS_TURN_END_STEP, + PASS_PRIORITY_UNTIL_NEXT_TURN, + PASS_PRIORITY_CANCEL_ALL_ACTIONS, + UNDO, + CONCEDE, + MANA_AUTO_PAYMENT_ON, + MANA_AUTO_PAYMENT_OFF +} \ No newline at end of file diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 1031f911fe..1b167e15bb 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -68,6 +68,7 @@ import mage.util.functions.ApplyToPermanent; import java.io.Serializable; import java.util.*; +import mage.constants.PlayerAction; public interface Game extends MageItem, Serializable { @@ -233,10 +234,8 @@ public interface Game extends MageItem, Serializable { void addCommander(Commander commander); void addPermanent(Permanent permanent); - // priority methods - void passPriorityUntilNextYourTurn(UUID userId); - void passTurnPriority(UUID userId); - void restorePriority(UUID userId); + // priority method + void sendPlayerAction(PlayerAction playerAction, UUID playerId); /** * This version supports copying of copies of any depth. diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 3481dd5799..a0cf12941c 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -1022,22 +1022,15 @@ public abstract class GameImpl implements Game, Serializable { } } } - + @Override - public synchronized void passPriorityUntilNextYourTurn(UUID playerId) { + public void sendPlayerAction(PlayerAction playerAction, UUID playerId) { Player player = state.getPlayer(playerId); if (player != null) { - player.passPriorityUntilNextYourTurn(this); - } - } - - @Override - public synchronized void passTurnPriority(UUID playerId) { - Player player = state.getPlayer(playerId); - if (player != null) { - player.passTurnPriority(this); - } + player.sendPlayerAction(playerAction, this); + } } + @Override public synchronized void setManaPoolMode(UUID playerId, boolean autoPayment) { @@ -1047,14 +1040,6 @@ public abstract class GameImpl implements Game, Serializable { } } - @Override - public synchronized void restorePriority(UUID playerId) { - Player player = state.getPlayer(playerId); - if (player != null) { - player.restorePriority(this); - } - } - @Override public void playPriority(UUID activePlayerId, boolean resuming) { int bookmark = 0; diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 8acf0a99a8..ffcd32c138 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -59,6 +59,7 @@ import mage.util.Copyable; import java.io.Serializable; import java.util.*; +import mage.constants.PlayerAction; import mage.game.combat.CombatGroup; /** @@ -256,10 +257,8 @@ public interface Player extends MageItem, Copyable { void abort(); void skip(); - //priority methods - void passPriorityUntilNextYourTurn(Game game); - void passTurnPriority(Game game); - void restorePriority(Game game); + // priority, undo, ... + void sendPlayerAction(PlayerAction passPriorityAction, Game game); int getStoredBookmark(); void setStoredBookmark(int bookmark); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index e3c69893d7..a496e778ac 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -81,6 +81,7 @@ import mage.constants.AsThoughEffectType; import mage.constants.CardType; import mage.constants.ManaType; import mage.constants.Outcome; +import mage.constants.PlayerAction; import mage.constants.PhaseStep; import mage.constants.RangeOfInfluence; import mage.constants.SpellAbilityType; @@ -149,17 +150,21 @@ public abstract class PlayerImpl implements Player, Serializable { protected int maxHandSize = 7; protected int maxAttackedBy = Integer.MAX_VALUE; protected ManaPool manaPool; + // priority control protected boolean passed; // player passed priority - protected boolean passedTurn; + protected boolean passedTurn; // F4 + protected boolean passedUntilEndOfTurn; // F5 + /** + * This indicates that player passed all turns until his own turn starts (F9). + * Note! This differs from passedTurn as it doesn't care about spells and abilities in the stack and will pass them as well. + */ + protected boolean passedAllTurns; + protected int turns; protected int storedBookmark = -1; protected int priorityTimeLeft = Integer.MAX_VALUE; - /** - * This indicates that player passed all turns until his own turn starts. - * Note! This differs from passedTurn as it doesn't care about spells and abilities in the stack and will pass them as well. - */ - protected boolean passedAllTurns; + // conceded or connection lost game protected boolean left; @@ -279,7 +284,9 @@ public abstract class PlayerImpl implements Player, Serializable { this.passed = player.passed; this.passedTurn = player.passedTurn; + this.passedUntilEndOfTurn = player.passedUntilEndOfTurn; this.passedAllTurns = player.passedAllTurns; + this.priorityTimeLeft = player.getPriorityTimeLeft(); this.reachedNextTurnAfterLeaving = player.reachedNextTurnAfterLeaving; @@ -386,6 +393,7 @@ public abstract class PlayerImpl implements Player, Serializable { this.playersUnderYourControl.clear(); this.passed = false; this.passedTurn = false; + this.passedUntilEndOfTurn = false; this.passedAllTurns = false; this.canGainLife = true; this.canLoseLife = true; @@ -533,6 +541,9 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public void endOfTurn(Game game) { this.passedTurn = false; + if (!game.getActivePlayerId().equals(playerId)) { + this.passedUntilEndOfTurn = false; + } } @Override @@ -1617,25 +1628,28 @@ public abstract class PlayerImpl implements Player, Serializable { } @Override - public void passPriorityUntilNextYourTurn(Game game) { - passedTurn = true; - passedAllTurns = true; - this.skip(); - logger.trace("Passed priority for turns"); - } - - @Override - public void passTurnPriority(Game game) { - passedTurn = true; - this.skip(); - logger.trace("Passed priority for turn"); - } - - @Override - public void restorePriority(Game game) { - passedAllTurns = false; - passedTurn = false; - logger.trace("Restore priority"); + public void sendPlayerAction(PlayerAction passPriorityAction, Game game) { + switch(passPriorityAction) { + case PASS_PRIORITY_UNTIL_MY_NEXT_TURN: + passedTurn = true; + passedAllTurns = true; + this.skip(); + break; + case PASS_PRIORITY_UNTIL_OPPONENTS_TURN_END_STEP: + passedUntilEndOfTurn = true; + this.skip(); + break; + case PASS_PRIORITY_UNTIL_NEXT_TURN: + passedTurn = true; + this.skip(); + break; + case PASS_PRIORITY_CANCEL_ALL_ACTIONS: + passedAllTurns = false; + passedTurn = false; + passedUntilEndOfTurn = false; + break; + } + logger.trace("PASS Priority: " + passPriorityAction.toString()); } @Override