From 766a24c1551a47453befe01d5953ec3c113a70d4 Mon Sep 17 00:00:00 2001 From: Beny Date: Wed, 15 May 2019 17:36:41 +0100 Subject: [PATCH] Added hotel.bot.butler.reachdistance config to ButlerBot. This will allow the bot to give an item without walking next to the player. --- .../eu/habbo/habbohotel/bots/ButlerBot.java | 12 +++++++++-- .../runnables/RoomUnitWalkToRoomUnit.java | 20 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java index d3cf80b9..a3da7344 100644 --- a/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java +++ b/src/main/java/com/eu/habbo/habbohotel/bots/ButlerBot.java @@ -99,20 +99,28 @@ public class ButlerBot extends Bot b.talk(Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername())); } }); + List failedReached = new ArrayList(); failedReached.add(new Runnable() { public void run() { - if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance")) { + if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) { for (Runnable t : tasks) { t.run(); } } } }); + Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId)); - Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), tasks, failedReached)); + + if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) { + Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3))); + } + else { + Emulator.getThreading().run(failedReached.get(0), 1000); + } } else { 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 69acc945..75f4c74e 100644 --- a/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java +++ b/src/main/java/com/eu/habbo/threading/runnables/RoomUnitWalkToRoomUnit.java @@ -11,6 +11,7 @@ import java.util.List; public class RoomUnitWalkToRoomUnit implements Runnable { + private final int minDistance; private RoomUnit walker; private RoomUnit target; private Room room; @@ -26,6 +27,17 @@ public class RoomUnitWalkToRoomUnit implements Runnable this.room = room; this.targetReached = targetReached; this.failedReached = failedReached; + this.minDistance = 1; + } + + public RoomUnitWalkToRoomUnit(RoomUnit walker, RoomUnit target, Room room, List targetReached, List failedReached, int minDistance) + { + this.walker = walker; + this.target = target; + this.room = room; + this.targetReached = targetReached; + this.failedReached = failedReached; + this.minDistance = minDistance; } @Override @@ -36,10 +48,14 @@ public class RoomUnitWalkToRoomUnit implements Runnable this.findNewLocation(); Emulator.getThreading().run(this, 500); } - else 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. + + 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.getCurrentLocation().equals(this.goalTile)) + if(this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) { for(Runnable r : this.targetReached) {