Merge pull request #3 from dginovker/development

Project setup easier and ready Bot classes
This commit is contained in:
Daniel Ginovker 2019-06-08 21:16:26 -04:00 committed by GitHub
commit 0f50c5d2bf
19 changed files with 182 additions and 23 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
production/*

9
.idea/09HDscape.iml generated
View file

@ -175,5 +175,14 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/09HDscape-server/data/libs/json-simple-1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

Binary file not shown.

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

@ -248,7 +248,6 @@ public class Player extends Entity {
*/
private final HunterManager hunterManager = new HunterManager(this);
/**
* The treasure trail manager.
*/
@ -274,7 +273,6 @@ public class Player extends Entity {
*/
private final IronmanManager ironmanManager = new IronmanManager(this);
/**
* The logout plugins.
*/

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

@ -1,6 +1,5 @@
package org.crandor.net.packet.out;
import com.oracle.jrockit.jfr.DataType;
import org.crandor.net.packet.IoBuffer;
import org.crandor.net.packet.OutgoingPacket;
import org.crandor.net.packet.context.CSConfigContext;

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,6 +27,7 @@ import java.util.List;
/**
* Handles the AIPlayer commands.
* These commands are for bots
* @author Emperor
*/
@InitializablePlugin
@ -176,6 +179,14 @@ public final class AIPCommandPlugin extends CommandPlugin {
case "pvpfight":
PVPAIPActions.syncBotThread(player);
return true;
/*
Start regular bots
*/
case "manthiev":
new GeneralBotCreator("Bot", player.getLocation(), new ManThiever());
break;
}
return false;
}