diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/game/state/LotroGame.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/game/state/LotroGame.java index 77cc3971f..a58b842c5 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/game/state/LotroGame.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/game/state/LotroGame.java @@ -1,5 +1,6 @@ package com.gempukku.lotro.game.state; +import com.gempukku.lotro.common.Phase; import com.gempukku.lotro.communication.UserFeedback; import com.gempukku.lotro.game.ActionsEnvironment; import com.gempukku.lotro.game.LotroFormat; @@ -28,4 +29,6 @@ public interface LotroGame { public String getWinnerPlayerId(); public LotroFormat getFormat(); + + public boolean shouldAutoPass(String playerId, Phase phase); } diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/DefaultLotroGame.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/DefaultLotroGame.java index a5ae6f35a..e3189ef01 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/DefaultLotroGame.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/DefaultLotroGame.java @@ -34,6 +34,7 @@ public class DefaultLotroGame implements LotroGame { private LotroFormat _format; private Set _allPlayers; + private Map> _autoPassConfiguration = new HashMap>(); private String _winnerPlayerId; private Map _losers = new HashMap(); @@ -82,6 +83,14 @@ public class DefaultLotroGame implements LotroGame { ruleSet.applyRuleSet(); } + @Override + public boolean shouldAutoPass(String playerId, Phase phase) { + final Set passablePhases = _autoPassConfiguration.get(playerId); + if (passablePhases == null) + return false; + return passablePhases.contains(phase); + } + public void addGameResultListener(GameResultListener listener) { _gameResultListeners.add(listener); } @@ -207,4 +216,8 @@ public class DefaultLotroGame implements LotroGame { public void removeGameStateListener(GameStateListener gameStateListener) { _gameState.removeGameStateListener(gameStateListener); } + + public void setPlayerAutoPassSettings(String playerId, Set phases) { + _autoPassConfiguration.put(playerId, phases); + } } diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayerPlaysPhaseActionsUntilPassesGameProcess.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayerPlaysPhaseActionsUntilPassesGameProcess.java index 27ab8c302..66addd7fc 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayerPlaysPhaseActionsUntilPassesGameProcess.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayerPlaysPhaseActionsUntilPassesGameProcess.java @@ -23,18 +23,26 @@ public class PlayerPlaysPhaseActionsUntilPassesGameProcess implements GameProces public void process(final LotroGame game) { final List playableActions = game.getActionsEnvironment().getPhaseActions(_playerId); - game.getUserFeedback().sendAwaitingDecision(_playerId, - new CardActionSelectionDecision(game, 1, "Play " + game.getGameState().getCurrentPhase().getHumanReadable() + " action or Pass", playableActions) { - @Override - public void decisionMade(String result) throws DecisionResultInvalidException { - Action action = getSelectedAction(result); - if (action != null) { - _nextProcess = new PlayerPlaysPhaseActionsUntilPassesGameProcess(_playerId, _followingGameProcess); - game.getActionsEnvironment().addActionToStack(action); - } else - _nextProcess = _followingGameProcess; - } - }); + if (playableActions.size() == 0 & game.shouldAutoPass(_playerId, game.getGameState().getCurrentPhase())) { + playerPassed(); + } else { + game.getUserFeedback().sendAwaitingDecision(_playerId, + new CardActionSelectionDecision(game, 1, "Play " + game.getGameState().getCurrentPhase().getHumanReadable() + " action or Pass", playableActions) { + @Override + public void decisionMade(String result) throws DecisionResultInvalidException { + Action action = getSelectedAction(result); + if (action != null) { + _nextProcess = new PlayerPlaysPhaseActionsUntilPassesGameProcess(_playerId, _followingGameProcess); + game.getActionsEnvironment().addActionToStack(action); + } else + playerPassed(); + } + }); + } + } + + private void playerPassed() { + _nextProcess = _followingGameProcess; } @Override diff --git a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayersPlayPhaseActionsInOrderGameProcess.java b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayersPlayPhaseActionsInOrderGameProcess.java index 30a1058d7..91a2a5f0e 100644 --- a/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayersPlayPhaseActionsInOrderGameProcess.java +++ b/gemp-lotr/gemp-lotr-logic/src/main/java/com/gempukku/lotro/logic/timing/processes/turn/general/PlayersPlayPhaseActionsInOrderGameProcess.java @@ -42,27 +42,34 @@ public class PlayersPlayPhaseActionsInOrderGameProcess implements GameProcess { } final List playableActions = game.getActionsEnvironment().getPhaseActions(playerId); - - game.getUserFeedback().sendAwaitingDecision(playerId, - new CardActionSelectionDecision(game, 1, "Play " + game.getGameState().getCurrentPhase().getHumanReadable() + " action or Pass", playableActions) { - @Override - public void decisionMade(String result) throws DecisionResultInvalidException { - Action action = getSelectedAction(result); - if (action != null) { - _nextProcess = new PlayersPlayPhaseActionsInOrderGameProcess(_playOrder, 0, _followingGameProcess); - game.getActionsEnvironment().addActionToStack(action); - } else { - _consecutivePasses++; - if (_consecutivePasses >= _playOrder.getPlayerCount()) - _nextProcess = _followingGameProcess; - else - _nextProcess = new PlayersPlayPhaseActionsInOrderGameProcess(_playOrder, _consecutivePasses, _followingGameProcess); + if (playableActions.size() == 0 & game.shouldAutoPass(playerId, game.getGameState().getCurrentPhase())) { + playerPassed(); + } else { + game.getUserFeedback().sendAwaitingDecision(playerId, + new CardActionSelectionDecision(game, 1, "Play " + game.getGameState().getCurrentPhase().getHumanReadable() + " action or Pass", playableActions) { + @Override + public void decisionMade(String result) throws DecisionResultInvalidException { + Action action = getSelectedAction(result); + if (action != null) { + _nextProcess = new PlayersPlayPhaseActionsInOrderGameProcess(_playOrder, 0, _followingGameProcess); + game.getActionsEnvironment().addActionToStack(action); + } else { + playerPassed(); + } } - } - }); + }); + } } } + private void playerPassed() { + _consecutivePasses++; + if (_consecutivePasses >= _playOrder.getPlayerCount()) + _nextProcess = _followingGameProcess; + else + _nextProcess = new PlayersPlayPhaseActionsInOrderGameProcess(_playOrder, _consecutivePasses, _followingGameProcess); + } + @Override public GameProcess getNextProcess() { return _nextProcess; diff --git a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java index cc1d80d68..4348fc55d 100644 --- a/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java +++ b/gemp-lotr/gemp-lotr-server/src/main/java/com/gempukku/lotro/game/LotroGameMediator.java @@ -54,6 +54,12 @@ public class LotroGameMediator { _userFeedback.setGame(_lotroGame); } + public void setPlayerAutoPassSettings(String playerId, Set phases) { + if (_playersPlaying.contains(playerId)) { + _lotroGame.setPlayerAutoPassSettings(playerId, phases); + } + } + public void sendMessageToPlayers(String message) { _lotroGame.getGameState().sendMessage(message); } diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/GameResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/GameResource.java index 951e03062..27622f1f2 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/GameResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/GameResource.java @@ -1,5 +1,6 @@ package com.gempukku.lotro.server; +import com.gempukku.lotro.common.Phase; import com.gempukku.lotro.game.LotroGameMediator; import com.gempukku.lotro.game.LotroServer; import com.gempukku.lotro.game.ParticipantCommunicationVisitor; @@ -13,6 +14,7 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; @@ -22,7 +24,10 @@ import javax.ws.rs.core.Response; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import java.util.Collections; +import java.util.HashSet; import java.util.Map; +import java.util.Set; @Singleton @Path("/game") @@ -31,6 +36,18 @@ public class GameResource extends AbstractResource { @Context private LotroServer _lotroServer; + private static Set _autoPassAll = new HashSet(); + + static { + _autoPassAll.add(Phase.FELLOWSHIP); + _autoPassAll.add(Phase.SHADOW); + _autoPassAll.add(Phase.MANEUVER); + _autoPassAll.add(Phase.ARCHERY); + _autoPassAll.add(Phase.ASSIGNMENT); + _autoPassAll.add(Phase.SKIRMISH); + _autoPassAll.add(Phase.REGROUP); + } + @Path("/{gameId}") @GET @Produces(MediaType.APPLICATION_XML) @@ -45,6 +62,8 @@ public class GameResource extends AbstractResource { if (gameMediator == null) sendError(Response.Status.NOT_FOUND); + gameMediator.setPlayerAutoPassSettings(resourceOwner.getName(), getAutoPassPhases(request)); + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document doc = documentBuilder.newDocument(); @@ -56,6 +75,23 @@ public class GameResource extends AbstractResource { return doc; } + private Set getAutoPassPhases(HttpServletRequest request) { + for (Cookie cookie : request.getCookies()) { + if (cookie.getName().equals("autoPassPhases")) { + final String[] phases = cookie.getValue().split(","); + Set result = new HashSet(); + for (String phase : phases) + result.add(Phase.valueOf(phase)); + return result; + } + } + for (Cookie cookie : request.getCookies()) { + if (cookie.getName().equals("autoPass") && cookie.getValue().equals("false")) + return Collections.emptySet(); + } + return _autoPassAll; + } + @Path("/{gameId}/cardInfo") @GET @Produces("text/html") @@ -106,6 +142,8 @@ public class GameResource extends AbstractResource { if (gameMediator == null) sendError(Response.Status.NOT_FOUND); + gameMediator.setPlayerAutoPassSettings(resourceOwner.getName(), getAutoPassPhases(request)); + if (decisionId != null) { try { gameMediator.playerAnswered(resourceOwner, decisionId, decisionValue);