refactor: update Lobby for changes to the game library
This commit is contained in:
parent
ae64d51a73
commit
68bbf07ac6
@ -1,8 +1,6 @@
|
|||||||
package uulm.teamname.marvelous.server.lobby;
|
package uulm.teamname.marvelous.server.lobby;
|
||||||
|
|
||||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
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.Event;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||||
@ -39,50 +37,44 @@ public class Lobby extends EventObserver {
|
|||||||
|
|
||||||
for(Request request: requests) {
|
for(Request request: requests) {
|
||||||
switch(request.type) {
|
switch(request.type) {
|
||||||
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest, EndRoundRequest -> {
|
||||||
if(!pause.isPaused()) {
|
if(!pause.isPaused()) {
|
||||||
//if game is paused, no actions should happen
|
stateRelevant.add(request);
|
||||||
stateRelevant.add(request); // these need to be checked all together by the game instance itself
|
}else {
|
||||||
}
|
// if game is paused, no actions should happen
|
||||||
else {
|
reject(source);
|
||||||
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
|
case PauseStartRequest, PauseStopRequest -> {
|
||||||
//if game is paused only PauseStop, Disconnect and Req are available
|
if(request.type == RequestType.PauseStartRequest || pause.isPaused()) {
|
||||||
if(!pause.isPaused()){
|
|
||||||
processRequest(source, request);
|
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);
|
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
|
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
|
// 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) {
|
private void processRequest(Participant source, Request request) {
|
||||||
//TODO: handle the rest of the requests
|
|
||||||
switch(request.type) {
|
switch(request.type) {
|
||||||
case PauseStopRequest -> {
|
case PauseStopRequest -> {
|
||||||
pause.pauseEnd();
|
pause.stop();
|
||||||
connection.sendEvents(source, new EventBuilder(EventType.PauseStopEvent).buildGameStateEvent(), game.getGameStateEvent());
|
connection.sendEvents(source, new EventBuilder(EventType.PauseStopEvent).buildGameStateEvent(), game.getGameStateEvent());
|
||||||
}
|
}
|
||||||
case PauseStartRequest -> {
|
case PauseStartRequest -> {
|
||||||
pause.pauseGame();
|
pause.start();
|
||||||
connection.sendEvents(source, new EventBuilder(EventType.PauseStartEvent).buildGameStateEvent(), game.getGameStateEvent());
|
connection.sendEvents(source, new EventBuilder(EventType.PauseStartEvent).buildGameStateEvent(), game.getGameStateEvent());
|
||||||
}
|
|
||||||
case EndRoundRequest -> {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
case DisconnectRequest -> {
|
case DisconnectRequest -> {
|
||||||
connection.removePlayer(source);
|
connection.removePlayer(source);
|
||||||
@ -94,17 +86,7 @@ public class Lobby extends EventObserver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endRound(){
|
private void reject(Participant source) {
|
||||||
ArrayList Entitys = new ArrayList<>();
|
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
||||||
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(){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,13 @@ public class PauseHandler {
|
|||||||
public PauseHandler(){
|
public PauseHandler(){
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
public void pauseGame(){
|
|
||||||
|
public void start() {
|
||||||
if(!paused)
|
if(!paused)
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
public void pauseEnd(){
|
|
||||||
|
public void stop() {
|
||||||
if(paused)
|
if(paused)
|
||||||
paused = false;
|
paused = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user