diff --git a/2006Redone Server/src/redone/game/bots/Bot.java b/2006Redone Server/src/redone/game/bots/Bot.java index 0aa47518..f6937e93 100644 --- a/2006Redone Server/src/redone/game/bots/Bot.java +++ b/2006Redone Server/src/redone/game/bots/Bot.java @@ -6,6 +6,7 @@ import redone.game.players.Client; import redone.game.players.Player; import redone.game.players.PlayerHandler; +import java.nio.charset.StandardCharsets; import java.util.Random; import java.util.Timer; import java.util.TimerTask; @@ -17,15 +18,15 @@ public class Bot { private Client botClient; static Timer timer = new Timer(); - public Bot(String username) { + public Bot(String username, int x, int y, int z) { botClient = new Client(null); botClient.playerName = username; botClient.playerName = username; botClient.playerName2 = botClient.playerName; + // TODO: randomize the bot passwords botClient.playerPass = "bot_password"; - botClient.saveCharacter = true; char first = username.charAt(0); botClient.properName = Character.toUpperCase(first) + username.substring(1, username.length()); @@ -33,8 +34,10 @@ public class Bot { botClient.saveCharacter = true; botClient.isActive = true; botClient.disconnected = false; - System.out.println(botClient.getPlayerAssistant().getTotalLevel()); Server.playerHandler.newPlayerClient(botClient); + + botClient.getPlayerAssistant().movePlayer(x, y, z); + loadPlayerInfo(botClient, username, "bot_password", false); new TradeChat().run(); } @@ -47,15 +50,24 @@ public class Bot { @Override public void run() { sendTradeChat(); - int delay = (15 + new Random().nextInt(25)) * 1000; + int delay = (5 + new Random().nextInt(15)) * 1000; timer.schedule(new TradeChat(), delay); } } public void sendTradeChat() { + botClient.forcedChat("Selling Rune Platebody 210k ea"); + /* + Real chat - Disabled for now, can't get it to function correctly + botClient.setChatTextColor(9); botClient.setChatTextEffects(2); - botClient.forcedChat("Selling Rune Platebody 210k ea - " + botClient.playerName + ""); + String message = "Selling Rune Platebody 210k ea - " + botClient.playerName; + botClient.setChatTextSize((byte) 29); + botClient.setChatText(message.getBytes(StandardCharsets.UTF_8)); + botClient.inStream.readBytes_reverseA(botClient.getChatText(), botClient.getChatTextSize(), 0); + botClient.setChatTextUpdateRequired(true); + */ } } diff --git a/2006Redone Server/src/redone/game/bots/BotHandler.java b/2006Redone Server/src/redone/game/bots/BotHandler.java index 29fe0fd3..4c2fa31e 100644 --- a/2006Redone Server/src/redone/game/bots/BotHandler.java +++ b/2006Redone Server/src/redone/game/bots/BotHandler.java @@ -1,7 +1,10 @@ package redone.game.bots; import redone.Constants; +import redone.game.players.Client; +import redone.game.players.Player; import redone.game.players.PlayerHandler; +import redone.util.Misc; import java.security.SecureRandom; import java.util.ArrayList; @@ -13,22 +16,45 @@ public class BotHandler static final List botList = new ArrayList<>(BotConstants.MAX_BOTS); static final Random random = new SecureRandom(); - public static void connectBots(int botCount) - { + public static Bot connectBot(String username, int x, int y, int z) { Bot bot; - for (int bots = 0; bots < botCount; bots++) - { - if (PlayerHandler.playerCount >= Constants.MAX_PLAYERS) - { - System.out.println("Bot could not be connected, server is full."); - return; - } - - final String botName = "bot" + random.nextInt(9999); - - bot = new Bot(botName); - botList.add(bot); + if (PlayerHandler.playerCount >= Constants.MAX_PLAYERS) { + System.out.println("Bot could not be connected, server is full."); + return null; } + bot = new Bot(username, x, y, z); + botList.add(bot); + return bot; } + + public static void playerShop(Client player){ + Bot playerShop = getPlayerShop(player); + + if (playerShop == null) { + String shopName = getShopName(player); + playerShop = connectBot(shopName, player.getX(), player.getY(), player.getH()); + } + + if (playerShop != null) + playerShop.getBotClient().getPlayerAssistant().movePlayer(player.getX(), player.getY(), player.getH()); + } + + private static String getShopName(Client player){ + return "♥" + player.playerName; + } + + private static Bot getPlayerShop(Client player){ + String shopName = getShopName(player); + for(Bot bot : botList) { + if(bot != null && bot.getBotClient() != null) { + Client botClient = bot.getBotClient(); + if(botClient.playerName.equalsIgnoreCase(shopName)) { + return bot; + } + } + } + return null; + } + } diff --git a/2006Redone Server/src/redone/game/players/Player.java b/2006Redone Server/src/redone/game/players/Player.java index 4e2e5a43..5bfbd325 100644 --- a/2006Redone Server/src/redone/game/players/Player.java +++ b/2006Redone Server/src/redone/game/players/Player.java @@ -116,7 +116,8 @@ public abstract class Player { teleOtherSlot = -1, tutorialProgress, Cookstage1 = 1, woodcuttingTree, smeltAmount, knightS, otherDirection, brightness = 3, recoilHits, droppedItem = -1, - spawnedHealers, cannonX = 0, cannonY = 0; + spawnedHealers, cannonX = 0, cannonY = 0, + playerShopId; public double playerEnergy = 100; @@ -1438,6 +1439,7 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY, private int chatTextEffects = 0; protected void appendPlayerChatText(Stream str) { + if (str == null) return; str.writeWordBigEndian(((getChatTextColor() & 0xFF) << 8) + (getChatTextEffects() & 0xFF)); str.writeByte(playerRights); str.writeByteC(getChatTextSize()); @@ -1454,7 +1456,8 @@ public boolean goodDistance(int objectX, int objectY, int playerX, int playerY, public String forcedText = "null"; public void appendForcedChat(Stream str) { - str.writeString(forcedText); + if (str != null) + str.writeString(forcedText); } /** diff --git a/2006Redone Server/src/redone/net/packets/impl/Commands.java b/2006Redone Server/src/redone/net/packets/impl/Commands.java index d9b4c726..d27075e4 100644 --- a/2006Redone Server/src/redone/net/packets/impl/Commands.java +++ b/2006Redone Server/src/redone/net/packets/impl/Commands.java @@ -93,11 +93,8 @@ public class Commands implements PacketType { player.getActionSender().sendMessage("There is currently " + PlayerHandler.getPlayerCount() + " player online."); } break; - case "bots": - if (arguments.length == 0) - player.getActionSender().sendMessage("Must have 1 argument: ::bots 5"); - else - BotHandler.connectBots(Integer.parseInt(arguments[0])); + case "shop": + BotHandler.playerShop(player); break; case "wealth": int totalWealth = player.getPlayerAssistant().totalGold();