From 71fc0893a87c1c2a01051799025efd3c751cc3e1 Mon Sep 17 00:00:00 2001 From: punchready Date: Tue, 1 Jun 2021 19:33:48 +0200 Subject: [PATCH] refactor: utilize NPCType --- .../gamelibrary/entities/Character.java | 2 +- .../marvelous/gamelibrary/entities/NPCType.java | 16 +++++++++++++--- .../gamelibrary/gamelogic/GameLogic.java | 8 ++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java index 5d67196..aed8b37 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java @@ -46,7 +46,7 @@ public class Character extends Entity { super(id, position); solid = false; opaque = true; - if(id.type == EntityType.NPC && id.id == 2) { + if(id.type == EntityType.NPC && id.id == NPCType.Thanos.getID()) { solid = true; //characters cannot walk into thanos } this.name = name; diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java index b4b339e..5c60f3e 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/NPCType.java @@ -2,7 +2,17 @@ package uulm.teamname.marvelous.gamelibrary.entities; /** Specifies the type of an {@link NPC}. */ public enum NPCType { - Goose, - Stan, - Thanos + Goose(0), + Stan(1), + Thanos(2); + + private final int id; + + NPCType(int id) { + this.id = id; + } + + public int getID() { + return id; + } } 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 6f7690f..40e1ad3 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/gamelogic/GameLogic.java @@ -785,7 +785,7 @@ class GameLogic { } IntVector2 position = free.get(rand.nextInt(free.size())); - EntityID goose = new EntityID(EntityType.NPC, 0); + EntityID goose = new EntityID(EntityType.NPC, NPCType.Goose.getID()); result.add(new EventBuilder(EventType.SpawnEntityEvent) .withEntity(new NPC(goose, position, inventory)) .buildEntityEvent()); @@ -832,7 +832,7 @@ class GameLogic { } IntVector2 spawnPosition = spawnOptions.get(rand.nextInt(spawnOptions.size())); - EntityID stan = new EntityID(EntityType.NPC, 1); + EntityID stan = new EntityID(EntityType.NPC, NPCType.Stan.getID()); result.add(new EventBuilder(EventType.SpawnEntityEvent) .withEntity(new NPC(stan, spawnPosition)) .buildEntityEvent()); @@ -880,7 +880,7 @@ class GameLogic { } } - EntityID thanos = new EntityID(EntityType.NPC, 2); + EntityID thanos = new EntityID(EntityType.NPC, NPCType.Thanos.getID()); result.add(new EventBuilder(EventType.SpawnEntityEvent) .withEntity(new NPC(thanos, position, maxMP)) .buildEntityEvent()); @@ -1010,7 +1010,7 @@ class GameLogic { state.turnNumber++; - if(state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == 2) { + if(state.activeCharacter.type == EntityType.NPC && state.activeCharacter.id == NPCType.Thanos.getID()) { NPC thanos = (NPC)state.entities.findEntity(state.activeCharacter); if(state.roundNumber > state.partyConfig.maxRounds + 1) {