mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-26 16:30:52 +01:00
Make bots act more like Habbo's bots
This commit is contained in:
parent
2897b24917
commit
2a6ddaee2b
@ -15,3 +15,7 @@ ALTER TABLE `pet_commands_data` CHANGE `cost_happyness` `cost_happiness` int(11)
|
||||
ALTER TABLE `users_pets` CHANGE `happyness` `happiness` int(11) NOT NULL DEFAULT '100';
|
||||
|
||||
UPDATE `items_base` SET `interaction_type` = 'spinning_bottle', `interaction_modes_count` = '8' WHERE `item_name` = 'bottle';
|
||||
|
||||
--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');
|
||||
|
@ -54,7 +54,6 @@ public class Bot implements Runnable {
|
||||
|
||||
private transient boolean canWalk = true;
|
||||
|
||||
|
||||
private boolean needsUpdate;
|
||||
|
||||
|
||||
@ -114,7 +113,6 @@ public class Bot implements Runnable {
|
||||
this.type = bot.getType();
|
||||
this.effect = bot.getEffect();
|
||||
this.bubble = bot.getBubbleId();
|
||||
|
||||
this.needsUpdate = false;
|
||||
}
|
||||
|
||||
@ -137,30 +135,27 @@ 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 = ?, 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");
|
||||
statement.setInt(7, this.roomUnit == null ? 0 : this.roomUnit.getBodyRotation().getValue());
|
||||
statement.setInt(8, this.roomUnit == null ? 0 : this.roomUnit.getDanceType().getType());
|
||||
statement.setString(9, 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(10, text.toString());
|
||||
statement.setString(11, this.chatAuto ? "1" : "0");
|
||||
statement.setString(12, this.chatRandom ? "1" : "0");
|
||||
statement.setInt(13, this.chatDelay);
|
||||
statement.setInt(14, this.effect);
|
||||
statement.setInt(15, this.bubble);
|
||||
statement.setInt(16, this.id);
|
||||
statement.execute();
|
||||
this.needsUpdate = false;
|
||||
} catch (SQLException e) {
|
||||
@ -174,7 +169,8 @@ 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(Emulator.getConfig().getBoolean("hotel.bot.limit.walking.distance", true) ? this.room.getLayout().getRandomWalkableTilesAround(this.roomUnit, this.room.getLayout().getTile(this.roomUnit.getBotStartLocation().getX(), this.roomUnit.getBotStartLocation().getY()), this.room, Emulator.getConfig().getInt("hotel.bot.limit.walking.distance.radius", 5)) : this.room.getRandomWalkableTile());
|
||||
|
||||
int timeOut = Emulator.getRandom().nextInt(20) * 2;
|
||||
this.roomUnit.setWalkTimeOut((timeOut < 10 ? 5 : timeOut) + Emulator.getIntUnixTimestamp());
|
||||
}
|
||||
@ -484,4 +480,35 @@ 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) {
|
||||
log.error("Caught SQL exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -131,7 +131,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());
|
||||
|
@ -7,9 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import java.awt.*;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@ -590,6 +588,30 @@ public class RoomLayout {
|
||||
return availableTiles;
|
||||
}
|
||||
|
||||
public RoomTile getRandomWalkableTilesAround(RoomUnit roomUnit, RoomTile tile, Room room, int radius) {
|
||||
if(!this.tileExists(tile.getX(), tile.getY())) {
|
||||
tile = this.getTile(roomUnit.getX(), roomUnit.getY());
|
||||
room.getBot(roomUnit).needsUpdate(true);
|
||||
}
|
||||
|
||||
List<RoomTile> newTiles = new ArrayList<>();
|
||||
|
||||
int minX = Math.max(0, tile.getX() - radius);
|
||||
int minY = Math.max(0, tile.getY() - radius);
|
||||
int maxX = Math.min(room.getLayout().getMapSizeX(), tile.getX() + radius);
|
||||
int maxY = Math.min(room.getLayout().getMapSizeY(), tile.getY() + radius);
|
||||
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
RoomTile tile2 = room.getLayout().getTile((short) x, (short) y);
|
||||
if (tile2 != null && tile.getState() != RoomTileState.BLOCKED && tile.getState() != RoomTileState.INVALID)
|
||||
newTiles.add(tile2);
|
||||
}
|
||||
}
|
||||
Collections.shuffle(newTiles);
|
||||
return newTiles.get(0);
|
||||
}
|
||||
|
||||
public boolean fitsOnMap(RoomTile tile, int width, int length, int rotation) {
|
||||
if (tile != null) {
|
||||
if (rotation == 0 || rotation == 4) {
|
||||
|
@ -79,6 +79,9 @@ public class RoomUnit {
|
||||
@Getter
|
||||
private RoomTile startLocation;
|
||||
@Getter
|
||||
@Setter
|
||||
private RoomTile botStartLocation;
|
||||
@Getter
|
||||
private RoomTile previousLocation;
|
||||
@Getter
|
||||
@Setter
|
||||
@ -501,6 +504,7 @@ public class RoomUnit {
|
||||
setPreviousLocation(location);
|
||||
setCurrentLocation(location);
|
||||
this.goalLocation = location;
|
||||
this.botStartLocation = location;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user