mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
Bot now only serves once when the distance is more than reach distance
This commit is contained in:
parent
9c0cb00628
commit
5851162a63
@ -58,58 +58,78 @@ public class ButlerBot extends Bot {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUserSay(final RoomChatMessage message) {
|
public void onUserSay(final RoomChatMessage message) {
|
||||||
if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE))
|
if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || this.getRoom() == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double distanceBetweenBotAndHabbo = this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation());
|
||||||
|
|
||||||
|
if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) {
|
||||||
|
|
||||||
if (this.getRoomUnit().getCurrentLocation().distance(message.getHabbo().getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance"))
|
|
||||||
if (message.getUnfilteredMessage() != null) {
|
if (message.getUnfilteredMessage() != null) {
|
||||||
for (Map.Entry<THashSet<String>, Integer> set : serveItems.entrySet()) {
|
for (Map.Entry<THashSet<String>, Integer> set : serveItems.entrySet()) {
|
||||||
for (String s : set.getKey()) {
|
for (String keyword : set.getKey()) {
|
||||||
if (message.getUnfilteredMessage().toLowerCase().contains(s)) {
|
|
||||||
|
// Check if the string contains a certain keyword using a regex.
|
||||||
|
// If keyword = tea, teapot wouldn't trigger it.
|
||||||
|
if (message.getUnfilteredMessage().toLowerCase().matches("\\b" + keyword + "\\b")) {
|
||||||
|
|
||||||
|
// Enable plugins to cancel this event
|
||||||
BotServerItemEvent serveEvent = new BotServerItemEvent(this, message.getHabbo(), set.getValue());
|
BotServerItemEvent serveEvent = new BotServerItemEvent(this, message.getHabbo(), set.getValue());
|
||||||
if (Emulator.getPluginManager().fireEvent(serveEvent).isCancelled()) {
|
if (Emulator.getPluginManager().fireEvent(serveEvent).isCancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start give handitem process
|
||||||
if (this.getRoomUnit().canWalk()) {
|
if (this.getRoomUnit().canWalk()) {
|
||||||
final String key = s;
|
final String key = keyword;
|
||||||
final Bot b = this;
|
final Bot bot = this;
|
||||||
b.lookAt(serveEvent.habbo);
|
|
||||||
|
|
||||||
final List<Runnable> tasks = new ArrayList();
|
// Step 1: Look at Habbo
|
||||||
|
bot.lookAt(serveEvent.habbo);
|
||||||
|
|
||||||
|
// Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo
|
||||||
|
final List<Runnable> tasks = new ArrayList<>();
|
||||||
|
tasks.add(() -> System.out.println("Serving drinks!"));
|
||||||
tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
|
tasks.add(new RoomUnitGiveHanditem(serveEvent.habbo.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
|
||||||
tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0));
|
tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), 0));
|
||||||
|
|
||||||
tasks.add(() -> {
|
tasks.add(() -> {
|
||||||
if(this.getRoom() != null) {
|
if(this.getRoom() != null) {
|
||||||
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", key).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
|
String botMessage = Emulator.getTexts()
|
||||||
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
|
.getValue("bots.butler.given")
|
||||||
b.talk(msg);
|
.replace("%key%", key)
|
||||||
|
.replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
|
||||||
|
|
||||||
|
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{ botMessage })) {
|
||||||
|
bot.talk(botMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
List<Runnable> failedReached = new ArrayList();
|
List<Runnable> failedReached = new ArrayList<>();
|
||||||
failedReached.add(() -> {
|
failedReached.add(() -> {
|
||||||
if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) {
|
if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.servedistance", 8)) {
|
||||||
for (Runnable t : tasks) {
|
System.out.println("Failed reached!");
|
||||||
t.run();
|
for (Runnable task : tasks) {
|
||||||
|
task.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Give bot the handitem that it's going to give the Habbo
|
||||||
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
|
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.habbo.getHabboInfo().getCurrentRoom(), serveEvent.itemId));
|
||||||
|
|
||||||
if (b.getRoomUnit().getCurrentLocation().distance(serveEvent.habbo.getRoomUnit().getCurrentLocation()) > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) {
|
if (distanceBetweenBotAndHabbo > 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)));
|
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 {
|
} else {
|
||||||
Emulator.getThreading().run(failedReached.get(0), 1000);
|
Emulator.getThreading().run(failedReached.get(0), 1000);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if(this.getRoom() != null) {
|
||||||
this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId);
|
this.getRoom().giveHandItem(serveEvent.habbo, serveEvent.itemId);
|
||||||
|
|
||||||
if(this.getRoom() != null) {
|
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
|
||||||
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", s).replace("%username%", serveEvent.habbo.getHabboInfo().getUsername());
|
|
||||||
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
|
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
|
||||||
this.talk(msg);
|
this.talk(msg);
|
||||||
}
|
}
|
||||||
@ -122,3 +142,4 @@ public class ButlerBot extends Bot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -42,10 +42,8 @@ public class RoomUnitWalkToRoomUnit implements Runnable {
|
|||||||
if (this.goalTile == null) {
|
if (this.goalTile == null) {
|
||||||
this.findNewLocation();
|
this.findNewLocation();
|
||||||
Emulator.getThreading().run(this, 500);
|
Emulator.getThreading().run(this, 500);
|
||||||
}
|
|
||||||
|
|
||||||
if (this.goalTile == null)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.walker.getGoal().equals(this.goalTile)) { // check that the action hasn't been cancelled by changing the goal
|
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) {
|
if (this.walker.getCurrentLocation().distance(this.goalTile) <= this.minDistance) {
|
||||||
|
Loading…
Reference in New Issue
Block a user