1
Fork 0
mirror of https://github.com/Quackster/Havana.git synced 2025-07-02 20:57:47 +00:00

add door flag for not allowing pet to walk to the door

This commit is contained in:
Quackster 2023-01-22 10:32:43 +10:00
parent a39cef9507
commit 67b8686257
3 changed files with 11 additions and 8 deletions

View file

@ -51,7 +51,7 @@ public class BotCommand extends Command {
e.printStackTrace();
}
Position bound = room.getMapping().getRandomWalkableBound(bot);
Position bound = room.getMapping().getRandomWalkableBound(bot, false);
if (bound != null)
room.getEntityManager().enterRoom(bot, bound);
@ -59,7 +59,7 @@ public class BotCommand extends Command {
room.getTaskManager().scheduleTask("BotCommandTask", ()-> {
for (Bot bot : room.getEntityManager().getEntitiesByClass(Bot.class)) {
Position newBound = room.getMapping().getRandomWalkableBound(bot);
Position newBound = room.getMapping().getRandomWalkableBound(bot, false);
if (newBound != null) {
bot.getRoomUser().walkTo(newBound.getX(), newBound.getY());

View file

@ -593,10 +593,7 @@ public class RoomMapping {
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;
@ -605,7 +602,13 @@ public class RoomMapping {
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;

View file

@ -304,7 +304,7 @@ public class EntityTask implements Runnable {
}
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());