diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java index ca1e4d6e..daff0b5d 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/InteractionPuzzleBox.java @@ -42,18 +42,9 @@ public class InteractionPuzzleBox extends HabboItem { } if (rotation == null) { - Optional nearestTile = Arrays.stream( - new RoomTile[]{ - room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.SOUTH.getValue()), - room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.NORTH.getValue()), - room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.EAST.getValue()), - room.getLayout().getTileInFront(room.getLayout().getTile(this.getX(), this.getY()), RoomUserRotation.WEST.getValue()) - } - ) - .filter(t -> t != null && t.isWalkable() && !room.hasHabbosAt(t.x, t.y)) - .min(Comparator.comparingDouble(a -> a.distance(client.getHabbo().getRoomUnit().getCurrentLocation()))); + RoomTile nearestTile = client.getHabbo().getRoomUnit().getClosestAdjacentTile(this.getX(), this.getY(), false); - nearestTile.ifPresent(roomTile -> client.getHabbo().getRoomUnit().setGoalLocation(roomTile)); + if (nearestTile != null) client.getHabbo().getRoomUnit().setGoalLocation(nearestTile); return; } diff --git a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java index d4c71610..348fddad 100644 --- a/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java +++ b/src/main/java/com/eu/habbo/habbohotel/rooms/RoomUnit.java @@ -3,7 +3,10 @@ package com.eu.habbo.habbohotel.rooms; import com.eu.habbo.Emulator; import com.eu.habbo.habbohotel.bots.Bot; import com.eu.habbo.habbohotel.items.Item; -import com.eu.habbo.habbohotel.items.interactions.*; +import com.eu.habbo.habbohotel.items.interactions.InteractionGuildGate; +import com.eu.habbo.habbohotel.items.interactions.InteractionHabboClubGate; +import com.eu.habbo.habbohotel.items.interactions.InteractionWater; +import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem; import com.eu.habbo.habbohotel.pets.Pet; import com.eu.habbo.habbohotel.pets.RideablePet; import com.eu.habbo.habbohotel.users.DanceType; @@ -22,9 +25,7 @@ import gnu.trove.map.TMap; import gnu.trove.map.hash.THashMap; import gnu.trove.set.hash.THashSet; -import java.util.Deque; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; public class RoomUnit { @@ -743,4 +744,28 @@ public class RoomUnit { return topItem == null || (!(topItem instanceof InteractionWater) && !(topItem instanceof InteractionWaterItem)); } + + public RoomTile getClosestAdjacentTile(short x, short y, boolean diagonal) { + RoomTile baseTile = room.getLayout().getTile(x, y); + + if (baseTile == null) return null; + + List rotations = new ArrayList<>(); + rotations.add(RoomUserRotation.SOUTH.getValue()); + rotations.add(RoomUserRotation.NORTH.getValue()); + rotations.add(RoomUserRotation.EAST.getValue()); + rotations.add(RoomUserRotation.WEST.getValue()); + + if (diagonal) { + rotations.add(RoomUserRotation.NORTH_EAST.getValue()); + rotations.add(RoomUserRotation.NORTH_WEST.getValue()); + rotations.add(RoomUserRotation.SOUTH_EAST.getValue()); + rotations.add(RoomUserRotation.SOUTH_WEST.getValue()); + } + + return rotations.stream() + .map(rotation -> room.getLayout().getTileInFront(baseTile, rotation)) + .filter(t -> t != null && t.isWalkable() && !room.hasHabbosAt(t.x, t.y)) + .min(Comparator.comparingDouble(a -> a.distance(this.getCurrentLocation()))).orElse(null); + } } diff --git a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java index 1eeac72d..e8ef0c71 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -74,23 +74,11 @@ public class RoomUnitWalkToRoomUnit implements Runnable { } private void findNewLocation() { - this.goalTile = this.room.getLayout().getTileInFront(this.target.getCurrentLocation(), this.target.getBodyRotation().getValue()); + this.goalTile = this.walker.getClosestAdjacentTile(this.target.getCurrentLocation().x, this.target.getCurrentLocation().y, true); if (this.goalTile == null) return; - if (!this.room.tileWalkable(this.goalTile)) { - List tiles = this.room.getLayout().getTilesAround(this.target.getCurrentLocation()); - - for (RoomTile t : tiles) { - if (this.room.tileWalkable(t)) { - this.goalTile = t; - - break; - } - } - } - this.walker.setGoalLocation(this.goalTile); if (this.walker.getPath().isEmpty() && this.failedReached != null) {