Tabs to spaces

This commit is contained in:
dginovker 2019-06-08 21:14:05 -04:00
parent 2a22cfa827
commit 05896914fb
13 changed files with 334 additions and 182 deletions

View file

@ -80,7 +80,7 @@ public final class CS2Mapping {
if (mapping.map == null) {
continue;
}
bw.append("Script - " + i + " [");
bw.append("ScriptAPI - " + i + " [");
for (int index : mapping.map.keySet()) {
bw.append(mapping.map.get(index) + ": " + index + " ");
}

View file

@ -336,19 +336,19 @@ public final class CharacterDesign {
return val;
}
//Male head ids : Script - 701 [0: 1 1: 2 2: 3 3: 4 4: 5 5: 6 6: 7 7: 8 8: 9 91: 10 92: 11 93: 12 94: 13 95: 14 96: 15 97: 16 261: 17 262: 18 263: 19 264: 20 265: 21 266: 22 267: 23 268: 24 ]
//Female head ids: Script - 689 [45: 1 46: 2 47: 3 48: 4 49: 5 50: 6 51: 7 52: 8 53: 9 54: 10 135: 11 136: 12 137: 13 138: 14 139: 15 140: 16 141: 17 142: 318 143: 19 144: 20 145: 21 146: 22 269: 23 270: 24 271: 25 272: 26 273: 27 274: 28 275: 29 276: 30 277: 31 278: 32 279: 33 280: 34 ]
//Male jaw ids: Script - 703 [10: 1 11: 2 12: 3 13: 4 14: 5 15: 6 16: 7 17: 8 98: 9 99: 10 100: 11 101: 12 102: 13 103: 14 104: 15 305: 16 306: 17 307: 18 308: 19 ]
//Male torso ids: Script - 1128 [19: 1 20: 2 21: 3 22: 4 23: 5 24: 6 25: 7 111: 8 112: 9 113: 10 114: 11 115: 12 116: 13 ]
//Female torso ids: Script - 1129 [57: 1 58: 2 59: 3 60: 4 153: 5 154: 6 155: 7 156: 8 157: 9 158: 10 ]
//Male arm ids: Script - 1130 [27: 1 28: 2 29: 3 30: 4 31: 5 105: 6 106: 7 107: 8 108: 9 109: 10 110: 11 ]
//Female arm ids: Script - 1131 [62: 1 63: 2 64: 3 65: 4 147: 5 148: 6 149: 7 150: 8 151: 9 152: 10 ]
//Male hand ids: Script - 1132 [34: 1 84: 2 117: 3 118: 4 119: 5 120: 6 121: 7 122: 8 123: 9 124: 10 125: 11 126: 12 ]
//Female hand ids: Script - 1133 [68: 1 127: 2 159: 3 160: 4 161: 5 162: 6 163: 7 164: 8 165: 9 166: 10 167: 11 168: 12 ]
//Male leg ids: Script - 1134 [37: 1 38: 2 39: 3 40: 4 85: 5 86: 6 87: 7 88: 8 89: 9 90: 10 ]
//Female leg ids: Script - 1135 [71: 1 72: 2 73: 3 74: 4 75: 5 76: 6 77: 7 128: 8 129: 9 130: 10 131: 11 132: 12 133: 13 134: 14 ]
//Male feet ids: Script - 1136 [43: 1 ]
//Female feet ids: Script - 1137 [80: 1 ]
//Male head ids : ScriptAPI - 701 [0: 1 1: 2 2: 3 3: 4 4: 5 5: 6 6: 7 7: 8 8: 9 91: 10 92: 11 93: 12 94: 13 95: 14 96: 15 97: 16 261: 17 262: 18 263: 19 264: 20 265: 21 266: 22 267: 23 268: 24 ]
//Female head ids: ScriptAPI - 689 [45: 1 46: 2 47: 3 48: 4 49: 5 50: 6 51: 7 52: 8 53: 9 54: 10 135: 11 136: 12 137: 13 138: 14 139: 15 140: 16 141: 17 142: 318 143: 19 144: 20 145: 21 146: 22 269: 23 270: 24 271: 25 272: 26 273: 27 274: 28 275: 29 276: 30 277: 31 278: 32 279: 33 280: 34 ]
//Male jaw ids: ScriptAPI - 703 [10: 1 11: 2 12: 3 13: 4 14: 5 15: 6 16: 7 17: 8 98: 9 99: 10 100: 11 101: 12 102: 13 103: 14 104: 15 305: 16 306: 17 307: 18 308: 19 ]
//Male torso ids: ScriptAPI - 1128 [19: 1 20: 2 21: 3 22: 4 23: 5 24: 6 25: 7 111: 8 112: 9 113: 10 114: 11 115: 12 116: 13 ]
//Female torso ids: ScriptAPI - 1129 [57: 1 58: 2 59: 3 60: 4 153: 5 154: 6 155: 7 156: 8 157: 9 158: 10 ]
//Male arm ids: ScriptAPI - 1130 [27: 1 28: 2 29: 3 30: 4 31: 5 105: 6 106: 7 107: 8 108: 9 109: 10 110: 11 ]
//Female arm ids: ScriptAPI - 1131 [62: 1 63: 2 64: 3 65: 4 147: 5 148: 6 149: 7 150: 8 151: 9 152: 10 ]
//Male hand ids: ScriptAPI - 1132 [34: 1 84: 2 117: 3 118: 4 119: 5 120: 6 121: 7 122: 8 123: 9 124: 10 125: 11 126: 12 ]
//Female hand ids: ScriptAPI - 1133 [68: 1 127: 2 159: 3 160: 4 161: 5 162: 6 163: 7 164: 8 165: 9 166: 10 167: 11 168: 12 ]
//Male leg ids: ScriptAPI - 1134 [37: 1 38: 2 39: 3 40: 4 85: 5 86: 6 87: 7 88: 8 89: 9 90: 10 ]
//Female leg ids: ScriptAPI - 1135 [71: 1 72: 2 73: 3 74: 4 75: 5 76: 6 77: 7 128: 8 129: 9 130: 10 131: 11 132: 12 133: 13 134: 14 ]
//Male feet ids: ScriptAPI - 1136 [43: 1 ]
//Female feet ids: ScriptAPI - 1137 [80: 1 ]
}

View file

@ -5,9 +5,13 @@ import org.crandor.game.interaction.DestinationFlag;
import org.crandor.game.interaction.MovementPulse;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.ai.general.ScriptAPI;
import org.crandor.game.node.entity.player.ai.general.scriptrepository.Script;
import org.crandor.game.node.entity.player.info.PlayerDetails;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.map.Location;
import org.crandor.tools.StringUtils;
import plugin.skill.thieving.ThievingOptionPlugin;
import java.util.HashMap;
import java.util.Map;
@ -52,7 +56,12 @@ public class AIPlayer extends Player {
* The player controlling this AIP.
*/
private Player controler;
/**
* The scriptAPI the bot will perform
*/
private ScriptAPI scriptAPI;
/**
* Constructs a new {@code AIPlayer} {@code Object}.
* @param name The name of the AIP.
@ -66,6 +75,7 @@ public class AIPlayer extends Player {
super.getDetails().setSession(ArtificialSession.getSingleton());
this.username = StringUtils.formatDisplayName(name);
this.uid = currentUID++;
this.scriptAPI = new ScriptAPI();
}
@Override
@ -133,6 +143,26 @@ public class AIPlayer extends Player {
this.setAttribute("dead", true);
}
public void runScript(Script script)
{
if (!this.getPulseManager().hasPulseRunning())
{
getPulseManager().run(new Pulse() {
@Override
public boolean pulse() {
return false;
}
@Override
public boolean update() {
super.update();
script.runLoop();
return true;
}
});
}
}
/**
* Gets the UID.
* @return the UID.
@ -192,5 +222,4 @@ public class AIPlayer extends Player {
public void setControler(Player controler) {
this.controler = controler;
}
}

View file

@ -0,0 +1,35 @@
package org.crandor.game.node.entity.player.ai.general;
import org.crandor.game.node.entity.player.ai.AIPBuilder;
import org.crandor.game.node.entity.player.ai.AIPlayer;
import org.crandor.game.node.entity.player.ai.general.scriptrepository.Script;
import org.crandor.game.system.task.Pulse;
import org.crandor.game.world.GameWorld;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.repository.Repository;
public class GeneralBotCreator {
public GeneralBotCreator(String botName, Location loc, Script botScript)
{
AIPlayer bot = AIPBuilder.create(botName, loc);
Repository.getPlayers().add(bot);
bot.init();
botScript.setPlayer(bot);
GameWorld.submit(new Pulse(1, bot) {
int ticks = 0;
@Override
public boolean pulse() {
if (ticks ++ == 5000)
{
AIPlayer.deregister(bot.getUid());
return true;
}
bot.runScript(botScript);
return false;
}
});
}
}

View file

@ -0,0 +1,49 @@
package org.crandor.game.node.entity.player.ai.general;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.object.GameObject;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.map.RegionPlane;
import org.crandor.game.world.map.path.Pathfinder;
public class ScriptAPI {
public double distance(Location l1, Location l2) {
return Pathfinder.find(l1, l2).getPoints().size();
}
public NPC getNearestNPC(Location loc, String npcName) {
NPC npc = null;
double minDistance = Double.MAX_VALUE;
for (RegionPlane p : RegionManager.forId(loc.getRegionId()).getPlanes()) {
for (NPC n : p.getNpcs()) {
if (n != null) {
if (n.getName().equals(npcName) && distance(loc, n.getLocation()) < minDistance) {
npc = n;
}
}
}
}
System.out.println("Returning " + npc.getName());
return npc;
}
public GameObject getNearestGameObject(Location loc, int objectId) {
GameObject nearestObject = null;
double minDistance = Double.MAX_VALUE;
for (GameObject[] o : RegionManager.forId(loc.getRegionId()).getPlanes()[0].getObjects()) {
for (GameObject obj : o) {
if (obj != null) {
if (distance(loc, obj.getLocation()) < minDistance) {
nearestObject = obj;
}
}
}
}
return nearestObject;
}
}

View file

@ -0,0 +1,12 @@
package org.crandor.game.node.entity.player.ai.general.scriptrepository;
import org.crandor.game.node.entity.player.Player;
import plugin.skill.thieving.ThievingOptionPlugin;
public class ManThiever extends Script {
@Override
public void runLoop() {
new ThievingOptionPlugin().handle(me, scriptAPI.getNearestNPC(me.getLocation(), "Man"), "pickpocket");
}
}

View file

@ -0,0 +1,16 @@
package org.crandor.game.node.entity.player.ai.general.scriptrepository;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.ai.general.ScriptAPI;
public abstract class Script {
public Player me;
public ScriptAPI scriptAPI = new ScriptAPI();
public void setPlayer(Player me)
{
this.me = me;
}
public abstract void runLoop();
}

View file

@ -137,7 +137,7 @@ public final class ScriptCompiler {
line = rawScript.poll();
if (line == null) {
br.close();
throw new ScriptException("Script " + file.getName() + " is empty!", -1);
throw new ScriptException("ScriptAPI " + file.getName() + " is empty!", -1);
}
br.close();
ScriptContext context = parseScript(line, rawScript, new ScriptEntry(null, null, null, false), null);

View file

@ -1,7 +1,7 @@
package org.crandor.game.system.script;
/**
* Script context, this can be a condition or an instruction.
* ScriptAPI context, this can be a condition or an instruction.
* @author Emperor
*/
public abstract class ScriptContext {

View file

@ -7,7 +7,7 @@ import org.crandor.game.system.script.ScriptContext;
import java.util.Arrays;
/**
* Script condition for checking if a player has an item in the inventory.
* ScriptAPI condition for checking if a player has an item in the inventory.
* @author Emperor
*/
public final class InvItemCondition extends ScriptContext {

View file

@ -4,7 +4,7 @@ import org.crandor.game.node.entity.player.Player;
import org.crandor.game.system.script.ScriptContext;
/**
* Script condition for checking if a player has warrior guild tokens.
* ScriptAPI condition for checking if a player has warrior guild tokens.
* @author 'Vexia
*/
public final class WGuildTokenCondition extends ScriptContext {

View file

@ -4,6 +4,8 @@ import org.crandor.game.interaction.Interaction;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.ai.AIPBuilder;
import org.crandor.game.node.entity.player.ai.AIPlayer;
import org.crandor.game.node.entity.player.ai.general.GeneralBotCreator;
import org.crandor.game.node.entity.player.ai.general.scriptrepository.ManThiever;
import org.crandor.game.node.entity.player.ai.pvp.PVPAIPActions;
import org.crandor.game.node.entity.player.ai.pvp.PVPAIPBuilderUtils;
import org.crandor.game.node.entity.player.ai.resource.ResourceAIPActions;
@ -25,173 +27,182 @@ import java.util.List;
/**
* Handles the AIPlayer commands.
* These commands are for bots
* @author Emperor
*/
@InitializablePlugin
public final class AIPCommandPlugin extends CommandPlugin {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
link(CommandSet.ADMINISTRATOR);
return this;
}
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
link(CommandSet.ADMINISTRATOR);
return this;
}
@Override
public boolean parse(final Player player, String name, String[] args) {
List<AIPlayer> legion = player.getAttribute("aip_legion");
switch (name) {
case "desaip":
player.removeAttribute("aip_select");
return true;
case "sellegion":
if (legion != null && !legion.isEmpty()) {
player.setAttribute("aip_select", legion.get(0));
}
return true;
case "regroup":
Player last = player;
if (legion != null && !legion.isEmpty()) {
for (AIPlayer p : legion) {
p.follow(last);
last = p;
}
}
player.removeAttribute("aip_select");
return true;
case "clearlegion":
if (legion != null && !legion.isEmpty()) {
for (AIPlayer p : legion) {
AIPlayer.deregister(p.getUid());
}
legion.clear();
}
player.removeAttribute("aip_select");
player.removeAttribute("aip_legion");
return true;
case "clearaips":
for (Player p : Repository.getPlayers()) {
if (p.isArtificial()) {
p.clear();
}
}
return true;
case "aip":
name = args.length < 2 ? player.getName() : args[1];
AIPlayer p = AIPBuilder.copy(player, name, player.getLocation().transform(0, 1, 0));
Repository.getPlayers().add(p);
p.init();
Interaction.sendOption(player, 7, "Control");
return true;
case "legion":
int size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (legion == null) {
player.setAttribute("aip_legion", legion = new ArrayList<>());
}
Interaction.sendOption(player, 7, "Control");
boolean joinClan = player.getCommunication().getClan() != null && !player.getCommunication().getClan().isDefault();
String message = player.getName().equals("ethan") ? "The Dark Army marches again!" : null; // Add
// your
// own
// message
for (int i = 0; i < size; i++) {
final AIPlayer aip = AIPBuilder.copy(player, last.getLocation().transform(0, 1, 0));
Repository.getPlayers().add(aip);
aip.init();
if (legion.isEmpty()) {
aip.setAttribute("aip_legion", legion);
}
legion.add(aip);
final Player l = last;
if (joinClan) {
if (player.getCommunication().getClan().enter(aip)) {
aip.getCommunication().setClan(player.getCommunication().getClan());
}
if (player.getCommunication().getClan().getClanWar() != null) {
player.getCommunication().getClan().getClanWar().fireEvent("join", aip);
}
}
GameWorld.submit(new Pulse(1) {
@Override
public boolean pulse() {
aip.follow(l);
return true;
}
});
if (message != null) {
aip.sendChat("The Dark Army marches again!");
}
last = aip;
}
return true;
case "pvplegion":
size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (PVPAIPActions.pvp_players == null) {
player.setAttribute("aip_legion", PVPAIPActions.pvp_players = new ArrayList<>());
}
for (int i = 0; i < size; i++) {
String aipName = PVPAIPBuilderUtils.names[i];
final AIPlayer aip = AIPBuilder.create(aipName, generateLocation(player));
aip.setControler(player);
aip.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
Repository.getPlayers().add(aip);
aip.init();
PVPAIPBuilderUtils.generateClass(aip);
if (PVPAIPActions.pvp_players.isEmpty()) {
aip.setAttribute("aip_legion", PVPAIPActions.pvp_players);
}
PVPAIPActions.pvp_players.add(aip);
last = aip;
}
return true;
case "resourcelegion":
size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (ResourceAIPActions.resource_players == null) {
player.setAttribute("aip_legion", ResourceAIPActions.resource_players = new ArrayList<>());
}
for (int i = 0; i < size; i++) {
String aipName = PVPAIPBuilderUtils.names[i];
final AIPlayer aip = AIPBuilder.create(aipName, generateLocation(player));
aip.setControler(player);
aip.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
Repository.getPlayers().add(aip);
aip.init();
PVPAIPBuilderUtils.generateClass(aip);
if (ResourceAIPActions.resource_players .isEmpty()) {
aip.setAttribute("aip_legion", ResourceAIPActions.resource_players );
}
ResourceAIPActions.resource_players.add(aip);
last = aip;
}
return true;
case "syncresource":
ResourceAIPActions.syncBotThread(player);
break;
case "pvpfight":
PVPAIPActions.syncBotThread(player);
return true;
}
return false;
}
private Location generateLocation(Player player) {
Location random_location = player.getLocation().transform(RandomFunction.random(-15, 15), RandomFunction.random(-15, 15), 0);
if (!RegionManager.isTeleportPermitted(random_location)) {
return generateLocation(player);
}
if (!Pathfinder.find(player, random_location, false, Pathfinder.DUMB).isSuccessful()) {
return generateLocation(player);
}
if (RegionManager.getObject(random_location) != null) {
return generateLocation(player);
}
return random_location;
}
@Override
public boolean parse(final Player player, String name, String[] args) {
List<AIPlayer> legion = player.getAttribute("aip_legion");
switch (name) {
case "desaip":
player.removeAttribute("aip_select");
return true;
case "sellegion":
if (legion != null && !legion.isEmpty()) {
player.setAttribute("aip_select", legion.get(0));
}
return true;
case "regroup":
Player last = player;
if (legion != null && !legion.isEmpty()) {
for (AIPlayer p : legion) {
p.follow(last);
last = p;
}
}
player.removeAttribute("aip_select");
return true;
case "clearlegion":
if (legion != null && !legion.isEmpty()) {
for (AIPlayer p : legion) {
AIPlayer.deregister(p.getUid());
}
legion.clear();
}
player.removeAttribute("aip_select");
player.removeAttribute("aip_legion");
return true;
case "clearaips":
for (Player p : Repository.getPlayers()) {
if (p.isArtificial()) {
p.clear();
}
}
return true;
case "aip":
name = args.length < 2 ? player.getName() : args[1];
AIPlayer p = AIPBuilder.copy(player, name, player.getLocation().transform(0, 1, 0));
Repository.getPlayers().add(p);
p.init();
Interaction.sendOption(player, 7, "Control");
return true;
case "legion":
int size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (legion == null) {
player.setAttribute("aip_legion", legion = new ArrayList<>());
}
Interaction.sendOption(player, 7, "Control");
boolean joinClan = player.getCommunication().getClan() != null && !player.getCommunication().getClan().isDefault();
String message = player.getName().equals("ethan") ? "The Dark Army marches again!" : null; // Add
// your
// own
// message
for (int i = 0; i < size; i++) {
final AIPlayer aip = AIPBuilder.copy(player, last.getLocation().transform(0, 1, 0));
Repository.getPlayers().add(aip);
aip.init();
if (legion.isEmpty()) {
aip.setAttribute("aip_legion", legion);
}
legion.add(aip);
final Player l = last;
if (joinClan) {
if (player.getCommunication().getClan().enter(aip)) {
aip.getCommunication().setClan(player.getCommunication().getClan());
}
if (player.getCommunication().getClan().getClanWar() != null) {
player.getCommunication().getClan().getClanWar().fireEvent("join", aip);
}
}
GameWorld.submit(new Pulse(1) {
@Override
public boolean pulse() {
aip.follow(l);
return true;
}
});
if (message != null) {
aip.sendChat("The Dark Army marches again!");
}
last = aip;
}
return true;
case "pvplegion":
size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (PVPAIPActions.pvp_players == null) {
player.setAttribute("aip_legion", PVPAIPActions.pvp_players = new ArrayList<>());
}
for (int i = 0; i < size; i++) {
String aipName = PVPAIPBuilderUtils.names[i];
final AIPlayer aip = AIPBuilder.create(aipName, generateLocation(player));
aip.setControler(player);
aip.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
Repository.getPlayers().add(aip);
aip.init();
PVPAIPBuilderUtils.generateClass(aip);
if (PVPAIPActions.pvp_players.isEmpty()) {
aip.setAttribute("aip_legion", PVPAIPActions.pvp_players);
}
PVPAIPActions.pvp_players.add(aip);
last = aip;
}
return true;
case "resourcelegion":
size = args.length < 2 ? 10 : Integer.parseInt(args[1]);
last = player;
if (ResourceAIPActions.resource_players == null) {
player.setAttribute("aip_legion", ResourceAIPActions.resource_players = new ArrayList<>());
}
for (int i = 0; i < size; i++) {
String aipName = PVPAIPBuilderUtils.names[i];
final AIPlayer aip = AIPBuilder.create(aipName, generateLocation(player));
aip.setControler(player);
aip.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
Repository.getPlayers().add(aip);
aip.init();
PVPAIPBuilderUtils.generateClass(aip);
if (ResourceAIPActions.resource_players .isEmpty()) {
aip.setAttribute("aip_legion", ResourceAIPActions.resource_players );
}
ResourceAIPActions.resource_players.add(aip);
last = aip;
}
return true;
case "syncresource":
ResourceAIPActions.syncBotThread(player);
break;
case "pvpfight":
PVPAIPActions.syncBotThread(player);
return true;
/*
Start regular bots
*/
case "manthiev":
new GeneralBotCreator("Bot", player.getLocation(), new ManThiever());
break;
}
return false;
}
private Location generateLocation(Player player) {
Location random_location = player.getLocation().transform(RandomFunction.random(-15, 15), RandomFunction.random(-15, 15), 0);
if (!RegionManager.isTeleportPermitted(random_location)) {
return generateLocation(player);
}
if (!Pathfinder.find(player, random_location, false, Pathfinder.DUMB).isSuccessful()) {
return generateLocation(player);
}
if (RegionManager.getObject(random_location) != null) {
return generateLocation(player);
}
return random_location;
}
}