diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java index fa68046..33300ca 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/EntityManager.java @@ -120,4 +120,12 @@ public class EntityManager { public Iterator getEntities() { return entities.iterator(); } + + /** + * Exports all entities as an array. + * @return An array containing every {@link Entity} + */ + public Entity[] export() { + return (Entity[])entities.toArray(); + } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java index 21d303e..3e20323 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -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; } } diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java index c730685..cbfba1e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java @@ -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; + } }