diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java index dc3ceeb..9e4aa05 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/Lobby.java @@ -1,8 +1,6 @@ package uulm.teamname.marvelous.server.lobby; import uulm.teamname.marvelous.gamelibrary.IntVector2; -import uulm.teamname.marvelous.gamelibrary.entities.Character; -import uulm.teamname.marvelous.gamelibrary.entities.EntityID; import uulm.teamname.marvelous.gamelibrary.events.Event; import uulm.teamname.marvelous.gamelibrary.events.EventBuilder; import uulm.teamname.marvelous.gamelibrary.events.EventType; @@ -39,50 +37,44 @@ public class Lobby extends EventObserver { for(Request request: requests) { switch(request.type) { - case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> { + case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest, EndRoundRequest -> { if(!pause.isPaused()) { - //if game is paused, no actions should happen - stateRelevant.add(request); // these need to be checked all together by the game instance itself - } - else { - connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent()); + stateRelevant.add(request); + }else { + // if game is paused, no actions should happen + reject(source); } } - case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> { - //if game is paused only PauseStop, Disconnect and Req are available - if(!pause.isPaused()){ + case PauseStartRequest, PauseStopRequest -> { + if(request.type == RequestType.PauseStartRequest || pause.isPaused()) { processRequest(source, request); + }else { + reject(source); } - else if(request.type != RequestType.PauseStartRequest && request.type != RequestType.EndRoundRequest ) { - processRequest(source, request); - } - else { - connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent()); - } + return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events + } + case DisconnectRequest, Req -> { + processRequest(source, request); return; // only one of these will ever be sent at once, and if that is the case, we wont have any other state relevant events } } } - if(!game.checkRequestsAndApply((Request[]) stateRelevant.toArray())) { + if(!game.checkRequestsAndApply(stateRelevant.toArray(new Request[0]))) { // requests don't apply, tell the client that they need to update their state - connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent()); + reject(source); } } private void processRequest(Participant source, Request request) { - //TODO: handle the rest of the requests switch(request.type) { case PauseStopRequest -> { - pause.pauseEnd(); + pause.stop(); connection.sendEvents(source, new EventBuilder(EventType.PauseStopEvent).buildGameStateEvent(), game.getGameStateEvent()); } case PauseStartRequest -> { - pause.pauseGame(); + pause.start(); connection.sendEvents(source, new EventBuilder(EventType.PauseStartEvent).buildGameStateEvent(), game.getGameStateEvent()); - } - case EndRoundRequest -> { - } case DisconnectRequest -> { connection.removePlayer(source); @@ -94,17 +86,7 @@ public class Lobby extends EventObserver { } } - public void endRound(){ - ArrayList Entitys = new ArrayList<>(); - for (EntityID id : game.state.getTurnOrder()) { - if(((Character) game.state.getEntities().findEntity(id)).hp.getValue() == 0){ - - } - } - int index = game.state.getTurnOrder().indexOf(game.state.getActiveCharacter()); - - } - public void closeLobby(){ - + private void reject(Participant source) { + connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent()); } } diff --git a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/PauseHandler.java b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/PauseHandler.java index 3ce2e1b..091b063 100644 --- a/Server/src/main/java/uulm/teamname/marvelous/server/lobby/PauseHandler.java +++ b/Server/src/main/java/uulm/teamname/marvelous/server/lobby/PauseHandler.java @@ -6,11 +6,13 @@ public class PauseHandler { public PauseHandler(){ paused = false; } - public void pauseGame(){ + + public void start() { if(!paused) paused = true; } - public void pauseEnd(){ + + public void stop() { if(paused) paused = false; }