From 3522cee9a41d72e60927f87a00d9114024564272 Mon Sep 17 00:00:00 2001 From: punchready Date: Thu, 27 May 2021 17:26:46 +0200 Subject: [PATCH] feat: add stone cooldown handling --- .../marvelous/gamelibrary/gamelogic/GameInstance.java | 1 + .../marvelous/gamelibrary/gamelogic/GameLogic.java | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java index 5c06777..02b1736 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameInstance.java @@ -101,6 +101,7 @@ public class GameInstance { * @param events The events to emit */ private void emit(Event... events) { + manager.applyEvents(events); emitter.update(events); } } 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 e8aee84..b1f8404 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -288,6 +288,10 @@ class GameLogic { requireAP(origin, 1); requireInfinityStone(origin, data.stoneType); + if(state.stoneCooldown.onCooldown(data.stoneType)) { + throw new InvalidRequestException(); + } + switch(((CharacterRequest) request).stoneType) { case SpaceStone -> { verifyCoordinates(state, data.targetField); @@ -507,6 +511,9 @@ class GameLogic { case MoveEvent -> { (state.entities.findEntity(((CharacterEvent)event).originEntity)).setPosition(((CharacterEvent)event).targetField); } + case UseInfinityStoneEvent -> { + state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType, 10); //TODO: use stone cooldown from config + } case ExchangeInfinityStoneEvent -> { ((Character)state.entities.findEntity(((CharacterEvent)event).originEntity)).inventory.removeStone(((CharacterEvent)event).stoneType); ((Character)state.entities.findEntity(((CharacterEvent)event).targetEntity)).inventory.addStone(((CharacterEvent)event).stoneType); @@ -598,6 +605,8 @@ class GameLogic { } } + state.stoneCooldown.update(); + result.add(new EventBuilder(EventType.RoundSetupEvent) .withRoundCount(state.roundNumber) .withCharacterOrder(state.turnOrder.toArray(new EntityID[0]))