refactor: update Lobby for changes to the game library

This commit is contained in:
punchready 2021-05-27 18:16:08 +02:00
parent ae64d51a73
commit 68bbf07ac6
2 changed files with 23 additions and 39 deletions

View File

@ -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 ) {
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);
}
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
}
}
}
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());
}
}

View File

@ -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;
}