diff --git a/09HDscape-server/data/eco/grand_exchange_db.emp b/09HDscape-server/data/eco/grand_exchange_db.emp index dfacbcb3f..2b045145b 100644 Binary files a/09HDscape-server/data/eco/grand_exchange_db.emp and b/09HDscape-server/data/eco/grand_exchange_db.emp differ diff --git a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java index 23385fcb0..0ba12cbb0 100644 --- a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java +++ b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/AIPlayer.java @@ -57,11 +57,6 @@ public class AIPlayer extends Player { */ 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. @@ -75,7 +70,6 @@ public class AIPlayer extends Player { super.getDetails().setSession(ArtificialSession.getSingleton()); this.username = StringUtils.formatDisplayName(name); this.uid = currentUID++; - this.scriptAPI = new ScriptAPI(); } @Override @@ -143,26 +137,6 @@ 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. diff --git a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/GeneralBotCreator.java b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/GeneralBotCreator.java index 8311a6ecc..18f1e794a 100644 --- a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/GeneralBotCreator.java +++ b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/GeneralBotCreator.java @@ -3,6 +3,7 @@ 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.node.item.Item; import org.crandor.game.system.task.Pulse; import org.crandor.game.world.GameWorld; import org.crandor.game.world.map.Location; @@ -10,24 +11,27 @@ import org.crandor.game.world.repository.Repository; public class GeneralBotCreator { + //org/crandor/net/packet/in/InteractionPacket.java <<< This is a very useful class for learning to code bots public GeneralBotCreator(String botName, Location loc, Script botScript) { - AIPlayer bot = AIPBuilder.create(botName, loc); - Repository.getPlayers().add(bot); - bot.init(); - botScript.setPlayer(bot); + botScript.bot = AIPBuilder.create(botName, loc); + Repository.getPlayers().add(botScript.bot); + botScript.init(); - GameWorld.submit(new Pulse(1, bot) { + GameWorld.submit(new Pulse(1, botScript.bot) { int ticks = 0; @Override public boolean pulse() { if (ticks ++ == 5000) { - AIPlayer.deregister(bot.getUid()); + AIPlayer.deregister(botScript.bot.getUid()); return true; } - bot.runScript(botScript); + if (!botScript.bot.getPulseManager().hasPulseRunning()) + { + botScript.runLoop(); + } return false; } }); diff --git a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/ScriptAPI.java b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/ScriptAPI.java index f4e54af64..a0dcb17c2 100644 --- a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/ScriptAPI.java +++ b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/ScriptAPI.java @@ -1,34 +1,39 @@ package org.crandor.game.node.entity.player.ai.general; -import org.crandor.game.node.entity.npc.NPC; +import org.crandor.game.node.Node; 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(); + private Player bot; + + public ScriptAPI(Player bot) { + this.bot = bot; } - public NPC getNearestNPC(Location loc, String npcName) { - NPC npc = null; + public double distance(Node n1, Node n2) + { + return Math.sqrt(Math.pow(n1.getLocation().getX() - n2.getLocation().getX(), 2) + Math.pow(n2.getLocation().getY() - n1.getLocation().getY(), 2)); + } + + public Node getNearestNode(String entityName) + { + Node entity = 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; - } - } + for (Node e : RegionManager.forId(bot.getLocation().getRegionId()).getPlanes()[bot.getLocation().getZ()].getEntities()) + { + if (e != null && e.getName().equals(entityName) && distance(bot, e) < minDistance && !Pathfinder.find(bot, e).isMoveNear()) + { + entity = e; + minDistance = distance(bot, e); } } - System.out.println("Returning " + npc.getName()); - return npc; + return entity; } public GameObject getNearestGameObject(Location loc, int objectId) { @@ -37,7 +42,7 @@ public class ScriptAPI { for (GameObject[] o : RegionManager.forId(loc.getRegionId()).getPlanes()[0].getObjects()) { for (GameObject obj : o) { if (obj != null) { - if (distance(loc, obj.getLocation()) < minDistance) { + if (distance(loc, obj) < minDistance) { nearestObject = obj; } } diff --git a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/ManThiever.java b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/ManThiever.java index 2f3cdd986..7774743e8 100644 --- a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/ManThiever.java +++ b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/ManThiever.java @@ -1,12 +1,23 @@ package org.crandor.game.node.entity.player.ai.general.scriptrepository; -import org.crandor.game.node.entity.player.Player; -import plugin.skill.thieving.ThievingOptionPlugin; +import org.crandor.game.node.Node; +import org.crandor.game.node.item.Item; + +import java.util.Arrays; public class ManThiever extends Script { + public ManThiever() + { + this.equipment.addAll(Arrays.asList(new Item(1103), new Item(1139), new Item(1265))); + } @Override public void runLoop() { - new ThievingOptionPlugin().handle(me, scriptAPI.getNearestNPC(me.getLocation(), "Man"), "pickpocket"); + Node man = scriptAPI.getNearestNode("Man"); + + if (man != null) + { + man.getInteraction().handle(bot, man.getInteraction().get(2)); + } } } diff --git a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/Script.java b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/Script.java index 534575d34..ad649cd06 100644 --- a/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/Script.java +++ b/09HDscape-server/src/org/crandor/game/node/entity/player/ai/general/scriptrepository/Script.java @@ -1,15 +1,31 @@ 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.AIPlayer; import org.crandor.game.node.entity.player.ai.general.ScriptAPI; +import org.crandor.game.node.item.Item; + +import java.util.ArrayList; public abstract class Script { - public Player me; - public ScriptAPI scriptAPI = new ScriptAPI(); + public ScriptAPI scriptAPI; + public ArrayList inventory = new ArrayList<>(); + public ArrayList equipment = new ArrayList<>(); - public void setPlayer(Player me) + public AIPlayer bot; + + public void init() { - this.me = me; + bot.init(); + scriptAPI = new ScriptAPI(bot); + + for (Item i : inventory) + { + bot.getInventory().add(i); + } + for (Item i : equipment) + { + bot.getEquipment().add(i, true, false); + } } public abstract void runLoop(); diff --git a/09HDscape-server/src/org/crandor/game/world/map/RegionPlane.java b/09HDscape-server/src/org/crandor/game/world/map/RegionPlane.java index b87e7297c..aac3d6dda 100644 --- a/09HDscape-server/src/org/crandor/game/world/map/RegionPlane.java +++ b/09HDscape-server/src/org/crandor/game/world/map/RegionPlane.java @@ -1,5 +1,7 @@ package org.crandor.game.world.map; +import org.crandor.game.node.Node; +import org.crandor.game.node.entity.Entity; import org.crandor.game.node.entity.npc.NPC; import org.crandor.game.node.entity.player.Player; import org.crandor.game.node.item.GroundItem; @@ -13,6 +15,8 @@ import org.crandor.net.packet.context.BuildItemContext; import org.crandor.net.packet.out.ClearGroundItem; import org.crandor.net.packet.out.ConstructGroundItem; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -320,6 +324,17 @@ public final class RegionPlane { return npcs; } + public List getEntities() + { + List entities = new ArrayList<>(npcs); + for (GameObject[] o : getObjects()) + { + entities.addAll(Arrays.asList(o)); + } + + return entities; + } + /** * Gets the players. * @return The players. diff --git a/09HDscape-server/src/org/crandor/game/world/map/path/SmartPathfinder.java b/09HDscape-server/src/org/crandor/game/world/map/path/SmartPathfinder.java index f50ad3121..bcf74e024 100644 --- a/09HDscape-server/src/org/crandor/game/world/map/path/SmartPathfinder.java +++ b/09HDscape-server/src/org/crandor/game/world/map/path/SmartPathfinder.java @@ -2,6 +2,7 @@ package org.crandor.game.world.map.path; import org.crandor.game.world.map.Location; import org.crandor.game.world.map.Point; +import org.crandor.game.world.map.RegionManager; public final class SmartPathfinder extends Pathfinder { diff --git a/09HDscape-server/src/org/crandor/net/packet/in/InteractionPacket.java b/09HDscape-server/src/org/crandor/net/packet/in/InteractionPacket.java index bb19eebee..7826cc73f 100644 --- a/09HDscape-server/src/org/crandor/net/packet/in/InteractionPacket.java +++ b/09HDscape-server/src/org/crandor/net/packet/in/InteractionPacket.java @@ -234,7 +234,7 @@ public final class InteractionPacket implements IncomingPacket { /** * Handles player interaction. - * @param playerThe player interacting. + * @param player The player interacting. * @param optionIndex The option index. * @param index The target index. */ @@ -262,7 +262,7 @@ public final class InteractionPacket implements IncomingPacket { * @param player The player. * @param index The index of the reward. * @param itemId The item id. - * @param locationThe location of the item. + * @param location The location of the item. */ private static void handleGroundItemInteraction(final Player player, int index, int itemId, Location location) { final GroundItem item = GroundItemManager.get(itemId, location, player); diff --git a/09HDscape-server/src/plugin/command/AIPCommandPlugin.java b/09HDscape-server/src/plugin/command/AIPCommandPlugin.java index bbec35221..351956904 100644 --- a/09HDscape-server/src/plugin/command/AIPCommandPlugin.java +++ b/09HDscape-server/src/plugin/command/AIPCommandPlugin.java @@ -1,5 +1,6 @@ package plugin.command; +import org.crandor.game.container.Container; import org.crandor.game.interaction.Interaction; import org.crandor.game.node.entity.player.Player; import org.crandor.game.node.entity.player.ai.AIPBuilder; @@ -10,6 +11,7 @@ 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; import org.crandor.game.node.entity.player.link.appearance.Gender; +import org.crandor.game.node.item.Item; import org.crandor.game.system.command.CommandPlugin; import org.crandor.game.system.command.CommandSet; import org.crandor.game.system.task.Pulse; @@ -22,6 +24,7 @@ import org.crandor.plugin.InitializablePlugin; import org.crandor.plugin.Plugin; import org.crandor.tools.RandomFunction; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; diff --git a/09HDscape-server/src/plugin/interaction/inter/PlayerExamineInterfacePlugin.java b/09HDscape-server/src/plugin/interaction/inter/PlayerExamineInterfacePlugin.java index 9d7e0cf39..2dcf3cdac 100644 --- a/09HDscape-server/src/plugin/interaction/inter/PlayerExamineInterfacePlugin.java +++ b/09HDscape-server/src/plugin/interaction/inter/PlayerExamineInterfacePlugin.java @@ -50,14 +50,14 @@ public class PlayerExamineInterfacePlugin extends ComponentPlugin { player.getPacketDispatch().sendInterfaceConfig(component.getId(), 13, true); player.getInterfaceManager().open(component); player.getPacketDispatch().sendString("" + examined.getSavedData().getSpawnData().getTitle().getName() + " " + StringUtils.formatDisplayName(examined.getName()) + " - Combat Level: " + player.getProperties().getCurrentCombatLevel(), 31, 3); - player.getPacketDispatch().sendString("KDR -> ", 31, 9); - player.getPacketDispatch().sendString("Total Kills -> ", 31, 10); - player.getPacketDispatch().sendString("Total Deaths -> ", 31, 16); - player.getPacketDispatch().sendString("Killstreak -> ", 31, 19); - player.getPacketDispatch().sendString("" + examined.getSavedData().getSpawnData().getKdr(), 31, 11); - player.getPacketDispatch().sendString("" + examined.getSavedData().getSpawnData().getKills(), 31, 12); - player.getPacketDispatch().sendString("" + examined.getSavedData().getSpawnData().getDeaths(), 31, 17); - player.getPacketDispatch().sendString("" + examined.getSavedData().getSpawnData().getKillStreak(), 31, 20); + player.getPacketDispatch().sendString("Total Level -> ", 31, 9); + player.getPacketDispatch().sendString("Inventory items -> ", 31, 10); + player.getPacketDispatch().sendString("Inventory value -> ", 31, 16); + player.getPacketDispatch().sendString("Bank value-> ", 31, 19); + player.getPacketDispatch().sendString("" + examined.getSkills().getTotalLevel(), 31, 11); + player.getPacketDispatch().sendString("" + examined.getInventory().itemCount(), 31, 12); + player.getPacketDispatch().sendString("" + examined.getInventory().getWealth(), 31, 17); + player.getPacketDispatch().sendString("" + examined.getBank().getWealth(), 31, 20); player.getPacketDispatch().sendString("Close", 31, 5); } }