Bot rework

This commit is contained in:
Stankman 2023-08-04 14:11:04 -05:00
parent 71062dc2fc
commit e99af600c3
28 changed files with 590 additions and 693 deletions

View File

@ -1,17 +1,18 @@
package com.eu.habbo.habbohotel.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.database.DatabaseConstants;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUserAction;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot;
import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.units.type.Avatar;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboGender;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.rooms.users.*;
import com.eu.habbo.plugin.events.bots.BotChatEvent;
import com.eu.habbo.plugin.events.bots.BotShoutEvent;
@ -28,86 +29,53 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Slf4j
public class Bot extends Unit implements Runnable {
@Getter
@Setter
private transient int id;
@Getter
private String name;
@Getter
private String motto;
@Getter
private String figure;
@Getter
private HabboGender gender;
@Getter
private int ownerId;
@Getter
private String ownerName;
@Getter
@Setter
private Room room;
@Getter
private boolean chatAuto;
@Getter
private boolean chatRandom;
@Getter
private short chatDelay;
@Getter
@Setter
private int chatTimeOut;
private int chatTimestamp;
@Getter
@Setter
private short lastChatIndex;
@Getter
private final int bubbleId;
@Getter
private final String type;
@Getter
private int effect;
private transient boolean canWalk = true;
private boolean needsUpdate;
@Getter
@Setter
private transient int followingHabboId;
@Getter
@Setter
@Accessors(chain = true)
private RoomBot roomUnit;
public class Bot extends Avatar implements Runnable {
private transient int id;
private String name;
private String motto;
private String figure;
private HabboGender gender;
private int ownerId;
private String ownerName;
private HabboInfo ownerInfo;
private boolean chatAuto;
private boolean chatRandom;
private short chatDelay;
private int chatTimeOut;
private int chatTimestamp;
private short lastChatIndex;
private final int bubbleId;
private final String type;
private int effect;
private transient boolean canWalk;
private boolean sqlUpdateNeeded;
private boolean xyzUpdateNeeded;
private transient int followingHabboId;
protected final RoomBot roomUnit;
public static final String NO_CHAT_SET = "${bot.skill.chatter.configuration.text.placeholder}";
public static String[] PLACEMENT_MESSAGES = "Yo!;Hello I'm a real party animal!;Hello!".split(";");
@Getter
private final ArrayList<String> chatLines;
public Bot(int id, String name, String motto, String figure, HabboGender gender, int ownerId, String ownerName) {
this.id = id;
this.name = name;
this.motto = motto;
this.figure = figure;
this.gender = gender;
this.ownerId = ownerId;
this.ownerName = ownerName;
this.chatAuto = false;
this.chatRandom = false;
this.chatDelay = 1000;
this.chatLines = new ArrayList<>();
this.type = "generic_bot";
this.room = null;
this.bubbleId = RoomChatMessageBubbles.BOT_RENTABLE.getType();
}
public Bot(ResultSet set) throws SQLException {
this.id = set.getInt("id");
this.name = set.getString("name");
this.motto = set.getString("motto");
this.figure = set.getString("figure");
this.gender = HabboGender.valueOf(set.getString("gender"));
this.ownerId = set.getInt(DatabaseConstants.USER_ID);
//@Deprecated
this.ownerId = set.getInt("owner_id");
this.ownerName = set.getString("owner_name");
this.ownerInfo = Emulator.getGameEnvironment().getHabboManager().getOfflineHabboInfo(set.getInt("owner_id"));
this.chatAuto = set.getString("chat_auto").equals("1");
this.chatRandom = set.getString("chat_random").equals("1");
this.chatDelay = set.getShort("chat_delay");
@ -115,61 +83,30 @@ public class Bot extends Unit implements Runnable {
this.type = set.getString("type");
this.effect = set.getInt("effect");
this.canWalk = set.getString("freeroam").equals("1");
this.room = null;
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
this.needsUpdate = false;
this.sqlUpdateNeeded = false;
this.bubbleId = set.getInt("bubble_id");
this.roomUnit = new RoomBot();
this.roomUnit.setUnit(this);
}
public Bot(Bot bot) {
this.name = bot.getName();
this.motto = bot.getMotto();
this.figure = bot.getFigure();
this.gender = bot.getGender();
this.ownerId = bot.getOwnerId();
this.ownerName = bot.getOwnerName();
this.chatAuto = true;
this.chatRandom = false;
this.chatDelay = 10;
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
this.chatLines = new ArrayList<>(List.of("Default Message :D"));
this.type = bot.getType();
this.effect = bot.getEffect();
this.bubbleId = bot.getBubbleId();
this.needsUpdate = false;
}
public static void initialise() {}
public static void initialise() {
}
public static void dispose() {
}
public void needsUpdate(boolean needsUpdate) {
this.needsUpdate = needsUpdate;
}
public boolean needsUpdate() {
return this.needsUpdate;
}
public static void dispose() {}
@Override
public void run() {
if (this.needsUpdate) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
if (this.sqlUpdateNeeded) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, owner_id = ?, room_id = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
statement.setString(1, this.name);
statement.setString(2, this.motto);
statement.setString(3, this.figure);
statement.setString(4, this.gender.toString());
statement.setInt(5, this.ownerId);
statement.setInt(6, this.room == null ? 0 : this.room.getRoomInfo().getId());
statement.setInt(7, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getBodyRotation().getValue());
statement.setInt(8, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getDanceType().getType());
statement.setInt(5, this.ownerInfo.getId());
statement.setInt(6, this.roomUnit.getRoom() == null ? 0 : this.roomUnit.getRoom().getRoomInfo().getId());
statement.setInt(7, this.roomUnit.getBodyRotation().getValue());
statement.setInt(8, this.roomUnit.getDanceType().getType());
statement.setString(9, this.canWalk ? "1" : "0");
StringBuilder text = new StringBuilder();
for (String s : this.chatLines) {
@ -183,7 +120,7 @@ public class Bot extends Unit implements Runnable {
statement.setInt(15, this.bubbleId);
statement.setInt(16, this.id);
statement.execute();
this.needsUpdate = false;
this.sqlUpdateNeeded = false;
} catch (SQLException e) {
log.error("Caught SQL exception", e);
}
@ -191,122 +128,108 @@ public class Bot extends Unit implements Runnable {
}
public void talk(String message) {
if (this.room != null) {
if (this.roomUnit.getRoom() != null) {
BotChatEvent event = new BotTalkEvent(this, message);
if (Emulator.getPluginManager().fireEvent(event).isCancelled())
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
this.room.botChat(new ChatMessageComposer(new RoomChatMessage(event.getMessage(), this.getRoomUnit(), RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
this.roomUnit.getRoom().botChat(new ChatMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
if (message.equals("o/") || message.equals("_o/")) {
this.room.sendComposer(new ExpressionMessageComposer(this.getRoomUnit(), RoomUserAction.WAVE).compose());
this.roomUnit.getRoom().sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose());
}
}
}
public void shout(String message) {
if (this.room != null) {
if (this.roomUnit.getRoom() != null) {
BotChatEvent event = new BotShoutEvent(this, message);
if (Emulator.getPluginManager().fireEvent(event).isCancelled())
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
this.room.botChat(new ShoutMessageComposer(new RoomChatMessage(event.getMessage(), this.getRoomUnit(), RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
this.roomUnit.getRoom().botChat(new ShoutMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))).compose());
if (message.equals("o/") || message.equals("_o/")) {
this.room.sendComposer(new ExpressionMessageComposer(this.getRoomUnit(), RoomUserAction.WAVE).compose());
this.roomUnit.getRoom().sendComposer(new ExpressionMessageComposer(this.roomUnit, RoomUserAction.WAVE).compose());
}
}
}
public void whisper(String message, Habbo habbo) {
if (this.room != null && habbo != null) {
if (this.roomUnit.getRoom() != null && habbo != null) {
BotWhisperEvent event = new BotWhisperEvent(this, message, habbo);
if (Emulator.getPluginManager().fireEvent(event).isCancelled())
return;
this.chatTimestamp = Emulator.getIntUnixTimestamp();
event.getTarget().getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(event.getMessage(), this.getRoomUnit(), RoomChatMessageBubbles.getBubble(this.getBubbleId()))));
event.getTarget().getClient().sendResponse(new WhisperMessageComposer(new RoomChatMessage(event.getMessage(), this.roomUnit, RoomChatMessageBubbles.getBubble(this.getBubbleId()))));
}
}
public void onPlace(Habbo habbo, Room room) {
if (this.getRoomUnit() != null) {
this.getRoomUnit().giveEffect(this.effect, -1);
if (this.roomUnit != null) {
this.roomUnit.giveEffect(this.effect, -1);
}
if(PLACEMENT_MESSAGES.length > 0) {
String message = PLACEMENT_MESSAGES[Emulator.getRandom().nextInt(PLACEMENT_MESSAGES.length)];
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), room, new Object[]{message})) {
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, room, new Object[]{message})) {
this.talk(message);
}
}
}
public void onPickUp(Habbo habbo, Room room) {
}
public void onPickUp(Habbo habbo, Room room) {}
public void onUserSay(final RoomChatMessage message) {}
public int getBubbleId() {
return bubbleId;
}
public void setName(String name) {
this.name = name;
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
//if(this.room != null)
//this.room.sendComposer(new ChangeNameUpdatedComposer(this.getRoomUnit(), this.getName()).compose());
//this.roomUnit.getRoom().sendComposer(new ChangeNameUpdatedComposer(this.roomUnit, this.getName()).compose());
}
public void setMotto(String motto) {
this.motto = motto;
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
public void setFigure(String figure) {
this.figure = figure;
this.needsUpdate = true;
if (this.room != null)
this.room.sendComposer(new RoomUsersComposer(this).compose());
this.sqlUpdateNeeded = true;
this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose());
}
public void setGender(HabboGender gender) {
this.gender = gender;
this.needsUpdate = true;
if (this.room != null)
this.room.sendComposer(new RoomUsersComposer(this).compose());
this.sqlUpdateNeeded = true;
this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose());
}
public void setOwnerId(int ownerId) {
this.ownerId = ownerId;
this.needsUpdate = true;
if (this.room != null)
this.room.sendComposer(new RoomUsersComposer(this).compose());
this.sqlUpdateNeeded = true;
this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose());
}
public void setOwnerName(String ownerName) {
this.ownerName = ownerName;
this.needsUpdate = true;
if (this.room != null)
this.room.sendComposer(new RoomUsersComposer(this).compose());
this.sqlUpdateNeeded = true;
this.roomUnit.getRoom().sendComposer(new RoomUsersComposer(this).compose());
}
public void setChatAuto(boolean chatAuto) {
this.chatAuto = chatAuto;
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
public void setChatRandom(boolean chatRandom) {
this.chatRandom = chatRandom;
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
public boolean hasChat() {
@ -315,28 +238,24 @@ public class Bot extends Unit implements Runnable {
public void setChatDelay(short chatDelay) {
this.chatDelay = (short) Math.min(Math.max(chatDelay, BotManager.MINIMUM_CHAT_SPEED), BotManager.MAXIMUM_CHAT_SPEED);
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
this.chatTimeOut = Emulator.getIntUnixTimestamp() + this.chatDelay;
}
public int getChatTimestamp() {
return this.chatTimestamp;
}
public void clearChat() {
synchronized (this.chatLines) {
this.chatLines.clear();
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
}
public void setEffect(int effect, int duration) {
this.effect = effect;
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
if (this.getRoomUnit() != null) {
if (this.room != null) {
this.getRoomUnit().giveEffect(this.effect, duration);
if (this.roomUnit != null) {
if (this.roomUnit.getRoom() != null) {
this.roomUnit.giveEffect(this.effect, duration);
}
}
}
@ -344,14 +263,14 @@ public class Bot extends Unit implements Runnable {
public void addChatLines(ArrayList<String> chatLines) {
synchronized (this.chatLines) {
this.chatLines.addAll(chatLines);
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
}
public void addChatLine(String chatLine) {
synchronized (this.chatLines) {
this.chatLines.add(chatLine);
this.needsUpdate = true;
this.sqlUpdateNeeded = true;
}
}
@ -363,37 +282,6 @@ public class Bot extends Unit implements Runnable {
this.canWalk = canWalk;
}
public void onPlaceUpdate() {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
statement.setString(1, this.name);
statement.setString(2, this.motto);
statement.setString(3, this.figure);
statement.setString(4, this.gender.toString());
statement.setInt(5, this.ownerId);
statement.setInt(6, this.room == null ? 0 : this.room.getRoomInfo().getId());
statement.setInt(7, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getCurrentPosition().getX());
statement.setInt(8, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getCurrentPosition().getY());
statement.setDouble(9, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getCurrentZ());
statement.setInt(10, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getBodyRotation().getValue());
statement.setInt(11, this.getRoomUnit() == null ? 0 : this.getRoomUnit().getDanceType().getType());
statement.setString(12, this.canWalk ? "1" : "0");
StringBuilder text = new StringBuilder();
for (String s : this.chatLines) {
text.append(s).append("\r");
}
statement.setString(13, text.toString());
statement.setString(14, this.chatAuto ? "1" : "0");
statement.setString(15, this.chatRandom ? "1" : "0");
statement.setInt(16, this.chatDelay);
statement.setInt(17, this.effect);
statement.setInt(18, this.bubbleId);
statement.setInt(19, this.id);
statement.execute();
} catch (SQLException e) {
log.error("Caught SQL exception", e);
}
}
public void incrementLastChatIndex() {
this.lastChatIndex++;
}
@ -401,4 +289,32 @@ public class Bot extends Unit implements Runnable {
public void resetLastChatIndex() {
this.lastChatIndex = 0;
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(-this.id);
message.appendString(this.name);
message.appendString(this.motto);
message.appendString(this.figure);
message.appendInt(this.roomUnit.getVirtualId());
message.appendInt(this.roomUnit.getCurrentPosition().getX());
message.appendInt(this.roomUnit.getCurrentPosition().getY());
message.appendString(String.valueOf(this.roomUnit.getCurrentZ()));
message.appendInt(this.roomUnit.getBodyRotation().getValue());
message.appendInt(4);
message.appendString(this.gender.name().toUpperCase());
message.appendInt(this.ownerId);
message.appendString(this.ownerName);
message.appendInt(10);
message.appendShort(0);
message.appendShort(1);
message.appendShort(2);
message.appendShort(3);
message.appendShort(4);
message.appendShort(5);
message.appendShort(6);
message.appendShort(7);
message.appendShort(8);
message.appendShort(9);
}
}

View File

@ -2,25 +2,11 @@ package com.eu.habbo.habbohotel.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.rooms.FurnitureMovementError;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomTile;
import com.eu.habbo.habbohotel.rooms.RoomTileState;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomBot;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
import com.eu.habbo.messages.outgoing.generic.alerts.BubbleAlertKeys;
import com.eu.habbo.messages.outgoing.generic.alerts.NotificationDialogMessageComposer;
import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
import gnu.trove.map.hash.THashMap;
import lombok.extern.slf4j.Slf4j;
@ -103,71 +89,6 @@ public class BotManager {
return bot;
}
public void placeBot(Bot bot, Habbo habbo, Room room, RoomTile location) {
BotPlacedEvent event = new BotPlacedEvent(bot, location, habbo);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled())
return;
if (room != null && bot != null && habbo != null) {
if (room.getRoomInfo().isRoomOwner(habbo) || habbo.hasPermissionRight(Permission.ACC_ANYROOMOWNER) || habbo.hasPermissionRight(Permission.ACC_PLACEFURNI)) {
if (room.getRoomUnitManager().getCurrentBots().size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
if (room.getRoomUnitManager().hasHabbosAt(location) || (!location.isWalkable() && location.getState() != RoomTileState.SIT && location.getState() != RoomTileState.LAY))
return;
if (!room.getRoomUnitManager().getBotsAt(location).isEmpty()) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
return;
}
RoomBot roomBot = bot.getRoomUnit();
roomBot.setRotation(RoomRotation.SOUTH);
roomBot.setLocation(location);
double stackHeight = room.getRoomItemManager().getTopHeightAt(location.getX(), location.getY());
roomBot.setCurrentZ(stackHeight);
roomBot.setRoom(room);
roomBot.setRoomUnitType(RoomUnitType.BOT);
roomBot.setCanWalk(room.isAllowBotsWalk());
bot.setRoom(room);
bot.onPlaceUpdate();
room.getRoomUnitManager().addRoomUnit(bot);
Emulator.getThreading().run(bot);
room.sendComposer(new RoomUsersComposer(bot).compose());
room.sendComposer(new UserUpdateComposer(bot.getRoomUnit()).compose());
habbo.getInventory().getBotsComponent().removeBot(bot);
habbo.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(habbo, room);
RoomItem topItem = room.getRoomItemManager().getTopItemAt(location.getX(), location.getY());
if (topItem != null) {
try {
topItem.onWalkOn(bot.getRoomUnit(), room, null);
} catch (Exception e) {
log.error("Caught exception", e);
}
}
} else {
habbo.getClient().sendResponse(new NotificationDialogMessageComposer(BubbleAlertKeys.FURNITURE_PLACEMENT_ERROR.getKey(), FurnitureMovementError.NO_RIGHTS.getErrorCode()));
}
}
}
public void pickUpBot(int botId, Habbo habbo, Room room) {
if (habbo.getRoomUnit().getRoom() != null) {
this.pickUpBot(habbo.getRoomUnit().getRoom().getRoomUnitManager().getRoomBotById(Math.abs(botId)), habbo, room);
}
}
public void pickUpBot(Bot bot, Habbo habbo, Room room) {
HabboInfo botOwnerInfo = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabboInfo(bot.getOwnerId()) : habbo.getHabboInfo();
@ -190,7 +111,7 @@ public class BotManager {
bot.setFollowingHabboId(0);
bot.setOwnerId(botOwnerInfo.getId());
bot.setOwnerName(botOwnerInfo.getUsername());
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
Habbo receiver = habbo == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : habbo;

View File

@ -30,10 +30,6 @@ public class ButlerBot extends Bot {
super(set);
}
public ButlerBot(Bot bot) {
super(bot);
}
public static void initialise() {
if (serveItems == null)
serveItems = new THashMap<>();
@ -58,11 +54,11 @@ public class ButlerBot extends Bot {
@Override
public void onUserSay(final RoomChatMessage message) {
if (this.getRoomUnit().hasStatus(RoomUnitStatus.MOVE) || this.getRoom() == null) {
if (this.roomUnit.hasStatus(RoomUnitStatus.MOVE) || this.roomUnit.getRoom() == null) {
return;
}
double distanceBetweenBotAndHabbo = this.getRoomUnit().getCurrentPosition().distance(message.getHabbo().getRoomUnit().getCurrentPosition());
double distanceBetweenBotAndHabbo = this.roomUnit.getCurrentPosition().distance(message.getHabbo().getRoomUnit().getCurrentPosition());
if (distanceBetweenBotAndHabbo <= Emulator.getConfig().getInt("hotel.bot.butler.commanddistance")) {
@ -81,7 +77,7 @@ public class ButlerBot extends Bot {
}
// Start give handitem process
if (this.getRoomUnit().isCanWalk()) {
if (this.roomUnit.isCanWalk()) {
final String key = keyword;
final Bot bot = this;
@ -91,16 +87,16 @@ public class ButlerBot extends Bot {
// Step 2: Prepare tasks for when the Bot (carrying the handitem) reaches the Habbo
final List<Runnable> tasks = new ArrayList<>();
tasks.add(new RoomUnitGiveHanditem(serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), serveEvent.getItemId()));
tasks.add(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), 0));
tasks.add(new RoomUnitGiveHanditem(this.roomUnit, serveEvent.getHabbo().getRoomUnit().getRoom(), 0));
tasks.add(() -> {
if (this.getRoom() != null) {
if (this.roomUnit.getRoom() != null) {
String botMessage = Emulator.getTexts()
.getValue("bots.butler.given")
.replace("%key%", key)
.replace("%username%", serveEvent.getHabbo().getHabboInfo().getUsername());
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{botMessage})) {
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, this.roomUnit.getRoom(), new Object[]{botMessage})) {
bot.talk(botMessage);
}
}
@ -116,20 +112,20 @@ public class ButlerBot extends Bot {
});
// Give bot the handitem that it's going to give the Habbo
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), serveEvent.getItemId()));
Emulator.getThreading().run(new RoomUnitGiveHanditem(this.roomUnit, serveEvent.getHabbo().getRoomUnit().getRoom(), serveEvent.getItemId()));
if (distanceBetweenBotAndHabbo > Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)) {
Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.getRoomUnit(), serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)));
Emulator.getThreading().run(new RoomUnitWalkToRoomUnit(this.roomUnit, serveEvent.getHabbo().getRoomUnit(), serveEvent.getHabbo().getRoomUnit().getRoom(), tasks, failedReached, Emulator.getConfig().getInt("hotel.bot.butler.reachdistance", 3)));
} else {
Emulator.getThreading().run(failedReached.get(0), 1000);
}
} else {
if (this.getRoom() != null) {
if (this.roomUnit.getRoom() != null) {
serveEvent.getHabbo().getRoomUnit().setHandItem(serveEvent.getItemId());
this.getRoom().sendComposer(new CarryObjectMessageComposer(serveEvent.getHabbo().getRoomUnit()).compose());
this.roomUnit.getRoom().sendComposer(new CarryObjectMessageComposer(serveEvent.getHabbo().getRoomUnit()).compose());
String msg = Emulator.getTexts().getValue("bots.butler.given").replace("%key%", keyword).replace("%username%", serveEvent.getHabbo().getHabboInfo().getUsername());
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.getRoomUnit(), this.getRoom(), new Object[]{msg})) {
if (!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this.roomUnit, this.roomUnit.getRoom(), new Object[]{msg})) {
this.talk(msg);
}
}

View File

@ -20,10 +20,6 @@ public class VisitorBot extends Bot {
super(set);
}
public VisitorBot(Bot bot) {
super(bot);
}
public static void initialise() {
DATE_FORMAT = new SimpleDateFormat(Emulator.getConfig().getValue("bots.visitor.dateformat"));
}

View File

@ -902,7 +902,7 @@ public class CatalogManager {
if (bot != null) {
bot.setOwnerId(habbo.getClient().getHabbo().getHabboInfo().getId());
bot.setOwnerName(habbo.getClient().getHabbo().getHabboInfo().getUsername());
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
habbo.getClient().getHabbo().getInventory().getBotsComponent().addBot(bot);
habbo.getClient().sendResponse(new BotAddedToInventoryComposer(bot));

View File

@ -51,7 +51,7 @@ public class WiredEffectBotTeleport extends InteractionWiredEffect {
for (RoomItem item : this.getWiredSettings().getItems(room)) {
if (item.getRoomId() != 0) {
Room room1 = bot.getRoom();
Room room1 = bot.getRoomUnit().getRoom();
if (item.getRoomId() == room1.getRoomInfo().getId()) {
if (i == j) {
teleportUnitToTile(bot.getRoomUnit(), room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()));

View File

@ -54,7 +54,7 @@ public class WiredEffectBotWalkToFurni extends InteractionWiredEffect {
RoomItem item = possibleItems.get(Emulator.getRandom().nextInt(possibleItems.size()));
if (item.getRoomId() != 0) {
Room room1 = bot.getRoom();
Room room1 = bot.getRoomUnit().getRoom();
if (item.getRoomId() == room1.getRoomInfo().getId()) {
bot.getRoomUnit().walkTo(room.getLayout().getTile(item.getCurrentPosition().getX(), item.getCurrentPosition().getY()));
}

View File

@ -37,6 +37,10 @@ public class RideablePet extends Pet {
this.hasSaddle = hasSaddle;
}
public boolean hasRider() {
return this.rider != null;
}
public boolean anyoneCanRide() {
return this.anyoneCanRide;
}

View File

@ -16,7 +16,6 @@ import com.eu.habbo.habbohotel.items.interactions.games.InteractionGameTimer;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
@ -392,75 +391,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
this.sendComposer(new UserUpdateComposer(roomUnit).compose());
}
public void updateHabbosAt(RoomTile tile) {
RoomItem item = this.roomItemManager.getTopItemAt(tile.getX(), tile.getY());
Collection<Habbo> habbos = this.roomUnitManager.getHabbosAt(tile);
if(habbos == null || habbos.isEmpty()) {
return;
}
//Improve this
for (Habbo habbo : habbos) {
double z = habbo.getRoomUnit().getCurrentPosition().getStackHeight();
if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
}
if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
}
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
if(item.getBaseItem().allowSit()) {
habbo.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item)));
} else if(item.getBaseItem().allowLay()) {
habbo.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item)));
}
habbo.getRoomUnit().setCurrentZ(item.getCurrentZ());
habbo.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation()));
} else {
habbo.getRoomUnit().setCurrentZ(z);
}
}
}
public void updateBotsAt(RoomTile tile) {
this.updateBotsAt(tile.getX(), tile.getY());
}
public void updateBotsAt(short x, short y) {
RoomItem topItem = this.roomItemManager.getTopItemAt(x, y);
THashSet<RoomUnit> roomUnits = new THashSet<>();
RoomTile tile = this.layout.getTile(x, y);
this.roomUnitManager.getBotsAt(tile).forEach(bot -> {
if (topItem != null) {
if (topItem.getBaseItem().allowSit()) {
bot.getRoomUnit().setCurrentZ(topItem.getCurrentZ());
bot.getRoomUnit().setRotation(RoomRotation.fromValue(topItem.getRotation()));
} else {
bot.getRoomUnit().setCurrentZ(topItem.getCurrentZ() + Item.getCurrentHeight(topItem));
if (topItem.getBaseItem().allowLay()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(topItem.getCurrentZ() + topItem.getBaseItem().getHeight()));
}
}
} else {
bot.getRoomUnit().setCurrentZ(bot.getRoomUnit().getCurrentPosition().getStackHeight());
}
roomUnits.add(bot.getRoomUnit());
});
if (!roomUnits.isEmpty()) {
this.sendComposer(new UserUpdateComposer(roomUnits).compose());
}
}
public void startTrade(Habbo userOne, Habbo userTwo) {
RoomTrade trade = new RoomTrade(userOne, userTwo, this);
synchronized (this.activeTrades) {
@ -1741,12 +1671,6 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
}
public boolean canSitOrLayAt(RoomTile tile) {
return this.canSitOrLayAt(tile.getX(), tile.getY());
}
public boolean canSitOrLayAt(int x, int y) {
RoomTile tile = this.layout.getTile((short) x, (short) y);
if(tile == null) {
return false;
}
@ -1754,7 +1678,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.roomUnitManager.hasHabbosAt(tile))
return false;
THashSet<RoomItem> items = this.roomItemManager.getItemsAt(x, y);
THashSet<RoomItem> items = this.roomItemManager.getItemsAt(tile);
return this.canSitAt(items) || this.canLayAt(items);
}
@ -1769,7 +1693,7 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
if (this.roomUnitManager.hasHabbosAt(tile))
return false;
return this.canSitAt(this.roomItemManager.getItemsAt(x, y));
return this.canSitAt(this.roomItemManager.getItemsAt(tile));
}
boolean canSitAt(THashSet<RoomItem> items) {

View File

@ -318,8 +318,8 @@ public class RoomItemManager {
this.room.sendComposer(new ObjectAddMessageComposer(item, this.room.getFurniOwnerName(item.getOwnerInfo().getId())).compose());
for (RoomTile t : occupiedTiles) {
this.room.updateHabbosAt(t);
this.room.updateBotsAt(t);
this.room.getRoomUnitManager().updateHabbosAt(t);
this.room.getRoomUnitManager().updateBotsAt(t);
}
Emulator.getThreading().run(item);
@ -514,8 +514,8 @@ public class RoomItemManager {
//Update Habbos at old position
for (RoomTile t : occupiedTiles) {
this.room.updateHabbosAt(t);
this.room.updateBotsAt(t);
this.room.getRoomUnitManager().updateHabbosAt(t);
this.room.getRoomUnitManager().updateBotsAt(t);
}
if (Emulator.getConfig().getBoolean("wired.place.under", false)) {
@ -572,8 +572,8 @@ public class RoomItemManager {
this.room.sendComposer(new HeightMapUpdateMessageComposer(this.room, updatedTiles).compose());
this.room.updateTiles(updatedTiles);
updatedTiles.forEach(tile -> {
this.room.updateHabbosAt(tile);
this.room.updateBotsAt(tile.getX(), tile.getY());
this.room.getRoomUnitManager().updateHabbosAt(tile);
this.room.getRoomUnitManager().updateBotsAt(tile);
});
} else if (item.getBaseItem().getType() == FurnitureType.WALL) {
this.room.sendComposer(new ItemRemoveMessageComposer(item).compose());

View File

@ -1,6 +1,7 @@
package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
@ -562,7 +563,8 @@ public class RoomLayout {
public RoomTile getRandomWalkableTilesAround(RoomUnit roomUnit, RoomTile tile, Room room, int radius) {
if(!this.tileExists(tile.getX(), tile.getY())) {
tile = this.getTile(roomUnit.getCurrentPosition().getX(), roomUnit.getCurrentPosition().getY());
room.getRoomUnitManager().getRoomBotById(roomUnit.getVirtualId()).needsUpdate(true);
Bot bot = room.getRoomUnitManager().getRoomBotById(roomUnit.getVirtualId());
bot.setSqlUpdateNeeded(true);
}
List<RoomTile> newTiles = new ArrayList<>();

View File

@ -710,7 +710,7 @@ public class RoomManager {
}
habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values(), true));
habbo.getClient().sendResponse(new RoomUsersComposer(room.getRoomUnitManager().getCurrentBots().values()));
if (!room.getRoomUnitManager().getCurrentBots().isEmpty()) {
room.getRoomUnitManager().getCurrentBots().values().stream()

View File

@ -87,7 +87,8 @@ public class RoomRightsManager {
return;
}
if (this.rights.add(habbo.getHabboInfo().getId())) {
this.rights.add(habbo.getHabboInfo().getId());
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("INSERT INTO room_rights VALUES (?, ?)")) {
statement.setInt(1, this.room.getRoomInfo().getId());
statement.setInt(2, habbo.getHabboInfo().getId());
@ -95,7 +96,6 @@ public class RoomRightsManager {
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
}
this.room.getRoomRightsManager().refreshRightsForHabbo(habbo);
this.room.sendComposer(new FlatControllerAddedComposer(this.room, habbo.getHabboInfo().getId(), habbo.getHabboInfo().getUsername()).compose());

View File

@ -2,6 +2,8 @@ package com.eu.habbo.habbohotel.rooms;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.bots.BotManager;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.PetManager;
@ -15,13 +17,16 @@ import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet;
import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.users.HabboInfo;
import com.eu.habbo.messages.outgoing.generic.alerts.BotErrorComposer;
import com.eu.habbo.messages.outgoing.inventory.BotAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.BotRemovedFromInventoryComposer;
import com.eu.habbo.messages.outgoing.inventory.PetAddedToInventoryComposer;
import com.eu.habbo.messages.outgoing.rooms.pets.RoomPetComposer;
import com.eu.habbo.messages.outgoing.rooms.users.RoomUsersComposer;
import com.eu.habbo.messages.outgoing.rooms.users.UserRemoveMessageComposer;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.bots.BotPickUpEvent;
import com.eu.habbo.plugin.events.bots.BotPlacedEvent;
import gnu.trove.set.hash.THashSet;
import lombok.Getter;
@ -67,28 +72,31 @@ public class RoomUnitManager {
private synchronized void loadBots(Connection connection) {
this.currentBots.clear();
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.user_id = users.id WHERE room_id = ?")) {
try (PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON bots.owner_id = users.id WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId());
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
Bot bot = Emulator.getGameEnvironment().getBotManager().loadBot(set);
//TODO IMPROVE THIS
if (bot != null) {
bot.setRoom(this.room);
bot.setRoomUnit(new RoomBot());
bot.getRoomUnit().setUnit(bot);
bot.getRoomUnit().setRoom(this.room);
bot.getRoomUnit().setLocation(this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y")));
if (bot.getRoomUnit().getCurrentPosition() == null || bot.getRoomUnit().getCurrentPosition().getState() == RoomTileState.INVALID) {
RoomTile spawnTile = this.room.getLayout().getTile((short) set.getInt("x"), (short) set.getInt("y"));
if(spawnTile == null) {
bot.getRoomUnit().setCurrentPosition(this.room.getLayout().getDoorTile());
bot.getRoomUnit().setCurrentZ(this.room.getLayout().getDoorTile().getStackHeight());
bot.getRoomUnit().setLocation(this.room.getLayout().getDoorTile());
bot.getRoomUnit().setRotation(RoomRotation.fromValue(this.room.getLayout().getDoorDirection()));
} else {
bot.getRoomUnit().setCurrentPosition(spawnTile);
bot.getRoomUnit().setCurrentZ(set.getDouble("z"));
bot.getRoomUnit().setRotation(RoomRotation.values()[set.getInt("rot")]);
}
bot.getRoomUnit().setRoomUnitType(RoomUnitType.BOT);
bot.getRoomUnit().setDanceType(DanceType.values()[set.getInt("dance")]);
//@DEPRECATED
bot.getRoomUnit().setInRoom(true);
bot.getRoomUnit().giveEffect(set.getInt("effect"), Integer.MAX_VALUE, false);
@ -150,7 +158,9 @@ public class RoomUnitManager {
this.currentHabbos.put(((Habbo) unit).getHabboInfo().getId(), (Habbo) unit);
unit.getRoomUnit().getRoom().updateDatabaseUserCount();
}
case BOT -> this.currentBots.put(((Bot) unit).getId(), (Bot) unit);
case BOT -> {
this.currentBots.put(((Bot) unit).getId(), (Bot) unit);
}
case PET -> {
this.currentPets.put(((Pet) unit).getId(), (Pet) unit);
Habbo habbo = this.getRoomHabboById(((Pet) unit).getUserId());
@ -170,6 +180,10 @@ public class RoomUnitManager {
return this.currentRoomUnits.values().stream().anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile));
}
public boolean areRoomUnitsAt(RoomTile tile, RoomUnit skippedRoomUnit) {
return this.currentRoomUnits.values().stream().filter(roomUnit -> !roomUnit.equals(skippedRoomUnit)).anyMatch(roomUnit -> roomUnit.getCurrentPosition().equals(tile));
}
public List<RoomUnit> getAvatarsAt(RoomTile tile) {
return Stream.concat(this.getHabbosAt(tile).stream(), this.getBotsAt(tile).stream()).map(Unit::getRoomUnit).collect(Collectors.toList());
}
@ -202,6 +216,41 @@ public class RoomUnitManager {
return this.currentHabbos.values().stream().filter(habbo -> habbo.getRoomUnit() == roomUnit).findFirst().orElse(null);
}
public void updateHabbosAt(RoomTile tile) {
Collection<Habbo> habbos = this.getHabbosAt(tile);
if(habbos == null || habbos.isEmpty()) {
return;
}
RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY());
for (Habbo habbo : habbos) {
double z = habbo.getRoomUnit().getCurrentPosition().getStackHeight();
if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !habbo.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
}
if (habbo.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !habbo.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) {
habbo.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
}
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
if(item.getBaseItem().allowSit()) {
habbo.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item)));
} else if(item.getBaseItem().allowLay()) {
habbo.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item)));
}
habbo.getRoomUnit().setCurrentZ(item.getCurrentZ());
habbo.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation()));
} else {
habbo.getRoomUnit().setCurrentZ(z);
}
}
}
public Bot getRoomBotById(int botId) {
return this.currentBots.get(botId);
}
@ -224,16 +273,17 @@ public class RoomUnitManager {
return this.currentBots.values().stream().filter(bot -> bot.getRoomUnit().getCurrentPosition().equals(tile)).collect(Collectors.toSet());
}
public void placeBot(Bot bot, Habbo habbo, int x, int y) {
public void placeBot(Bot bot, Habbo botOwner, int x, int y) {
synchronized (this.currentBots) {
RoomTile spawnTile = room.getLayout().getTile((short) x, (short) y);
if(spawnTile == null) {
spawnTile = room.getLayout().getDoorTile();
if(spawnTile == null || (!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || this.areRoomUnitsAt(spawnTile)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
return;
}
if (Emulator.getPluginManager().isRegistered(BotPlacedEvent.class, false)) {
Event event = new BotPlacedEvent(bot, spawnTile, habbo);
Event event = new BotPlacedEvent(bot, spawnTile, botOwner);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled()) {
@ -241,13 +291,8 @@ public class RoomUnitManager {
}
}
if(this.currentBots.size() >= Room.MAXIMUM_BOTS && !habbo.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
if((!spawnTile.isWalkable() && !this.room.canSitOrLayAt(spawnTile)) || this.areRoomUnitsAt(spawnTile)) {
habbo.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_BOTS_SELECTED_TILE_NOT_FREE));
if(this.currentBots.size() >= Room.MAXIMUM_BOTS && !botOwner.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS)) {
botOwner.getClient().sendResponse(new BotErrorComposer(BotErrorComposer.ROOM_ERROR_MAX_BOTS));
return;
}
@ -259,15 +304,92 @@ public class RoomUnitManager {
roomBot.setRotation(RoomRotation.SOUTH);
roomBot.setCanWalk(this.room.isAllowBotsWalk());
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
this.addRoomUnit(bot);
this.room.sendComposer(new RoomUsersComposer(bot).compose());
roomBot.instantUpdate();
habbo.getInventory().getBotsComponent().removeBot(bot);
habbo.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(habbo, room);
botOwner.getInventory().getBotsComponent().removeBot(bot);
botOwner.getClient().sendResponse(new BotRemovedFromInventoryComposer(bot));
bot.onPlace(botOwner, room);
}
}
public void updateBotsAt(RoomTile tile) {
Collection<Bot> bots = this.getBotsAt(tile);
if(bots == null || bots.isEmpty()) {
return;
}
RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile.getX(), tile.getY());
bots.forEach(bot -> {
double z = bot.getRoomUnit().getCurrentPosition().getStackHeight();
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.SIT) && ((item == null && !bot.getRoomUnit().isCmdSitEnabled()) || (item != null && !item.getBaseItem().allowSit()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.SIT);
}
if (bot.getRoomUnit().hasStatus(RoomUnitStatus.LAY) && ((item == null && !bot.getRoomUnit().isCmdLayEnabled()) || (item != null && !item.getBaseItem().allowLay()))) {
bot.getRoomUnit().removeStatus(RoomUnitStatus.LAY);
}
if (item != null && (item.getBaseItem().allowSit() || item.getBaseItem().allowLay())) {
if(item.getBaseItem().allowSit()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.SIT, String.valueOf(Item.getCurrentHeight(item)));
} else if(item.getBaseItem().allowLay()) {
bot.getRoomUnit().addStatus(RoomUnitStatus.LAY, String.valueOf(Item.getCurrentHeight(item)));
}
bot.getRoomUnit().setCurrentZ(item.getCurrentZ());
bot.getRoomUnit().setRotation(RoomRotation.fromValue(item.getRotation()));
} else {
bot.getRoomUnit().setCurrentZ(z);
}
});
}
public void pickUpBot(Bot bot, Habbo picker) {
HabboInfo botOwnerInfo = picker == null ? bot.getOwnerInfo() : picker.getHabboInfo();
BotPickUpEvent pickedUpEvent = new BotPickUpEvent(bot, picker);
Emulator.getPluginManager().fireEvent(pickedUpEvent);
if (pickedUpEvent.isCancelled())
return;
if (picker == null || (bot.getOwnerInfo().getId() == picker.getHabboInfo().getId() || picker.hasPermissionRight(Permission.ACC_ANYROOMOWNER))) {
if (picker != null && !picker.hasPermissionRight(Permission.ACC_UNLIMITED_BOTS) && picker.getInventory().getBotsComponent().getBots().size() >= BotManager.MAXIMUM_BOT_INVENTORY_SIZE) {
picker.alert(Emulator.getTexts().getValue("error.bots.max.inventory").replace("%amount%", String.valueOf(BotManager.MAXIMUM_BOT_INVENTORY_SIZE)));
return;
}
bot.onPickUp(picker, this.room);
bot.setFollowingHabboId(0);
//@DEPRECATED
bot.setOwnerId(botOwnerInfo.getId());
bot.setOwnerName(botOwnerInfo.getUsername());
bot.setOwnerInfo(botOwnerInfo);
this.removeBot(bot);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
Habbo receiver = picker == null ? Emulator.getGameEnvironment().getHabboManager().getHabbo(botOwnerInfo.getId()) : picker;
if (receiver != null) {
receiver.getInventory().getBotsComponent().addBot(bot);
receiver.getClient().sendResponse(new BotAddedToInventoryComposer(bot));
}
}
}
@ -384,9 +506,10 @@ public class RoomUnitManager {
roomHabbo.clear();
}
public boolean removeBot(Bot bot) {
public void removeBot(Bot bot) {
synchronized (this.currentBots) {
if (this.currentBots.containsKey(bot.getId())) {
//TODO gotta do a method to removeUnit and clear tile
if (bot.getRoomUnit() != null && bot.getRoomUnit().getCurrentPosition() != null) {
bot.getRoomUnit().getCurrentPosition().removeUnit(bot.getRoomUnit());
}
@ -394,15 +517,13 @@ public class RoomUnitManager {
this.currentBots.remove(bot.getId());
this.currentRoomUnits.remove(bot.getRoomUnit().getVirtualId());
//@DEPRECATED
bot.getRoomUnit().setInRoom(false);
bot.setRoom(null);
bot.getRoomUnit().setRoom(null);
this.room.sendComposer(new UserRemoveMessageComposer(bot.getRoomUnit()).compose());
return true;
}
}
return false;
}
public Pet removePet(int petId) {
@ -471,7 +592,7 @@ public class RoomUnitManager {
while(botIterator.hasNext()) {
try {
Bot bot = botIterator.next();
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
Emulator.getThreading().run(bot);
} catch (NoSuchElementException e) {
log.error("Caught Exception", e);

View File

@ -78,4 +78,17 @@ public class RoomWordFilterManager {
}
}
}
public void removeAllWords() {
synchronized (this.filteredWords) {
this.filteredWords.clear();
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ?")) {
statement.setInt(1, this.room.getRoomInfo().getId());
statement.execute();
} catch (SQLException e) {
log.error(CAUGHT_SQL_EXCEPTION, e);
}
}
}
}

View File

@ -5,11 +5,13 @@ import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.items.Item;
import com.eu.habbo.habbohotel.items.interactions.InteractionWater;
import com.eu.habbo.habbohotel.items.interactions.InteractionWaterItem;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.*;
import com.eu.habbo.habbohotel.rooms.entities.RoomEntity;
import com.eu.habbo.habbohotel.rooms.entities.RoomRotation;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomAvatar;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomPet;
import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.users.DanceType;
import com.eu.habbo.messages.outgoing.rooms.users.UserUpdateComposer;
@ -32,59 +34,57 @@ import java.util.concurrent.ConcurrentHashMap;
@Accessors(chain = true)
public abstract class RoomUnit extends RoomEntity {
@Setter
private int virtualId;
protected int virtualId;
@Setter
private Unit unit;
protected Unit unit;
@Setter
private RoomUnitType roomUnitType;
protected RoomUnitType roomUnitType;
@Setter
private RoomRotation bodyRotation;
protected RoomRotation bodyRotation;
@Setter
private RoomRotation headRotation;
protected RoomRotation headRotation;
@Setter
private boolean canWalk;
protected boolean canWalk;
@Setter
private boolean canRotate;
protected boolean canRotate;
@Setter
private boolean isTeleporting;
protected boolean isTeleporting;
@Setter
private boolean cmdSitEnabled = false;
protected boolean cmdSitEnabled = false;
@Setter
private boolean cmdStandEnabled = false;
protected boolean cmdStandEnabled = false;
@Setter
private boolean cmdLayEnabled = false;
protected boolean cmdLayEnabled = false;
@Setter
private boolean isSwimming = false;
protected boolean isSwimming = false;
@Setter
private boolean cmdFastWalkEnabled;
protected boolean cmdFastWalkEnabled;
@Setter
private boolean temporalFastWalkEnabled;
private final ConcurrentHashMap<RoomUnitStatus, String> statuses;
protected boolean temporalFastWalkEnabled;
protected final ConcurrentHashMap<RoomUnitStatus, String> statuses;
@Setter
private boolean statusUpdateNeeded;
protected boolean statusUpdateNeeded;
@Setter
private boolean isWiredTeleporting = false;
protected boolean isWiredTeleporting = false;
@Setter
private boolean isLeavingTeleporter = false;
private final THashMap<String, Object> cacheable;
protected boolean isLeavingTeleporter = false;
protected final THashMap<String, Object> cacheable;
@Setter
private boolean isKicked;
protected boolean isKicked;
@Setter
private int kickCount = 0;
protected int kickCount = 0;
@Setter
private boolean inRoom;
protected boolean inRoom;
@Setter
@Accessors(chain = true)
private boolean invisible = false;
protected boolean invisible = false;
@Setter
private boolean canLeaveRoomByDoor = true;
protected boolean canLeaveRoomByDoor = true;
@Setter
private int walkTimeOut;
private int previousEffectId;
private int previousEffectEndTimestamp;
private int timeInRoom;
private RoomRightLevels rightsLevel = RoomRightLevels.NONE;
private final THashSet<Integer> overridableTiles;
protected int walkTimeOut;
protected int timeInRoom;
protected RoomRightLevels rightsLevel = RoomRightLevels.NONE;
protected final THashSet<Integer> overridableTiles;
public RoomUnit() {
this.virtualId = 0;
@ -103,10 +103,6 @@ public abstract class RoomUnit extends RoomEntity {
this.walkTimeOut = Emulator.getIntUnixTimestamp();
this.timeInRoom = 0;
//RoomAvatar
this.previousEffectId = 0;
this.previousEffectEndTimestamp = -1;
//RoomHabbo
this.isKicked = false;
this.overridableTiles = new THashSet<>();
@ -170,7 +166,7 @@ public abstract class RoomUnit extends RoomEntity {
if (this.room != null) {
Bot bot = this.room.getRoomUnitManager().getRoomBotById(getVirtualId());
if (bot != null) {
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
}
}
@ -243,7 +239,7 @@ public abstract class RoomUnit extends RoomEntity {
boolean hasValidLayout = hasValidRoom && this.room.getLayout() != null;
boolean hasValidTargetPosition = this.targetPosition != null;
boolean isTargetPositionWalkable = hasValidTargetPosition && this.targetPosition.isWalkable();
boolean canSitOrLayAtTarget = hasValidTargetPosition && hasValidRoom && this.room.canSitOrLayAt(this.targetPosition.getX(), this.targetPosition.getY());
boolean canSitOrLayAtTarget = hasValidTargetPosition && hasValidRoom && this.room.canSitOrLayAt(this.targetPosition);
boolean canOverrideTile = hasValidTargetPosition && this.canOverrideTile(this.targetPosition);
if (hasValidLayout && (isTargetPositionWalkable || canSitOrLayAtTarget || canOverrideTile)) {
@ -496,7 +492,7 @@ public abstract class RoomUnit extends RoomEntity {
this.setCurrentZ(this.getNextZ());
}
if(!this.path.isEmpty()) {
if(this.path != null && !this.path.isEmpty()) {
RoomTile next = this.path.poll();
if(this.path.size() > 1 && (this.cmdFastWalkEnabled || this.temporalFastWalkEnabled)) {
@ -570,8 +566,18 @@ public abstract class RoomUnit extends RoomEntity {
double heightDifference = tile.getStackHeight() - this.currentZ;
//TODO Why bots are not being detected?
boolean areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile);
if(this instanceof RoomAvatar roomAvatar && roomAvatar.isRiding()) {
areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile, roomAvatar.getRidingPet().getRoomUnit());
}
if(this instanceof RoomPet roomPet) {
if(roomPet.getUnit() instanceof RideablePet rideablePet && rideablePet.hasRider()) {
areRoomUnitsAtTile = this.room.getRoomUnitManager().areRoomUnitsAt(tile, rideablePet.getRider().getRoomUnit());
}
}
boolean isAboveMaximumStepHeight = (!RoomLayout.ALLOW_FALLING && heightDifference < -RoomLayout.MAXIMUM_STEP_HEIGHT);
boolean isOpenTileAboveMaxHeight = (tile.getState() == RoomTileState.OPEN && heightDifference > RoomLayout.MAXIMUM_STEP_HEIGHT);
boolean isTileBlocked = tile.getState().equals(RoomTileState.BLOCKED) || tile.getState().equals(RoomTileState.INVALID);
@ -579,16 +585,15 @@ public abstract class RoomUnit extends RoomEntity {
if(isTileBlocked || isAboveMaximumStepHeight || isOpenTileAboveMaxHeight) {
return false;
} else {
if(this.room.getRoomInfo().isAllowWalkthrough()) {
if(areRoomUnitsAtTile && !this.targetPosition.equals(tile)) {
if(areRoomUnitsAtTile && this.targetPosition.equals(tile)) {
this.stopWalking();
return false;
}
} else {
if(areRoomUnitsAtTile) {
if(areRoomUnitsAtTile && !this.room.getRoomInfo().isAllowWalkthrough()) {
return false;
}
}
}
RoomItem item = this.room.getRoomItemManager().getTopItemAt(tile);
@ -606,8 +611,6 @@ public abstract class RoomUnit extends RoomEntity {
this.canRotate = true;
this.cmdFastWalkEnabled = false;
this.clearStatuses();
this.previousEffectId = 0;
this.previousEffectEndTimestamp = -1;
this.isKicked = false;
this.cacheable.clear();
}

View File

@ -26,7 +26,7 @@ import java.util.List;
@Getter
@Setter
@Accessors(chain = true)
public class RoomAvatar extends RoomUnit {
public abstract class RoomAvatar extends RoomUnit {
protected RideablePet ridingPet;
protected boolean rideLocked;
protected DanceType danceType;
@ -91,8 +91,6 @@ public class RoomAvatar extends RoomUnit {
this.ridingPet.setRider(null);
this.ridingPet.setTask(PetTasks.FREE);
this.ridingPet = null;
this.giveEffect(0, -1);
this.setCurrentZ(this.ridingPet.getRoomUnit().getCurrentZ());
this.stopWalking();
@ -102,6 +100,8 @@ public class RoomAvatar extends RoomUnit {
this.instantUpdate();
this.ridingPet.getRoomUnit().instantUpdate();
this.ridingPet = null;
List<RoomTile> availableTiles = isRemoving ? new ArrayList<>() : this.room.getLayout().getWalkableTilesAround(this.getCurrentPosition());
RoomTile tile = availableTiles.isEmpty() ? this.getCurrentPosition() : availableTiles.get(0);
@ -184,6 +184,7 @@ public class RoomAvatar extends RoomUnit {
super.clear();
this.ridingPet = null;
this.rideLocked = false;
this.danceType = DanceType.NONE;
this.handItem = 0;
this.handItemTimestamp = 0;

View File

@ -1,10 +1,26 @@
package com.eu.habbo.habbohotel.rooms.entities.units.types;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.rooms.RoomChatMessage;
import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUserAction;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.WiredTriggerType;
import com.eu.habbo.messages.outgoing.rooms.users.ChatMessageComposer;
import com.eu.habbo.messages.outgoing.rooms.users.ExpressionMessageComposer;
import com.eu.habbo.plugin.Event;
import com.eu.habbo.plugin.events.bots.BotTalkEvent;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Getter
@Setter
@Accessors(chain = true)
public class RoomBot extends RoomAvatar {
private Bot unit;
@ -14,9 +30,67 @@ public class RoomBot extends RoomAvatar {
@Override
public void cycle() {
if(this.room.isAllowBotsWalk() && this.unit.canWalk()) {
if (!this.isWalking()) {
if (this.getWalkTimeOut() < Emulator.getIntUnixTimestamp() && this.unit.getFollowingHabboId() == 0) {
this.walkTo(Emulator.getConfig().getBoolean("hotel.bot.limit.walking.distance", true) ? this.getRoom().getLayout().getRandomWalkableTilesAround(this, this.currentPosition, this.getRoom(), Emulator.getConfig().getInt("hotel.bot.limit.walking.distance.radius", 5)) : this.getRoom().getRandomWalkableTile());
int timeOut = Emulator.getRandom().nextInt(20) * 2;
this.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp());
}
}
}
boolean hasChatLines = !this.unit.getChatLines().isEmpty();
boolean hasAutoChatEnabled = this.unit.isChatAuto();
boolean chatTimeOutPassed = Emulator.getIntUnixTimestamp() >= this.unit.getChatTimeOut();
if (hasChatLines && chatTimeOutPassed && hasAutoChatEnabled) {
if(this.unit.isChatRandom()) {
this.unit.setLastChatIndex((short) Emulator.getRandom().nextInt(this.unit.getChatLines().size()));
} else if(this.unit.getLastChatIndex() == this.unit.getChatLines().size() - 1) {
this.unit.resetLastChatIndex();
} else {
this.unit.incrementLastChatIndex();
}
if (this.unit.getLastChatIndex() >= this.unit.getChatLines().size()) {
this.unit.resetLastChatIndex();
}
String message = this.unit.getChatLines().get(this.unit.getLastChatIndex())
.replace(Emulator.getTexts().getValue("wired.variable.owner", "%owner%"), this.getRoom().getRoomInfo().getOwnerInfo().getUsername())
.replace(Emulator.getTexts().getValue("wired.variable.item_count", "%item_count%"), String.valueOf(this.getRoom().getRoomItemManager().getCurrentItems().size()))
.replace(Emulator.getTexts().getValue("wired.variable.name", "%name%"), this.unit.getName())
.replace(Emulator.getTexts().getValue("wired.variable.roomname", "%roomname%"), this.getRoom().getRoomInfo().getName())
.replace(Emulator.getTexts().getValue("wired.variable.user_count", "%user_count%"), String.valueOf(this.getRoom().getRoomUnitManager().getRoomHabbosCount()));
if(!WiredHandler.handle(WiredTriggerType.SAY_SOMETHING, this, room, new Object[]{ message })) {
this.talk(message);
}
this.unit.setChatTimeOut(Emulator.getIntUnixTimestamp() + this.unit.getChatDelay());
}
super.cycle();
}
public void talk(String message) {
if (Emulator.getPluginManager().isRegistered(BotTalkEvent.class, false)) {
Event event = new BotTalkEvent(this.unit, message);
Emulator.getPluginManager().fireEvent(event);
if (event.isCancelled())
return;
}
this.unit.setChatTimestamp(Emulator.getIntUnixTimestamp());
this.room.botChat(new ChatMessageComposer(new RoomChatMessage(message, this, RoomChatMessageBubbles.getBubble(this.unit.getBubbleId()))).compose());
if (message.equals("o/") || message.equals("_o/")) {
this.room.sendComposer(new ExpressionMessageComposer(this, RoomUserAction.WAVE).compose());
}
}
public RoomUnitType getRoomUnitType() {
return RoomUnitType.BOT;
}

View File

@ -2,7 +2,6 @@ package com.eu.habbo.habbohotel.rooms.entities.units.types;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.RideablePet;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.habbohotel.rooms.RoomUnitStatus;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnit;
import com.eu.habbo.habbohotel.rooms.entities.units.RoomUnitType;
@ -19,13 +18,15 @@ public class RoomPet extends RoomUnit {
@Override
public void cycle() {
if (!this.handleRider()) {
super.cycle();
}
}
public boolean handleRider(Pet pet, Room room) {
public boolean handleRider() {
Habbo rider = null;
if (pet instanceof RideablePet rideablePet) {
if (this.unit instanceof RideablePet rideablePet) {
rider = rideablePet.getRider();
}
@ -38,7 +39,7 @@ public class RoomPet extends RoomUnit {
this.removeStatus(RoomUnitStatus.MOVE);
}
if (!this.getCurrentPosition().equals(rider.getRoomUnit().getCurrentPosition())) {
if (!this.currentPosition.equals(rider.getRoomUnit().getCurrentPosition())) {
this.addStatus(RoomUnitStatus.MOVE, rider.getRoomUnit().getCurrentPosition().getX() + "," + rider.getRoomUnit().getCurrentPosition().getY() + "," + (rider.getRoomUnit().getCurrentPosition().getStackHeight()));
this.setCurrentPosition(rider.getRoomUnit().getCurrentPosition());
this.setCurrentZ(rider.getRoomUnit().getCurrentPosition().getStackHeight());

View File

@ -0,0 +1,10 @@
package com.eu.habbo.habbohotel.units.type;
import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.messages.ISerialize;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public abstract class Avatar extends Unit implements ISerialize {}

View File

@ -5,6 +5,7 @@ import com.eu.habbo.habbohotel.achievements.AchievementManager;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.catalog.ClothItem;
import com.eu.habbo.habbohotel.gameclients.GameClient;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.messenger.Messenger;
import com.eu.habbo.habbohotel.permissions.Permission;
import com.eu.habbo.habbohotel.pets.Pet;
@ -14,8 +15,9 @@ import com.eu.habbo.habbohotel.rooms.RoomChatMessageBubbles;
import com.eu.habbo.habbohotel.rooms.RoomUserAction;
import com.eu.habbo.habbohotel.rooms.entities.items.RoomItem;
import com.eu.habbo.habbohotel.rooms.entities.units.types.RoomHabbo;
import com.eu.habbo.habbohotel.units.Unit;
import com.eu.habbo.habbohotel.units.type.Avatar;
import com.eu.habbo.habbohotel.users.inventory.BadgesComponent;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.generic.alerts.*;
import com.eu.habbo.messages.outgoing.inventory.*;
import com.eu.habbo.messages.outgoing.rooms.FloodControlMessageComposer;
@ -40,7 +42,7 @@ import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class Habbo extends Unit implements Runnable {
public class Habbo extends Avatar implements Runnable {
@Getter
private RoomHabbo roomUnit;
@Getter
@ -345,7 +347,7 @@ public class Habbo extends Unit implements Runnable {
public void deleteBot(Bot bot) {
this.removeBot(bot);
bot.getRoom().getRoomUnitManager().removeBot(bot);
bot.getRoomUnit().getRoom().getRoomUnitManager().removeBot(bot);
Emulator.getGameEnvironment().getBotManager().deleteBot(bot);
}
@ -467,4 +469,34 @@ public class Habbo extends Unit implements Runnable {
.flatMap(c -> Arrays.stream(c).boxed())
.collect(Collectors.toSet());
}
@Override
public void serialize(ServerMessage message) {
message.appendInt(this.habboInfo.getId());
message.appendString(this.habboInfo.getUsername());
message.appendString(this.habboInfo.getMotto());
message.appendString(this.habboInfo.getLook());
message.appendInt(this.roomUnit.getVirtualId());
message.appendInt(this.roomUnit.getCurrentPosition().getX());
message.appendInt(this.roomUnit.getCurrentPosition().getY());
message.appendString(String.valueOf(this.roomUnit.getCurrentZ()));
message.appendInt(this.roomUnit.getBodyRotation().getValue());
message.appendInt(1);
message.appendString(this.habboInfo.getGender().name().toUpperCase());
message.appendInt(this.habboStats.getGuild() != 0 ? this.habboStats.getGuild() : -1);
message.appendInt(this.habboStats.getGuild() != 0 ? 1 : -1);
String name = "";
if (this.habboStats.getGuild() != 0) {
Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.habboStats.getGuild());
if (g != null)
name = g.getName();
}
message.appendString(name);
message.appendString("");
message.appendInt(this.habboStats.getAchievementScore());
message.appendBoolean(true);
}
}

View File

@ -25,7 +25,7 @@ public class BotsComponent {
private void loadBots(Habbo habbo) {
synchronized (this.bots) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON users.id = bots.user_id WHERE user_id = ? AND room_id = 0 ORDER BY id ASC")) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("SELECT users.username AS owner_name, bots.* FROM bots INNER JOIN users ON users.id = bots.owner_id WHERE owner_id = ? AND room_id = 0 ORDER BY id ASC")) {
statement.setInt(1, habbo.getHabboInfo().getId());
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
@ -60,7 +60,7 @@ public class BotsComponent {
public void dispose() {
synchronized (this.bots) {
for (Map.Entry<Integer, Bot> map : this.bots.entrySet()) {
if (map.getValue().needsUpdate()) {
if (map.getValue().isSqlUpdateNeeded()) {
Emulator.getThreading().run(map.getValue());
}
}

View File

@ -2,7 +2,6 @@ package com.eu.habbo.messages.incoming.navigator;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.modtool.ScripterManager;
import com.eu.habbo.habbohotel.pets.Pet;
import com.eu.habbo.habbohotel.pets.RideablePet;
@ -29,8 +28,17 @@ public class DeleteRoomEvent extends MessageHandler {
Room room = Emulator.getGameEnvironment().getRoomManager().getActiveRoomById(roomId);
if (room != null) {
if (room.getRoomInfo().isRoomOwner(this.client.getHabbo())) {
if(room == null) {
return;
}
if(!room.getRoomInfo().isRoomOwner(this.client.getHabbo())) {
String message = Emulator.getTexts().getValue("scripter.warning.room.delete").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", room.getRoomInfo().getName()).replace("%roomowner%", room.getRoomInfo().getOwnerInfo().getUsername());
ScripterManager.scripterDetected(this.client, message);
log.info(message);
return;
}
if (room.getRoomInfo().getId() == this.client.getHabbo().getHabboInfo().getHomeRoom()) {
return;
}
@ -66,15 +74,14 @@ public class DeleteRoomEvent extends MessageHandler {
}
}
if (room.getRoomInfo().getGuild().getId() > 0) {
Guild guild = Emulator.getGameEnvironment().getGuildManager().getGuild(room.getRoomInfo().getGuild().getId());
if (guild != null) {
Emulator.getGameEnvironment().getGuildManager().deleteGuild(guild);
}
if (room.getRoomInfo().hasGuild()) {
Emulator.getGameEnvironment().getGuildManager().deleteGuild(room.getRoomInfo().getGuild());
}
room.preventUnloading = false;
room.getRoomRightsManager().removeAllRights();
room.getRoomWordFilterManager().removeAllWords();
room.dispose();
Emulator.getGameEnvironment().getRoomManager().uncacheRoom(room);
@ -91,30 +98,12 @@ public class DeleteRoomEvent extends MessageHandler {
}
}
room.dispose();
try (PreparedStatement rights = connection.prepareStatement("DELETE FROM room_rights WHERE room_id = ?")) {
rights.setInt(1, roomId);
rights.execute();
}
try (PreparedStatement votes = connection.prepareStatement("DELETE FROM room_votes WHERE room_id = ?")) {
votes.setInt(1, roomId);
votes.execute();
}
try (PreparedStatement filter = connection.prepareStatement("DELETE FROM room_wordfilter WHERE room_id = ?")) {
filter.setInt(1, roomId);
filter.execute();
}
} catch (SQLException e) {
log.error("Caught SQL exception", e);
}
} else {
String message = Emulator.getTexts().getValue("scripter.warning.room.delete").replace("%username%", this.client.getHabbo().getHabboInfo().getUsername()).replace("%roomname%", room.getRoomInfo().getName()).replace("%roomowner%", room.getRoomInfo().getOwnerInfo().getUsername());
ScripterManager.scripterDetected(this.client, message);
log.info(message);
}
}
}
}

View File

@ -26,13 +26,14 @@ public class CommandBotEvent extends MessageHandler {
if (room == null)
return;
if (room.getRoomInfo().getOwnerInfo().getId() == this.client.getHabbo().getHabboInfo().getId() || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) {
if (room.getRoomInfo().isRoomOwner(this.client.getHabbo()) || this.client.getHabbo().hasPermissionRight(Permission.ACC_ANYROOMOWNER)) {
int botId = this.packet.readInt();
Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId));
if (bot == null)
if (bot == null) {
return;
}
int settingId = this.packet.readInt();
@ -45,10 +46,11 @@ public class CommandBotEvent extends MessageHandler {
Emulator.getPluginManager().fireEvent(lookEvent);
if (lookEvent.isCancelled())
break;
bot.setFigure(lookEvent.getNewLook());
bot.setGender(lookEvent.getGender());
bot.setEffect(lookEvent.getEffect(), -1);
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
}
case 2 -> {
String messageString = this.packet.readString();
@ -102,16 +104,16 @@ public class CommandBotEvent extends MessageHandler {
bot.setChatDelay((short) chatEvent.getChatDelay());
bot.clearChat();
bot.addChatLines(chat);
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
}
case 3 -> {
bot.setCanWalk(!bot.canWalk());
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
}
case 4 -> {
bot.getRoomUnit().setDanceType(DanceType.values()[(bot.getRoomUnit().getDanceType().getType() + 1) % DanceType.values().length]);
room.sendComposer(new DanceMessageComposer(bot.getRoomUnit()).compose());
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
}
case 5 -> {
String name = this.packet.readString();
@ -128,7 +130,7 @@ public class CommandBotEvent extends MessageHandler {
break;
bot.setName(nameEvent.getName());
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
room.sendComposer(new UserNameChangedMessageComposer(bot.getRoomUnit().getVirtualId(), bot.getRoomUnit().getVirtualId(), nameEvent.getName()).compose());
}
}
@ -140,12 +142,12 @@ public class CommandBotEvent extends MessageHandler {
String motto = this.packet.readString();
if (motto.length() > Emulator.getConfig().getInt("motto.max_length", 38)) break;
bot.setMotto(motto);
bot.needsUpdate(true);
bot.setSqlUpdateNeeded(true);
room.sendComposer(new RoomUsersComposer(bot).compose());
}
}
if (bot.needsUpdate()) {
if (bot.isSqlUpdateNeeded()) {
Emulator.getThreading().run(bot);
}
}

View File

@ -1,6 +1,6 @@
package com.eu.habbo.messages.incoming.rooms.bots;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.rooms.Room;
import com.eu.habbo.messages.incoming.MessageHandler;
@ -11,9 +11,18 @@ public class RemoveBotFromFlatEvent extends MessageHandler {
public void handle() {
Room room = this.client.getHabbo().getRoomUnit().getRoom();
if (room == null)
if (room == null) {
return;
}
Emulator.getGameEnvironment().getBotManager().pickUpBot(this.packet.readInt(), this.client.getHabbo(), room);
int botId = this.packet.readInt();
Bot bot = room.getRoomUnitManager().getRoomBotById(Math.abs(botId));
if(bot == null) {
return;
}
room.getRoomUnitManager().pickUpBot(bot, this.client.getHabbo());
}
}

View File

@ -1,153 +1,36 @@
package com.eu.habbo.messages.outgoing.rooms.users;
import com.eu.habbo.Emulator;
import com.eu.habbo.habbohotel.bots.Bot;
import com.eu.habbo.habbohotel.guilds.Guild;
import com.eu.habbo.habbohotel.users.Habbo;
import com.eu.habbo.habbohotel.units.type.Avatar;
import com.eu.habbo.messages.ServerMessage;
import com.eu.habbo.messages.outgoing.MessageComposer;
import com.eu.habbo.messages.outgoing.Outgoing;
import java.util.Collection;
import java.util.List;
public class RoomUsersComposer extends MessageComposer {
private Habbo habbo;
private Collection<Habbo> habbos;
private Bot bot;
private Collection<Bot> bots;
private final Collection<? extends Avatar> avatars;
public RoomUsersComposer(Habbo habbo) {
this.habbo = habbo;
public RoomUsersComposer(Avatar avatar) {
this.avatars = List.of(avatar);
}
public RoomUsersComposer(Collection<Habbo> habbos) {
this.habbos = habbos;
}
public RoomUsersComposer(Bot bot) {
this.bot = bot;
}
public RoomUsersComposer(Collection<Bot> bots, boolean isBot) {
this.bots = bots;
public RoomUsersComposer(Collection<? extends Avatar> avatars) {
this.avatars = avatars;
}
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.usersComposer);
if (this.habbo != null) {
this.response.appendInt(1);
this.response.appendInt(this.habbo.getHabboInfo().getId());
this.response.appendString(this.habbo.getHabboInfo().getUsername());
this.response.appendString(this.habbo.getHabboInfo().getMotto());
this.response.appendString(this.habbo.getHabboInfo().getLook());
this.response.appendInt(this.habbo.getRoomUnit().getVirtualId()); //Room Unit ID
this.response.appendInt(this.habbo.getRoomUnit().getCurrentPosition().getX());
this.response.appendInt(this.habbo.getRoomUnit().getCurrentPosition().getY());
this.response.appendString(this.habbo.getRoomUnit().getCurrentZ() + "");
this.response.appendInt(this.habbo.getRoomUnit().getBodyRotation().getValue());
this.response.appendInt(1);
this.response.appendString(this.habbo.getHabboInfo().getGender().name().toUpperCase());
this.response.appendInt(this.habbo.getHabboStats().getGuild() != 0 ? this.habbo.getHabboStats().getGuild() : -1);
this.response.appendInt(this.habbo.getHabboStats().getGuild() != 0 ? 1 : -1);
if (this.avatars != null) {
this.response.appendInt(this.avatars.size());
for (Avatar avatar : this.avatars) {
if (avatar != null) {
avatar.serialize(this.response);
}
}
}
String name = "";
if (this.habbo.getHabboStats().getGuild() != 0) {
Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(this.habbo.getHabboStats().getGuild());
if (g != null)
name = g.getName();
}
this.response.appendString(name);
this.response.appendString("");
this.response.appendInt(this.habbo.getHabboStats().getAchievementScore());
this.response.appendBoolean(true);
} else if (this.habbos != null) {
this.response.appendInt(this.habbos.size());
for (Habbo habbo : this.habbos) {
if (habbo != null) {
this.response.appendInt(habbo.getHabboInfo().getId());
this.response.appendString(habbo.getHabboInfo().getUsername());
this.response.appendString(habbo.getHabboInfo().getMotto());
this.response.appendString(habbo.getHabboInfo().getLook());
this.response.appendInt(habbo.getRoomUnit().getVirtualId()); //Room Unit ID
this.response.appendInt(habbo.getRoomUnit().getCurrentPosition().getX());
this.response.appendInt(habbo.getRoomUnit().getCurrentPosition().getY());
this.response.appendString(habbo.getRoomUnit().getCurrentZ() + "");
this.response.appendInt(habbo.getRoomUnit().getBodyRotation().getValue());
this.response.appendInt(1);
this.response.appendString(habbo.getHabboInfo().getGender().name().toUpperCase());
this.response.appendInt(habbo.getHabboStats().getGuild() != 0 ? habbo.getHabboStats().getGuild() : -1);
this.response.appendInt(habbo.getHabboStats().getGuild() != 0 ? habbo.getHabboStats().getGuild() : -1);
String name = "";
if (habbo.getHabboStats().getGuild() != 0) {
Guild g = Emulator.getGameEnvironment().getGuildManager().getGuild(habbo.getHabboStats().getGuild());
if (g != null)
name = g.getName();
}
this.response.appendString(name);
this.response.appendString("");
this.response.appendInt(habbo.getHabboStats().getAchievementScore());
this.response.appendBoolean(true);
}
}
} else if (this.bot != null) {
this.response.appendInt(1);
this.response.appendInt(-this.bot.getId());
this.response.appendString(this.bot.getName());
this.response.appendString(this.bot.getMotto());
this.response.appendString(this.bot.getFigure());
this.response.appendInt(this.bot.getRoomUnit().getVirtualId());
this.response.appendInt(this.bot.getRoomUnit().getCurrentPosition().getX());
this.response.appendInt(this.bot.getRoomUnit().getCurrentPosition().getY());
this.response.appendString(this.bot.getRoomUnit().getCurrentZ() + "");
this.response.appendInt(this.bot.getRoomUnit().getBodyRotation().getValue());
this.response.appendInt(4);
this.response.appendString(this.bot.getGender().name().toUpperCase());
this.response.appendInt(this.bot.getOwnerId());
this.response.appendString(this.bot.getOwnerName());
this.response.appendInt(10);
this.response.appendShort(0);
this.response.appendShort(1);
this.response.appendShort(2);
this.response.appendShort(3);
this.response.appendShort(4);
this.response.appendShort(5);
this.response.appendShort(6);
this.response.appendShort(7);
this.response.appendShort(8);
this.response.appendShort(9);
} else if (this.bots != null) {
this.response.appendInt(this.bots.size());
for (Bot bot : this.bots) {
this.response.appendInt(-bot.getId());
this.response.appendString(bot.getName());
this.response.appendString(bot.getMotto());
this.response.appendString(bot.getFigure());
this.response.appendInt(bot.getRoomUnit().getVirtualId());
this.response.appendInt(bot.getRoomUnit().getCurrentPosition().getX());
this.response.appendInt(bot.getRoomUnit().getCurrentPosition().getY());
this.response.appendString(bot.getRoomUnit().getCurrentZ() + "");
this.response.appendInt(bot.getRoomUnit().getBodyRotation().getValue());
this.response.appendInt(4);
this.response.appendString(bot.getGender().name().toUpperCase());
this.response.appendInt(bot.getOwnerId());
this.response.appendString(bot.getOwnerName());
this.response.appendInt(10);
this.response.appendShort(0);
this.response.appendShort(1);
this.response.appendShort(2);
this.response.appendShort(3);
this.response.appendShort(4);
this.response.appendShort(5);
this.response.appendShort(6);
this.response.appendShort(7);
this.response.appendShort(8);
this.response.appendShort(9);
}
}
return this.response;
}
}

View File

@ -13,7 +13,7 @@ public class UserRemoveMessageComposer extends MessageComposer {
@Override
protected ServerMessage composeInternal() {
this.response.init(Outgoing.userRemoveMessageComposer);
this.response.appendString(this.roomUnit.getVirtualId() + "");
this.response.appendString(String.valueOf(this.roomUnit.getVirtualId()));
return this.response;
}
}

View File

@ -54,8 +54,8 @@ public class RoomUnitTeleport implements Runnable {
this.roomUnit.setStatusUpdateNeeded(true);
roomUnit.setWiredTeleporting(false);
this.room.updateHabbosAt(newLocation);
this.room.updateBotsAt(newLocation.getX(), newLocation.getY());
this.room.getRoomUnitManager().updateHabbosAt(newLocation);
this.room.getRoomUnitManager().updateBotsAt(newLocation);
topItem = room.getRoomItemManager().getTopItemAt(x, y);
if (topItem != null && roomUnit.getCurrentPosition().equals(room.getLayout().getTile((short) x, (short) y))) {