Refactored bot wired.

This commit is contained in:
necmi 2020-07-10 21:18:45 -04:00 committed by Harmonic
parent a7e70d2061
commit 4c27917273
7 changed files with 72 additions and 74 deletions

View File

@ -68,12 +68,13 @@ public class WiredEffectBotClothes extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false;
}
for (Bot bot : bots) {
bot.setFigure(this.botLook);
}
Bot bot = bots.get(0);
bot.setFigure(this.botLook);
return true;
}

View File

@ -86,16 +86,15 @@ public class WiredEffectBotFollowHabbo extends InteractionWiredEffect {
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit);
if (habbo != null) {
List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
return false;
}
for (Bot bot : bots) {
if (this.mode == 1)
bot.startFollowingHabbo(habbo);
else
bot.stopFollowingHabbo();
List<Bot> bots = room.getBots(this.botName);
if (habbo != null && bots.size() == 1) {
Bot bot = bots.get(0);
if (this.mode == 1) {
bot.startFollowingHabbo(habbo);
} else {
bot.stopFollowingHabbo();
}
return true;

View File

@ -88,24 +88,21 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName);
if (habbo != null) {
List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
return false;
}
for (Bot bot : bots) {
List<Runnable> tasks = new ArrayList<>();
tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId));
tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0));
if (habbo != null && bots.size() == 1) {
Bot bot = bots.get(0);
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
List<Runnable> tasks = new ArrayList<>();
tasks.add(new RoomUnitGiveHanditem(habbo.getRoomUnit(), room, this.itemId));
tasks.add(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, 0));
List<Runnable> failedReach = new ArrayList<>();
failedReach.add(() -> tasks.forEach(Runnable::run));
Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach));
}
List<Runnable> failedReach = new ArrayList<>();
failedReach.add(() -> tasks.forEach(Runnable::run));
Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(bot.getRoomUnit(), habbo.getRoomUnit(), room, tasks, failedReach));
return true;
}

View File

@ -83,16 +83,21 @@ public class WiredEffectBotTalk extends InteractionWiredEffect {
.replace(Emulator.getTexts().getValue("wired.variable.pixels"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
}
List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false;
}
for (Bot bot : bots) {
if (this.mode == 1)
bot.shout(message);
else
bot.talk(message);
Bot bot = bots.get(0);
if (this.mode == 1) {
bot.shout(message);
} else {
bot.talk(message);
}
return true;
}

View File

@ -103,19 +103,22 @@ public class WiredEffectBotTalkToHabbo extends InteractionWiredEffect {
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false;
}
for (Bot bot : bots) {
if (this.mode == 1) {
bot.whisper(m, habbo);
} else {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
}
Bot bot = bots.get(0);
if (this.mode == 1) {
bot.whisper(m, habbo);
} else {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
}
return true;
}
return false;
}

View File

@ -139,23 +139,22 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
List<Bot> bots = room.getBots(this.botName);
if (bots.isEmpty())
return false;
if (bots.size() > 1) {
if (bots.size() != 1) {
return false;
}
for (Bot bot : bots) {
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
int j = 1;
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
return true;
} else {
j++;
}
Bot bot = bots.get(0);
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
int j = 1;
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getX(), item.getY()));
return true;
} else {
j++;
}
}
}

View File

@ -88,14 +88,13 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
@Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
if (this.items.isEmpty())
return false;
List<Bot> bots = room.getBots(this.botName);
if (bots.isEmpty())
if (this.items.isEmpty() || bots.size() != 1) {
return false;
}
Bot bot = bots.get(0);
THashSet<HabboItem> items = new THashSet<>();
for (HabboItem item : this.items) {
@ -108,20 +107,15 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
}
if (this.items.size() > 0) {
if (bots.size() > 1) {
return false;
}
for (Bot bot : bots) {
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
int j = 1;
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
break;
} else {
j++;
}
int i = Emulator.getRandom().nextInt(this.items.size()) + 1;
int j = 1;
for (HabboItem item : this.items) {
if (item.getRoomId() != 0 && item.getRoomId() == bot.getRoom().getId()) {
if (i == j) {
bot.getRoomUnit().setGoalLocation(room.getLayout().getTile(item.getX(), item.getY()));
break;
} else {
j++;
}
}
}