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 @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false; return false;
} }
for (Bot bot : bots) {
bot.setFigure(this.botLook); Bot bot = bots.get(0);
} bot.setFigure(this.botLook);
return true; return true;
} }

View File

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

View File

@ -88,24 +88,21 @@ public class WiredEffectBotGiveHandItem extends InteractionWiredEffect {
@Override @Override
public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) { public boolean execute(RoomUnit roomUnit, Room room, Object[] stuff) {
Habbo habbo = room.getHabbo(roomUnit); Habbo habbo = room.getHabbo(roomUnit);
List<Bot> bots = room.getBots(this.botName);
if (habbo != null) { if (habbo != null && bots.size() == 1) {
List<Bot> bots = room.getBots(this.botName); Bot bot = bots.get(0);
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));
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<>(); Emulator.getThreading().run(new RoomUnitGiveHanditem(bot.getRoomUnit(), room, this.itemId));
failedReach.add(() -> tasks.forEach(Runnable::run));
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; 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.pixels"), habbo.getHabboInfo().getPixels() + "")
.replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + ""); .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
} }
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false; return false;
} }
for (Bot bot : bots) {
if (this.mode == 1) Bot bot = bots.get(0);
bot.shout(message);
else if (this.mode == 1) {
bot.talk(message); bot.shout(message);
} else {
bot.talk(message);
} }
return true; 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")) + ""); .replace(Emulator.getTexts().getValue("wired.variable.points"), habbo.getHabboInfo().getCurrencyAmount(Emulator.getConfig().getInt("seasonal.primary.type")) + "");
List<Bot> bots = room.getBots(this.botName); List<Bot> bots = room.getBots(this.botName);
if (bots.size() > 1) {
if (bots.size() != 1) {
return false; return false;
} }
for (Bot bot : bots) {
if (this.mode == 1) { Bot bot = bots.get(0);
bot.whisper(m, habbo);
} else { if (this.mode == 1) {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m); bot.whisper(m, habbo);
} } else {
bot.talk(habbo.getHabboInfo().getUsername() + ": " + m);
} }
return true; return true;
} }
return false; return false;
} }

View File

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