Added hotel.bot.butler.reachdistance config to ButlerBot. This will allow the bot to give an item without walking next to the player.

This commit is contained in:
Beny 2019-05-15 17:36:41 +01:00
parent 23ae60119b
commit 766a24c155
2 changed files with 28 additions and 4 deletions

View File

@ -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<Runnable> 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
{

View File

@ -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<Runnable> targetReached, List<Runnable> 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)
{