From 4ecba6723d07756c9b8bd0769c1eadf7f352da01 Mon Sep 17 00:00:00 2001 From: Alejandro <25-alejandro@users.noreply.git.krews.org> Date: Wed, 5 Feb 2020 19:52:29 +0200 Subject: [PATCH] Fix giving handitems with bots --- .../effects/WiredEffectBotGiveHandItem.java | 7 +++++- .../runnables/RoomUnitWalkToRoomUnit.java | 24 +++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java index d32e932a..918f12fb 100644 --- a/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java +++ b/src/main/java/com/eu/habbo/habbohotel/items/interactions/wired/effects/WiredEffectBotGiveHandItem.java @@ -96,8 +96,13 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect { List tasks = new ArrayList<>(); tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId)); tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0)); + Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, null)); + + List failedReach = new ArrayList<>(); + failedReach.add(() -> tasks.forEach(Runnable::run)); + + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach)); } return true; 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 e8ef0c71..296490e7 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -47,9 +47,7 @@ public class RoomUnitWalkToRoomUnit implements Runnable { if (this.goalTile == null) return; - if (this.walker.getGoal().equals(this.goalTile)) //Check if the goal is still the same. Chances are something is running the same task. If so we dump this task. - { - //Check if arrived. + if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for (Runnable r : this.targetReached) { Emulator.getThreading().run(r); @@ -57,17 +55,6 @@ public class RoomUnitWalkToRoomUnit implements Runnable { WiredHandler.handle(WiredTriggerType.BOT_REACHED_AVTR, this.target, this.room, new Object[]{this.walker}); } } else { - List tiles = this.room.getLayout().getTilesAround(this.target.getCurrentLocation()); - - for (RoomTile t : tiles) { - if (t.equals(this.goalTile)) { - Emulator.getThreading().run(this, 500); - return; - } - } - - this.findNewLocation(); - Emulator.getThreading().run(this, 500); } } @@ -76,8 +63,15 @@ public class RoomUnitWalkToRoomUnit implements Runnable { private void findNewLocation() { this.goalTile = this.walker.getClosestAdjacentTile(this.target.getCurrentLocation().x, this.target.getCurrentLocation().y, true); - if (this.goalTile == null) + if (this.goalTile == null) { + if (this.failedReached != null) { + for (Runnable r : this.failedReached) { + Emulator.getThreading().run(r); + } + } + return; + } this.walker.setGoalLocation(this.goalTile);