mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2025-01-18 23:46:28 +01:00
Make bots walk to nearest adjacent tile when giving a handitem
This commit is contained in:
parent
95b0884a8c
commit
82ff5c0a08
@ -42,18 +42,9 @@ public class InteractionPuzzleBox extends HabboItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rotation == null) {
|
if (rotation == null) {
|
||||||
Optional<RoomTile> nearestTile = Arrays.stream(
|
RoomTile nearestTile = client.getHabbo().getRoomUnit().getClosestAdjacentTile(this.getX(), this.getY(), false);
|
||||||
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())));
|
|
||||||
|
|
||||||
nearestTile.ifPresent(roomTile -> client.getHabbo().getRoomUnit().setGoalLocation(roomTile));
|
if (nearestTile != null) client.getHabbo().getRoomUnit().setGoalLocation(nearestTile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,10 @@ package com.eu.habbo.habbohotel.rooms;
|
|||||||
import com.eu.habbo.Emulator;
|
import com.eu.habbo.Emulator;
|
||||||
import com.eu.habbo.habbohotel.bots.Bot;
|
import com.eu.habbo.habbohotel.bots.Bot;
|
||||||
import com.eu.habbo.habbohotel.items.Item;
|
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.Pet;
|
||||||
import com.eu.habbo.habbohotel.pets.RideablePet;
|
import com.eu.habbo.habbohotel.pets.RideablePet;
|
||||||
import com.eu.habbo.habbohotel.users.DanceType;
|
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.map.hash.THashMap;
|
||||||
import gnu.trove.set.hash.THashSet;
|
import gnu.trove.set.hash.THashSet;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class RoomUnit {
|
public class RoomUnit {
|
||||||
@ -743,4 +744,28 @@ public class RoomUnit {
|
|||||||
|
|
||||||
return topItem == null || (!(topItem instanceof InteractionWater) && !(topItem instanceof InteractionWaterItem));
|
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<Integer> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,23 +74,11 @@ public class RoomUnitWalkToRoomUnit implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void findNewLocation() {
|
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)
|
if (this.goalTile == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.room.tileWalkable(this.goalTile)) {
|
|
||||||
List<RoomTile> 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);
|
this.walker.setGoalLocation(this.goalTile);
|
||||||
|
|
||||||
if (this.walker.getPath().isEmpty() && this.failedReached != null) {
|
if (this.walker.getPath().isEmpty() && this.failedReached != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user