refactor: utilize NPCType

This commit is contained in:
punchready 2021-06-01 19:33:48 +02:00
parent e88476eb10
commit 71fc0893a8
3 changed files with 18 additions and 8 deletions

View File

@ -46,7 +46,7 @@ public class Character extends Entity {
super(id, position); super(id, position);
solid = false; solid = false;
opaque = true; 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 solid = true; //characters cannot walk into thanos
} }
this.name = name; this.name = name;

View File

@ -2,7 +2,17 @@ package uulm.teamname.marvelous.gamelibrary.entities;
/** Specifies the type of an {@link NPC}. */ /** Specifies the type of an {@link NPC}. */
public enum NPCType { public enum NPCType {
Goose, Goose(0),
Stan, Stan(1),
Thanos Thanos(2);
private final int id;
NPCType(int id) {
this.id = id;
}
public int getID() {
return id;
}
} }

View File

@ -785,7 +785,7 @@ class GameLogic {
} }
IntVector2 position = free.get(rand.nextInt(free.size())); 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) result.add(new EventBuilder(EventType.SpawnEntityEvent)
.withEntity(new NPC(goose, position, inventory)) .withEntity(new NPC(goose, position, inventory))
.buildEntityEvent()); .buildEntityEvent());
@ -832,7 +832,7 @@ class GameLogic {
} }
IntVector2 spawnPosition = spawnOptions.get(rand.nextInt(spawnOptions.size())); 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) result.add(new EventBuilder(EventType.SpawnEntityEvent)
.withEntity(new NPC(stan, spawnPosition)) .withEntity(new NPC(stan, spawnPosition))
.buildEntityEvent()); .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) result.add(new EventBuilder(EventType.SpawnEntityEvent)
.withEntity(new NPC(thanos, position, maxMP)) .withEntity(new NPC(thanos, position, maxMP))
.buildEntityEvent()); .buildEntityEvent());
@ -1010,7 +1010,7 @@ class GameLogic {
state.turnNumber++; 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); NPC thanos = (NPC)state.entities.findEntity(state.activeCharacter);
if(state.roundNumber > state.partyConfig.maxRounds + 1) { if(state.roundNumber > state.partyConfig.maxRounds + 1) {