Improvement/bot limit walking distance

This commit is contained in:
Yordi 2024-10-17 16:03:56 +00:00 committed by ArpyAge
parent 0a6355996a
commit 908b5605b3
5 changed files with 90 additions and 17 deletions

View File

@ -0,0 +1,3 @@
--New bot walking settings
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.bot.limit.walking.distance', '1');
INSERT INTO `emulator_settings` (`key`, `value`) VALUES ('hotel.bot.limit.walking.distance.radius', '5');

View File

@ -27,6 +27,8 @@ public class Bot implements Runnable {
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(";");
public static boolean BOT_LIMIT_WALKING_DISTANCE = true;
public static int BOT_WALKING_DISTANCE_RADIUS = 5;
private final ArrayList<String> chatLines;
private transient int id;
@ -137,30 +139,26 @@ public class Bot implements Runnable {
@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 = ?, x = ?, y = ?, z = ?, rot = ?, dance = ?, freeroam = ?, chat_lines = ?, chat_auto = ?, chat_random = ?, chat_delay = ?, effect = ?, bubble_id = ? WHERE id = ?")) {
try (Connection connection = Emulator.getDatabase().getDataSource().getConnection(); PreparedStatement statement = connection.prepareStatement("UPDATE bots SET name = ?, motto = ?, figure = ?, gender = ?, user_id = ?, room_id = ?, 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.getId());
statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getX());
statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getY());
statement.setDouble(9, this.roomUnit == null ? 0 : this.roomUnit.getZ());
statement.setInt(10, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue());
statement.setInt(11, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType());
statement.setString(12, this.canWalk ? "1" : "0");
statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType());
statement.setString(8, 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.bubble);
statement.setInt(19, this.id);
statement.setString(9, text.toString());
statement.setString(10, this.chatAuto ? "1" : "0");
statement.setString(11, this.chatRandom ? "1" : "0");
statement.setInt(12, this.chatDelay);
statement.setInt(13, this.effect);
statement.setInt(14, this.bubble);
statement.setInt(15, this.id);
statement.execute();
this.needsUpdate = false;
} catch (SQLException e) {
@ -174,7 +172,15 @@ public class Bot implements Runnable {
if (allowBotsWalk && this.canWalk) {
if (!this.roomUnit.isWalking()) {
if (this.roomUnit.getWalkTimeOut() < Emulator.getIntUnixTimestamp() && this.followingHabboId == 0) {
this.roomUnit.setGoalLocation(this.room.getRandomWalkableTile());
this.roomUnit.setGoalLocation(
Bot.BOT_LIMIT_WALKING_DISTANCE
? this.room.getRandomWalkableTilesAround(
this.getRoomUnit(),
this.room.getLayout().getTile(this.roomUnit.getX(), this.roomUnit.getY()),
Bot.BOT_WALKING_DISTANCE_RADIUS)
: this.room.getRandomWalkableTile()
);
int timeOut = Emulator.getRandom().nextInt(20) * 2;
this.roomUnit.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp());
}
@ -497,4 +503,36 @@ public class Bot implements Runnable {
this.roomUnit.statusUpdate(true);
}
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.getId());
statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getX());
statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getY());
statement.setDouble(9, this.roomUnit == null ? 0 : this.roomUnit.getZ());
statement.setInt(10, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue());
statement.setInt(11, this.roomUnit == null ? 0 : this.roomUnit.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.bubble);
statement.setInt(19, this.id);
statement.execute();
} catch (SQLException e) {
LOGGER.error("Caught SQL exception", e);
}
}
}

View File

@ -136,7 +136,7 @@ public class BotManager {
roomUnit.setCanWalk(room.isAllowBotsWalk());
bot.setRoomUnit(roomUnit);
bot.setRoom(room);
bot.needsUpdate(true);
bot.onPlaceUpdate();
room.addBot(bot);
Emulator.getThreading().run(bot);
room.sendComposer(new RoomUsersComposer(bot).compose());

View File

@ -3849,6 +3849,37 @@ public class Room implements Comparable<Room>, ISerialize, Runnable {
return null;
}
public RoomTile getRandomWalkableTilesAround(RoomUnit roomUnit, RoomTile tile, int radius) {
if (!layout.tileExists(tile.x, tile.y)) {
tile = layout.getTile(roomUnit.getX(), roomUnit.getY());
this.getBot(roomUnit).needsUpdate(true);
}
List<RoomTile> walkableTiles = new ArrayList<>();
int minX = Math.max(0, tile.x - radius);
int minY = Math.max(0, tile.y - radius);
int maxX = Math.min(this.getLayout().getMapSizeX() - 1, tile.x + radius);
int maxY = Math.min(this.getLayout().getMapSizeY() - 1, tile.y + radius);
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
RoomTile candidateTile = this.getLayout().getTile((short) x, (short) y);
if (candidateTile != null && candidateTile.getState() != RoomTileState.BLOCKED && candidateTile.getState() != RoomTileState.INVALID) {
walkableTiles.add(candidateTile);
}
}
}
if (walkableTiles.isEmpty()) {
return tile;
}
Collections.shuffle(walkableTiles);
return walkableTiles.get(0);
}
public Habbo getHabbo(String username) {
for (Habbo habbo : this.getHabbos()) {
if (habbo.getHabboInfo().getUsername().equalsIgnoreCase(username))

View File

@ -25,7 +25,6 @@ import com.eu.habbo.habbohotel.users.clothingvalidation.ClothingValidationManage
import com.eu.habbo.habbohotel.users.HabboInventory;
import com.eu.habbo.habbohotel.users.HabboManager;
import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionHabboClub;
import com.eu.habbo.habbohotel.users.subscriptions.SubscriptionManager;
import com.eu.habbo.habbohotel.wired.WiredHandler;
import com.eu.habbo.habbohotel.wired.highscores.WiredHighscoreManager;
import com.eu.habbo.messages.PacketManager;
@ -100,6 +99,8 @@ public class PluginManager {
BotManager.MAXIMUM_NAME_LENGTH = Emulator.getConfig().getInt("hotel.bot.max.namelength");
BotManager.MAXIMUM_CHAT_SPEED = Emulator.getConfig().getInt("hotel.bot.max.chatdelay");
Bot.PLACEMENT_MESSAGES = Emulator.getConfig().getValue("hotel.bot.placement.messages", "Yo!;Hello I'm a real party animal!;Hello!").split(";");
Bot.BOT_LIMIT_WALKING_DISTANCE = Emulator.getConfig().getBoolean("hotel.bot.limit.walking.distance", true);
Bot.BOT_WALKING_DISTANCE_RADIUS = Emulator.getConfig().getInt("hotel.bot.limit.walking.distance.radius", 5);
HabboInventory.MAXIMUM_ITEMS = Emulator.getConfig().getInt("hotel.inventory.max.items");
Messenger.MAXIMUM_FRIENDS = Emulator.getConfig().getInt("hotel.users.max.friends", 300);