From cc4c5ba8cb82d39323ee4c8a55d1fb340467fa7b Mon Sep 17 00:00:00 2001 From: punchready Date: Thu, 3 Jun 2021 02:30:25 +0200 Subject: [PATCH] fix: include NPCs in RoundSetupEvent and TurnEvent for standard compatibility --- .../gamelibrary/gamelogic/GameLogic.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) 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 db398d4..d55ae8d 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -751,16 +751,25 @@ public class GameLogic { state.roundNumber++; state.turnNumber = 0; + result.add(new EventBuilder(EventType.RoundSetupEvent) + .withRoundCount(state.roundNumber) + .buildGameEvent()); + + ArrayList turns = new ArrayList<>(); + if(state.roundNumber >= 1 && state.roundNumber <= 6) { + turns.add(new EntityID(EntityType.NPC, NPCType.Goose.getID())); result.addAll(handleGoose(state)); } HashSet revived = new HashSet<>(); if(state.roundNumber == 7) { + turns.add(new EntityID(EntityType.NPC, NPCType.Stan.getID())); result.addAll(handleStan(state, revived)); } if(state.roundNumber == state.partyConfig.maxRounds + 1) { + turns.add(new EntityID(EntityType.NPC, NPCType.Thanos.getID())); result.addAll(spawnThanos(state)); } @@ -775,10 +784,10 @@ public class GameLogic { state.stoneCooldown.update(); - result.add(new EventBuilder(EventType.RoundSetupEvent) - .withRoundCount(state.roundNumber) - .withCharacterOrder(state.turnOrder.toArray(new EntityID[0])) - .buildGameEvent()); + turns.addAll(state.turnOrder); + + // RoundSetupEvent has to be sent first, but the contents of it are determined later... + ((GameEvent)result.get(0)).characterOrder = turns.toArray(new EntityID[0]); return result; } @@ -791,6 +800,13 @@ public class GameLogic { private static ArrayList handleGoose(GameState state) { ArrayList result = new ArrayList<>(); + EntityID goose = new EntityID(EntityType.NPC, NPCType.Goose.getID()); + + result.add(new EventBuilder(EventType.TurnEvent) + .withTurnCount(state.turnOrder.size()) + .withNextCharacter(goose) + .buildGameEvent()); + ArrayList inventory = new ArrayList<>(state.unvomitedStones); int picked = rand.nextInt(inventory.size()); StoneType stone = inventory.get(picked); @@ -808,7 +824,6 @@ public class GameLogic { } IntVector2 position = free.get(rand.nextInt(free.size())); - EntityID goose = new EntityID(EntityType.NPC, NPCType.Goose.getID()); result.add(new EventBuilder(EventType.SpawnEntityEvent) .withEntity(new NPC(goose, position, inventory)) .buildEntityEvent()); @@ -831,6 +846,13 @@ public class GameLogic { private static ArrayList handleStan(GameState state, HashSet revived) { ArrayList result = new ArrayList<>(); + EntityID stan = new EntityID(EntityType.NPC, NPCType.Stan.getID()); + + result.add(new EventBuilder(EventType.TurnEvent) + .withTurnCount(state.turnOrder.size()) + .withNextCharacter(stan) + .buildGameEvent()); + ArrayList characters = new ArrayList<>(); ArrayList targetOptions = new ArrayList<>(); @@ -855,7 +877,6 @@ public class GameLogic { } IntVector2 spawnPosition = spawnOptions.get(rand.nextInt(spawnOptions.size())); - EntityID stan = new EntityID(EntityType.NPC, NPCType.Stan.getID()); result.add(new EventBuilder(EventType.SpawnEntityEvent) .withEntity(new NPC(stan, spawnPosition)) .buildEntityEvent()); @@ -921,6 +942,11 @@ public class GameLogic { private static ArrayList handleThanos(GameState state, NPC thanos) { ArrayList result = new ArrayList<>(); + result.add(new EventBuilder(EventType.TurnEvent) + .withTurnCount(state.turnOrder.size()) + .withNextCharacter(thanos.id) + .buildGameEvent()); + if(thanos.inventory.getFreeSlots() > 0) { IntVector2 picked = null; @@ -1053,10 +1079,6 @@ public class GameLogic { .buildGameEvent()); thanos.mp.setValue(thanos.mp.getMax()); } - result.add(new EventBuilder(EventType.TurnEvent) - .withTurnCount(state.turnOrder.size()) - .withNextCharacter(state.activeCharacter) - .buildGameEvent()); result.addAll(handleThanos(state, thanos)); return result;