initial bots

This commit is contained in:
RedSparr0w
2019-11-22 13:03:02 +13:00
parent 4b3bb7ade7
commit 447fc738d9
5 changed files with 86 additions and 13 deletions
@@ -0,0 +1,39 @@
package redone.game.bots;
import redone.Server;
import redone.game.players.Client;
import redone.game.players.Player;
import redone.game.players.PlayerHandler;
import static redone.game.players.PlayerSave.loadPlayerInfo;
public class Bot {
private Client botClient;
public Bot(String username) {
botClient = new Client(null, -1);
botClient.playerName = username;
botClient.playerName = username;
botClient.playerName2 = botClient.playerName;
botClient.playerPass = "bot_password";
botClient.saveCharacter = true;
char first = username.charAt(0);
botClient.properName = Character.toUpperCase(first) + username.substring(1, username.length());
botClient.saveFile = true;
botClient.saveCharacter = true;
botClient.isActive = true;
botClient.disconnected = false;
System.out.println(botClient.getPlayerAssistant().getTotalLevel());
Server.playerHandler.newPlayerClient(botClient);
loadPlayerInfo(botClient, username, "bot_password", false);
}
public Client getBotClient() {
return botClient;
}
}
@@ -0,0 +1,6 @@
package redone.game.bots;
public class BotConstants
{
public static final int MAX_BOTS = 100;
}
@@ -0,0 +1,34 @@
package redone.game.bots;
import redone.Constants;
import redone.game.players.PlayerHandler;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class BotHandler
{
static final List<Bot> botList = new ArrayList<>(BotConstants.MAX_BOTS);
static final Random random = new SecureRandom();
public static void connectBots(int botCount)
{
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) + random.nextInt(9999);
bot = new Bot(botName);
botList.add(bot);
}
}
}
@@ -594,10 +594,6 @@ public class Client extends Player {
super.destruct();
// PlayerSave.saveGame(this);
}
public static final String[][] data = {
{"Andrew", "Andrew1"},
};
@Override
public void initialize() {
@@ -606,15 +602,6 @@ public class Client extends Player {
logout();
return;
}
/*(for (int i = 0; i < data.length; i++) {
if (playerRights > 0) {
if (playerName != data[0][i]) {
Connection.addNameToBanList(playerName);
Connection.addNameToFile(playerName);
disconnected = true;
}
}
}*/
synchronized (this) {
outStream.createFrame(249);
outStream.writeByteA(membership ? 1 : 0);
@@ -3,6 +3,7 @@ package redone.net.packets.impl;
import redone.Connection;
import redone.Constants;
import redone.Server;
import redone.game.bots.BotHandler;
import redone.game.items.ItemAssistant;
import redone.game.npcs.NpcHandler;
import redone.game.players.*;
@@ -92,6 +93,12 @@ 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]));
break;
case "wealth":
int totalWealth = player.getPlayerAssistant().totalGold();
player.getActionSender().sendMessage("You currently have " + totalWealth + "gp.");