From 184c839c3a630fb9dbf92e2aae06a456fdb2b860 Mon Sep 17 00:00:00 2001 From: punchready Date: Mon, 31 May 2021 18:30:26 +0200 Subject: [PATCH] fix: utilize config in GameLogic --- .../gamelibrary/gamelogic/GameLogic.java | 7 ++--- .../gamelibrary/gamelogic/GameState.java | 3 ++- .../gamelogic/StoneCooldownManager.java | 27 +++++++++++++++---- 3 files changed, 28 insertions(+), 9 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 e6766b0..1cfb093 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -116,7 +116,6 @@ class GameLogic { } case RealityStone -> { if(data.originEntity == data.targetEntity) { // => place stone - //TODO: use config values result.add(new EventBuilder(EventType.SpawnEntityEvent) .withTargetField(data.targetField) .withEntity(new Rock(new EntityID(EntityType.Rocks, state.entities.findFreeRockSlot()), data.targetField, 100)) @@ -303,7 +302,9 @@ class GameLogic { if(data.originField == data.targetField) { throw new InvalidRequestException(); } - //TODO: mind stone damage check (config) ??????? + if(data.value != state.partyConfig.mindStoneDMG) { + throw new InvalidRequestException(); + } } case RealityStone -> { if(data.originEntity == data.targetEntity) { // => place stone @@ -527,7 +528,7 @@ class GameLogic { target.setPosition(((CharacterEvent)event).targetField); } case UseInfinityStoneEvent -> { - state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType, 10); //TODO: use stone cooldown from config + state.stoneCooldown.setCooldown(((CharacterEvent)event).stoneType); } case ExchangeInfinityStoneEvent -> { ((Character)state.entities.findEntity(((CharacterEvent)event).originEntity)).inventory.removeStone(((CharacterEvent)event).stoneType); diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java index a589417..8de64ba 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameState.java @@ -41,7 +41,7 @@ class GameState { public boolean won = false; /** The global cooldown of every infinity stone */ - public final StoneCooldownManager stoneCooldown = new StoneCooldownManager(); + public final StoneCooldownManager stoneCooldown; /** The data for every win condition for each player */ public final WinConditionManager winConditions = new WinConditionManager(); @@ -54,6 +54,7 @@ class GameState { this.partyConfig = partyConfig; this.characterConfig = characterConfig; this.scenarioConfig = scenarioConfig; + stoneCooldown = new StoneCooldownManager(partyConfig); } /** 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 cbfba1e..2b79805 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/StoneCooldownManager.java @@ -1,7 +1,7 @@ package uulm.teamname.marvelous.gamelibrary.gamelogic; -import uulm.teamname.marvelous.gamelibrary.entities.Entity; import uulm.teamname.marvelous.gamelibrary.entities.StoneType; +import uulm.teamname.marvelous.gamelibrary.json.config.PartyConfig; import java.util.HashMap; @@ -10,6 +10,22 @@ public class StoneCooldownManager { /** The cooldown round numbers for every stone */ private final HashMap cooldowns = new HashMap<>(); + /** The max cooldown round numbers for every stone */ + private final HashMap maxCooldowns = new HashMap<>(); + + /** + * Constructs a new {@link StoneCooldownManager} with the given config. + */ + public StoneCooldownManager(PartyConfig partyConfig) { + //thanks + maxCooldowns.put(StoneType.SpaceStone, partyConfig.spaceStoneCD); + maxCooldowns.put(StoneType.MindStone, partyConfig.mindStoneCD); + maxCooldowns.put(StoneType.RealityStone, partyConfig.realityStoneCD); + maxCooldowns.put(StoneType.PowerStone, partyConfig.powerStoneCD); + maxCooldowns.put(StoneType.TimeStone, partyConfig.timeStoneCD); + maxCooldowns.put(StoneType.SoulStone, partyConfig.soulStoneCD); + } + /** * Takes over all the cooldowns from a different {@link StoneCooldownManager}. * @param other The cooldown manager to take the data from @@ -17,6 +33,8 @@ public class StoneCooldownManager { public void cloneFrom(StoneCooldownManager other) { cooldowns.clear(); cooldowns.putAll(other.cooldowns); + maxCooldowns.clear(); + maxCooldowns.putAll(other.maxCooldowns); } /** @@ -46,11 +64,10 @@ public class StoneCooldownManager { /** * Marks a stone as on cooldown. - * @param stone The {@link StoneType} to check for - * @param duration The number of rounds the stone should be on cooldown + * @param stone The {@link StoneType} to mark */ - public void setCooldown(StoneType stone, int duration) { - cooldowns.put(stone, Math.max(0, duration)); + public void setCooldown(StoneType stone) { + cooldowns.put(stone, Math.max(0, maxCooldowns.get(stone))); } /**