From e1b50dec3f4f51ada2d3b6859b1cfd6807e29eac Mon Sep 17 00:00:00 2001 From: Quackster Date: Sun, 22 Jan 2023 10:31:34 +1000 Subject: [PATCH] Don't allow door coordinate for pet path --- .../kepler/game/room/mapping/RoomMapping.java | 14 +++++++++----- .../alexdev/kepler/game/room/tasks/EntityTask.java | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/mapping/RoomMapping.java b/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/mapping/RoomMapping.java index 61c3f201..f1f562b0 100644 --- a/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/mapping/RoomMapping.java +++ b/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/mapping/RoomMapping.java @@ -1,5 +1,6 @@ package org.alexdev.kepler.game.room.mapping; +import org.alexdev.kepler.game.entity.EntityType; import org.alexdev.kepler.game.player.Player; import org.alexdev.kepler.game.entity.Entity; import org.alexdev.kepler.game.item.Item; @@ -489,10 +490,7 @@ public RoomTile getTile(int x, int y) { return this.roomMap[x][y]; } - public Position getRandomWalkableBound(Entity entity) { - Position position = null; - - boolean isWalkable = false; + public Position getRandomWalkableBound(Entity entity, boolean allowDoorBound) { int attempts = 0; int maxAttempts = 10; @@ -501,7 +499,13 @@ public Position getRandomWalkableBound(Entity entity) { int randomX = this.room.getModel().getRandomBound(0); int randomY = this.room.getModel().getRandomBound(1); - position = new Position(randomX, randomY); + + var position = new Position(randomX, randomY); + + if (!allowDoorBound) { + if (position.equals(this.room.getModel().getDoorLocation())) + continue; + } if (RoomTile.isValidTile(this.room, entity, position)) { return position; diff --git a/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/tasks/EntityTask.java b/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/tasks/EntityTask.java index 4fd2a50a..0cd89657 100644 --- a/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/tasks/EntityTask.java +++ b/Kepler-Server/src/main/java/org/alexdev/kepler/game/room/tasks/EntityTask.java @@ -296,7 +296,7 @@ private void processPet(Pet pet) { } - Position availableTile = this.room.getMapping().getRandomWalkableBound(pet); + Position availableTile = this.room.getMapping().getRandomWalkableBound(pet, false); if (availableTile != null) { pet.getRoomUser().walkTo(availableTile.getX(), availableTile.getY());