|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
package uulm.teamname.marvelous.server.Lobby;
|
|
|
|
|
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.Character;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityID;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.entities.EntityType;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
|
|
|
@ -8,7 +12,9 @@ import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.gamelogic.ParticipantType;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
|
|
|
|
import uulm.teamname.marvelous.gamelibrary.requests.RequestType;
|
|
|
|
|
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
|
|
|
|
|
import uulm.teamname.marvelous.server.LobbyManager.Participant;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
@ -16,6 +22,7 @@ public class Lobby extends EventObserver {
|
|
|
|
|
public final String gameID;
|
|
|
|
|
public final LobbyConnection connection;
|
|
|
|
|
public final GameInstance game;
|
|
|
|
|
private final PauseHandler pause = new PauseHandler();
|
|
|
|
|
|
|
|
|
|
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
|
|
|
|
this.gameID = gameID;
|
|
|
|
@ -30,16 +37,31 @@ public class Lobby extends EventObserver {
|
|
|
|
|
connection.broadcastEvents(events);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void receiveRequests(ParticipantType source, Request[] requests) {
|
|
|
|
|
public void receiveRequests(Participant source, Request[] requests) {
|
|
|
|
|
ArrayList<Request> stateRelevant = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for(Request request: requests) {
|
|
|
|
|
switch(request.type) {
|
|
|
|
|
case MeleeAttackRequest, RangedAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest -> {
|
|
|
|
|
stateRelevant.add(request); // these need to be checked all together by the game instance itself
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
|
|
|
|
|
processRequest(source, request);
|
|
|
|
|
//if game is paused only PauseStop, Disconnect and Req are available
|
|
|
|
|
if(!pause.isPaused()){
|
|
|
|
|
processRequest(source, request);
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -51,58 +73,38 @@ public class Lobby extends EventObserver {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processRequest(ParticipantType source, Request request) {
|
|
|
|
|
private void processRequest(Participant source, Request request) {
|
|
|
|
|
//TODO: handle the rest of the requests
|
|
|
|
|
switch(request.type) {
|
|
|
|
|
case PauseStopRequest -> {
|
|
|
|
|
|
|
|
|
|
pause.pauseEnd();
|
|
|
|
|
connection.sendEvents(source, new EventBuilder(EventType.PauseStopEvent).buildGameStateEvent(), game.getGameStateEvent());
|
|
|
|
|
}
|
|
|
|
|
case PauseStartRequest -> {
|
|
|
|
|
|
|
|
|
|
pause.pauseGame();
|
|
|
|
|
connection.sendEvents(source, new EventBuilder(EventType.PauseStartEvent).buildGameStateEvent(), game.getGameStateEvent());
|
|
|
|
|
}
|
|
|
|
|
case EndRoundRequest -> {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
case DisconnectRequest -> {
|
|
|
|
|
|
|
|
|
|
connection.removePlayer(source);
|
|
|
|
|
connection.sendEvents(source, new EventBuilder(EventType.DisconnectEvent).buildGameStateEvent(), game.getGameStateEvent());
|
|
|
|
|
}
|
|
|
|
|
case Req -> {
|
|
|
|
|
|
|
|
|
|
connection.sendEvents(source, game.getGameStateEvent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void pause() {
|
|
|
|
|
public void endRound(){
|
|
|
|
|
ArrayList Entitys = new ArrayList<>();
|
|
|
|
|
for (EntityID id : game.state.getTurnOrder()) {
|
|
|
|
|
if(((Character) game.state.getEntities().findEntity(id)).hp.getValue() == 0){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void unpause(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handleDisconnects(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void DisconnectClient(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void checkCheating(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void SendGamestate(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handleConnects(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handleSpectators(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handlePlayers(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handleLogon(){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void handleLogoff(){
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int index = game.state.getTurnOrder().indexOf(game.state.getActiveCharacter());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void closeLobby(){
|
|
|
|
|