Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
Don't allow door coordinate for pet path
Browse files Browse the repository at this point in the history
  • Loading branch information
Quackster committed Jan 22, 2023
1 parent d896b9e commit e1b50de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit e1b50de

Please sign in to comment.