mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-07 08:39:07 +00:00
initial bots
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -595,10 +595,6 @@ public class Client extends Player {
|
|||||||
// PlayerSave.saveGame(this);
|
// PlayerSave.saveGame(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String[][] data = {
|
|
||||||
{"Andrew", "Andrew1"},
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
getPlayerAssistant().loginScreen();
|
getPlayerAssistant().loginScreen();
|
||||||
@@ -606,15 +602,6 @@ public class Client extends Player {
|
|||||||
logout();
|
logout();
|
||||||
return;
|
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) {
|
synchronized (this) {
|
||||||
outStream.createFrame(249);
|
outStream.createFrame(249);
|
||||||
outStream.writeByteA(membership ? 1 : 0);
|
outStream.writeByteA(membership ? 1 : 0);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package redone.net.packets.impl;
|
|||||||
import redone.Connection;
|
import redone.Connection;
|
||||||
import redone.Constants;
|
import redone.Constants;
|
||||||
import redone.Server;
|
import redone.Server;
|
||||||
|
import redone.game.bots.BotHandler;
|
||||||
import redone.game.items.ItemAssistant;
|
import redone.game.items.ItemAssistant;
|
||||||
import redone.game.npcs.NpcHandler;
|
import redone.game.npcs.NpcHandler;
|
||||||
import redone.game.players.*;
|
import redone.game.players.*;
|
||||||
@@ -92,6 +93,12 @@ public class Commands implements PacketType {
|
|||||||
player.getActionSender().sendMessage("There is currently " + PlayerHandler.getPlayerCount() + " player online.");
|
player.getActionSender().sendMessage("There is currently " + PlayerHandler.getPlayerCount() + " player online.");
|
||||||
}
|
}
|
||||||
break;
|
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":
|
case "wealth":
|
||||||
int totalWealth = player.getPlayerAssistant().totalGold();
|
int totalWealth = player.getPlayerAssistant().totalGold();
|
||||||
player.getActionSender().sendMessage("You currently have " + totalWealth + "gp.");
|
player.getActionSender().sendMessage("You currently have " + totalWealth + "gp.");
|
||||||
|
|||||||
Reference in New Issue
Block a user