feat: handle Req request and remove handling of lobby events
This commit is contained in:
parent
a9c80cb19b
commit
c2d1c2cc98
@ -120,4 +120,12 @@ public class EntityManager {
|
||||
public Iterator<Entity> getEntities() {
|
||||
return entities.iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports all entities as an array.
|
||||
* @return An array containing every {@link Entity}
|
||||
*/
|
||||
public Entity[] export() {
|
||||
return (Entity[])entities.toArray();
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +88,15 @@ class GameLogic {
|
||||
.buildEntityEvent());
|
||||
//TODO: add infinity stone usage effect in GameLogic.executeRequest
|
||||
}
|
||||
case DisconnectRequest -> {
|
||||
result.add(new EventBuilder(EventType.DisconnectEvent)
|
||||
.buildGameEvent());
|
||||
case Req -> {
|
||||
result.add(new EventBuilder(EventType.GameStateEvent)
|
||||
.withEntities(state.entities.export())
|
||||
.withTurnOrder((EntityID[])state.turnOrder.toArray())
|
||||
.withMapSize(state.mapSize)
|
||||
.withActiveCharacter(state.activeCharacter)
|
||||
.withStoneCooldowns(state.stoneCooldown.export())
|
||||
.withWinCondition(state.won)
|
||||
.buildGameStateEvent());
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,11 +188,8 @@ class GameLogic {
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
case DisconnectRequest -> {
|
||||
//TODO: add check for DisconnectRequest in GameLogic.checkRequest
|
||||
|
||||
case Req -> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package uulm.teamname.marvelous.gamelibrary.gamelogic;
|
||||
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.Entity;
|
||||
import uulm.teamname.marvelous.gamelibrary.entities.StoneType;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -51,4 +52,17 @@ public class StoneCooldownManager {
|
||||
public void setCooldown(StoneType stone, int duration) {
|
||||
cooldowns.put(stone, Math.max(0, duration));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports the cooldowns as an array ordered according to the enum.
|
||||
* @return An array containing every cooldown
|
||||
*/
|
||||
public Integer[] export() {
|
||||
Integer[] data = new Integer[6];
|
||||
int i = 0;
|
||||
for (StoneType stone: StoneType.values()) {
|
||||
data[i++] = cooldowns.getOrDefault(stone, 0);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user