diff --git a/src/main/java/com/comandante/creeper/command/BackCommand.java b/src/main/java/com/comandante/creeper/command/BackCommand.java index aead2c1ddceb19e8932a44472366a35e17307f20..5429d5c26132b9ae2576ca6748a4bd5c3ab518f0 100644 --- a/src/main/java/com/comandante/creeper/command/BackCommand.java +++ b/src/main/java/com/comandante/creeper/command/BackCommand.java @@ -27,7 +27,7 @@ public class BackCommand extends Command { return; } Room returnRoom = player.getPreviousRoom(); - PlayerMovement playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), returnRoom.getRoomId(), "fleed to where they came from.", "up"); + PlayerMovement playerMovement = new PlayerMovement(player, currentRoom.getRoomId(), returnRoom.getRoomId(), "returned to where they came from.", "N/A"); player.movePlayer(playerMovement); }); } diff --git a/src/main/java/com/comandante/creeper/command/MovementCommand.java b/src/main/java/com/comandante/creeper/command/MovementCommand.java index 329460fc2d1be8ecde4aad26dbc09c17d2114885..b8c024cf44cfa9f253df5c11a790ce99e067b2be 100644 --- a/src/main/java/com/comandante/creeper/command/MovementCommand.java +++ b/src/main/java/com/comandante/creeper/command/MovementCommand.java @@ -44,7 +44,7 @@ public class MovementCommand extends Command { MovementCommand.this.write("You are dead and can not move."); return; } - if (player.isAlertedNpcPresentInCurrentRoom()) { + if (player.areAnyAlertedNpcsInCurrentRoom()) { MovementCommand.this.write("You are unable to progress, but can return to where you came from by typing \"back\"."); return; } diff --git a/src/main/java/com/comandante/creeper/managers/GameManager.java b/src/main/java/com/comandante/creeper/managers/GameManager.java index 87be794be33b11c3ba2861fc0026773438c9da23..13e1e41a6d4a2baf158392d8a9b0d02c809f9260 100644 --- a/src/main/java/com/comandante/creeper/managers/GameManager.java +++ b/src/main/java/com/comandante/creeper/managers/GameManager.java @@ -726,7 +726,7 @@ public class GameManager { sb.append(Color.GREEN + "F" + Color.RESET); } } - if (player.isAlertedNpcPresentInCurrentRoom()) { + if (player.areAnyAlertedNpcsInCurrentRoom()) { sb.append(" "); sb.append(Color.RED + "ALERT" + Color.RESET); } diff --git a/src/main/java/com/comandante/creeper/player/Player.java b/src/main/java/com/comandante/creeper/player/Player.java index 82c58fa05e91602f697dfb165f96eea15149c9f9..5c6e600be411b383154d25ddb919113b684a321d 100644 --- a/src/main/java/com/comandante/creeper/player/Player.java +++ b/src/main/java/com/comandante/creeper/player/Player.java @@ -368,10 +368,14 @@ public class Player extends CreeperEntity { } } - public boolean isAlertedNpcPresentInCurrentRoom() { + public boolean areAnyAlertedNpcsInCurrentRoom() { return currentRoom.getPresentNpcs().stream().filter(this::isActiveAlertNpcStatus).count() > 0; } + public boolean areInTheSameRoom(Npc npc) { + return currentRoom.getPresentNpcs().contains(npc); + } + public void setIsActiveAlertNpcStatus(Npc npc) { synchronized (interner.intern(playerId)) { alertedNpcs.add(npc); @@ -605,14 +609,13 @@ public class Player extends CreeperEntity { }) .collect(Collectors.toList()); - final Room originalRoom = currentRoom; aggresiveRoomNpcs.forEach(npc -> { gameManager.writeToPlayerCurrentRoom(getPlayerId(), getPlayerName() + " has alerted a " + npc.getColorName() + "\r\n"); gameManager.getChannelUtils().write(playerId, "You can return to your previous location by typing \"back\"" + "\r\n"); setIsActiveAlertNpcStatus(npc); scheduledExecutor.schedule(() -> { removeActiveAlertStatus(npc); - if (!getCurrentRoom().getRoomId().equals(originalRoom.getRoomId())) { + if (!areInTheSameRoom(npc)) { return; } if (!npc.getIsAlive().get()) {