feat: add basic backbone for lobby
This commit is contained in:
@ -2,41 +2,77 @@ package uulm.teamname.marvelous.server.Lobby;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.IntVector2;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.Event;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventBuilder;
|
||||
import uulm.teamname.marvelous.gamelibrary.events.EventType;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.EventObserver;
|
||||
import uulm.teamname.marvelous.gamelibrary.gamelogic.GameInstance;
|
||||
import uulm.teamname.marvelous.gamelibrary.requests.Request;
|
||||
import uulm.teamname.marvelous.server.LobbyManager.LobbyConnection;
|
||||
import uulm.teamname.marvelous.server.LobbyManager.MessageSource;
|
||||
|
||||
public class Lobby {
|
||||
import java.util.*;
|
||||
|
||||
String gameID;
|
||||
GameInstance gameInstance; // This is the main "wrapper" class for Gamestate, Event creation and so son
|
||||
public class Lobby extends EventObserver {
|
||||
public final String gameID;
|
||||
public final LobbyConnection connection;
|
||||
public final GameInstance game;
|
||||
|
||||
|
||||
|
||||
public Lobby(String gameID){
|
||||
//the LobbyManager can create a Lobby with a specific ID.
|
||||
public Lobby(String gameID, IntVector2 mapSize, LobbyConnection connection) {
|
||||
this.gameID = gameID;
|
||||
this.connection = connection;
|
||||
|
||||
game = new GameInstance(mapSize);
|
||||
game.addObserver(this);
|
||||
}
|
||||
|
||||
public void recieveEvents(Request[] requests){
|
||||
//Get Messages from the LobbyManager
|
||||
//possible requests: MeleeAttackRequest, RangeAttackRequest, MoveRequest, ExchangeInfinityStoneRequest, UseInfinityStoneRequest.
|
||||
@Override
|
||||
protected void handle(Event[] events) {
|
||||
connection.broadcastEvents(events);
|
||||
}
|
||||
|
||||
public void sendEvents(Event[] events){
|
||||
//Send Messages to the LobbyManager
|
||||
//Events spliced in:
|
||||
//Gamestate Events: Ack, Nack, Req, GamestateEvent, CustomEvent
|
||||
//Entity Events: DestroyEntityEvent, HealedEvent, TakenDamageEvent, SpawnEntityEvent
|
||||
//Character Events: MeleeAttackEvent, RangedAttackEvent, MoveEvent, UseInfinityStoneEvent, ExchangeInfinityStoneEvent
|
||||
//Game Events: TimeoutEvent, TimeoutWarningEvent, WinEvent, RoundSetupEvent, TurnEvent, TurnTimeoutEvent, DisconnectEvent.
|
||||
public void receiveRequests(MessageSource 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
|
||||
}
|
||||
case PauseStopRequest, PauseStartRequest, EndRoundRequest, DisconnectRequest, Req -> {
|
||||
processRequest(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())) {
|
||||
// requests don't apply, tell the client that they need to update their state
|
||||
connection.sendEvents(source, new EventBuilder(EventType.Nack).buildGameEvent(), game.getGameStateEvent());
|
||||
}
|
||||
}
|
||||
|
||||
public void processEvents(){
|
||||
//The largest Block to handle all possible Events
|
||||
//To defuse this Method you could use the smaller Methods below.
|
||||
private void processRequest(Request request) {
|
||||
//TODO: handle the rest of the requests
|
||||
switch(request.type) {
|
||||
case PauseStopRequest -> {
|
||||
|
||||
}
|
||||
case PauseStartRequest -> {
|
||||
|
||||
}
|
||||
case EndRoundRequest -> {
|
||||
|
||||
}
|
||||
case DisconnectRequest -> {
|
||||
|
||||
}
|
||||
case Req -> {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void pause(){
|
||||
public void pause() {
|
||||
|
||||
}
|
||||
public void unpause(){
|
||||
@ -44,18 +80,6 @@ public class Lobby {
|
||||
}
|
||||
public void handleDisconnects(){
|
||||
|
||||
}
|
||||
public void validateRequest(){
|
||||
|
||||
}
|
||||
public void applyRequestToGamestate(){
|
||||
|
||||
}
|
||||
public void generateEvents(){
|
||||
|
||||
}
|
||||
public void saidEvents(){
|
||||
|
||||
}
|
||||
public void DisconnectClient(){
|
||||
|
||||
|
@ -100,12 +100,12 @@ public class LobbyConnection {
|
||||
|
||||
// Methods to send events
|
||||
|
||||
public void sendEvents(Event[] events, MessageSource target) {
|
||||
public void sendEvents(MessageSource target, Event... events) {
|
||||
// TODO: implement
|
||||
MessageRelay.getInstance();
|
||||
}
|
||||
|
||||
public void broadcastEvents(Event[] events) {
|
||||
public void broadcastEvents(Event... events) {
|
||||
// TODO: implement
|
||||
MessageRelay.getInstance();
|
||||
}
|
||||
|
Reference in New Issue
Block a user