uhhh go brrr?

This commit is contained in:
Ceikry
2021-03-11 20:42:32 -06:00
parent 89d51b788b
commit 76c7b16108
2757 changed files with 0 additions and 0 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,107 @@
package plugin.ai;
import core.game.content.dialogue.DialoguePlugin;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.info.Rights;
/**
* Handles artificial intelligent player controls.
* @author Emperor
*/
public final class AIPControlDialogue extends DialoguePlugin {
/**
* The AIP to control.
*/
private AIPlayer aip;
/**
* Constructs a new {@code AIPControlDialogue} {@code Object}.
*/
public AIPControlDialogue() {
/*
* empty.
*/
}
/**
* Constructs a new {@code AIPControlDialogue} {@code Object}.
* @param player The player.
*/
public AIPControlDialogue(Player player) {
super(player);
}
@Override
public DialoguePlugin newInstance(Player player) {
return new AIPControlDialogue(player);
}
@Override
public boolean open(Object... args) {
if (player.getDetails().getRights() != Rights.ADMINISTRATOR) {
return false;
}
aip = (AIPlayer) args[0];
String select = "Select";
if (player.getAttribute("aip_select") == aip) {
select = "Deselect";
}
interpreter.sendOptions("AIP#" + aip.getUid() + " controls", select, "Settings", "Follow", "Stand-by", "Clear");
return true;
}
@Override
public boolean handle(int interfaceId, int buttonId) {
switch (interfaceId) {
case 234:
switch (buttonId) {
case 1:
if (player.getAttribute("aip_select") == aip) {
player.removeAttribute("aip_select");
break;
}
player.setAttribute("aip_select", aip);
break;
case 2:
interpreter.sendOptions("AIP#" + aip.getUid() + " settings", "Toggle run", "Toggle retaliate", "Toggle special attack");
return true;
case 3:
aip.follow(player);
player.removeAttribute("aip_select");
break;
case 4:
aip.getPulseManager().clear();
player.removeAttribute("aip_select");
break;
case 5:
AIPlayer.deregister(aip.getUid());
player.removeAttribute("aip_select");
break;
}
close();
return true;
case 230:
switch (buttonId) {
case 1:
aip.getSettings().toggleRun();
break;
case 2:
aip.getSettings().toggleRetaliating();
break;
case 3:
aip.getSettings().toggleSpecialBar();
break;
}
close();
return true;
}
return false;
}
@Override
public int[] getIds() {
return new int[0];
}
}
@@ -0,0 +1,615 @@
package plugin.ai;
import core.ServerConstants;
import core.game.container.impl.EquipmentContainer;
import core.game.interaction.DestinationFlag;
import core.game.interaction.MovementPulse;
import core.game.interaction.Option;
import core.game.interaction.OptionHandler;
import core.game.node.Node;
import core.game.node.entity.Entity;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import core.game.node.entity.player.info.PlayerDetails;
import core.game.node.entity.player.link.appearance.Gender;
import core.game.node.item.Item;
import core.game.system.SystemLogger;
import core.game.world.map.Direction;
import core.game.world.map.Location;
import core.game.world.map.RegionManager;
import core.game.world.map.path.Pathfinder;
import core.game.world.map.zone.impl.WildernessZone;
import core.game.world.repository.Repository;
import core.net.packet.context.MessageContext;
import core.net.packet.in.InteractionPacket;
import core.plugin.Plugin;
import core.tools.RandomFunction;
import core.tools.StringUtils;
import core.game.content.dialogue.DialoguePlugin;
import core.game.node.entity.skill.Skills;
import core.game.content.quest.tutorials.tutorialisland.CharacterDesign;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
/**
* Represents an <b>A</b>rtificial <b>I</b>ntelligent <b>P</b>layer.
*
* @author Emperor
*/
public class AIPlayer extends Player {
/**
* The current UID.
*/
private static int currentUID = 0x1;
private static List<String> botNames = new ArrayList<String>();
private static List<String> usedNames = new ArrayList<String>();
/**
* The active Artificial intelligent players mapping.
*/
private static final Map<Integer, AIPlayer> botMapping = new HashMap<>();
/**
* The aip control dialogue.
*/
private static final AIPControlDialogue CONTROL_DIAL = new AIPControlDialogue();
/**
* A line of data from namesandarmor.txt that will be used to generate the appearance
* Data in format:
* //name:cblevel:helmet:cape:neck:weapon:chest:shield:unknown:legs:unknown:gloves:boots:
*/
private static String OSRScopyLine;
/**
* The AIP's UID.
*/
private final int uid;
/**
* The start location of the AIP.
*/
private final Location startLocation;
/**
* The username.
*/
private String username;
/**
* The player controlling this AIP.
*/
private Player controler;
/**
* Constructs a new {@code AIPlayer} {@code Object}.
*
* @param l The location.
*/
static {
loadNames("botnames.txt");
}
public AIPlayer(Location l) {
this(getRandomName(), l, null);
}
public AIPlayer(String fileName, Location l) {
this(retrieveRandomName(fileName), l, null);
}
@SuppressWarnings("deprecation")
private AIPlayer(String name, Location l, String ignored) {
super(new PlayerDetails("/aip" + (currentUID + 1) + ":" + name));
super.setLocation(startLocation = l);
super.artificial = true;
super.getDetails().setSession(ArtificialSession.getSingleton());
Repository.getPlayers().add(this);
this.username = StringUtils.formatDisplayName(name + (currentUID + 1));
this.uid = currentUID++;
this.updateRandomValues();
this.init();
}
/**
* Generates bot stats/equipment/etc based on OSRScopyLine
*/
public void updateRandomValues() {
this.getAppearance().setGender(RandomFunction.random(5) == 1 ? Gender.FEMALE : Gender.MALE);
int setTo = RandomFunction.random(0,10);
CharacterDesign.randomize(this,true);
this.setDirection(Direction.values()[new Random().nextInt(Direction.values().length)]); //Random facing dir
this.getSkills().updateCombatLevel();
this.getAppearance().sync();
}
@Override
public void update() {
return;
}
private void setLevels() {
//Create realistic player stats
int maxLevel = RandomFunction.random(1, Math.min(parseOSRS(1), 99));
for (int i = 0; i < Skills.NUM_SKILLS; i++) {
this.getSkills().setStaticLevel(i, RandomFunction.linearDecreaseRand(maxLevel));
}
int combatLevelsLeft = parseOSRS(1);
int hitpoints = Math.max(RandomFunction.random(10, Math.min(maxLevel, combatLevelsLeft * 4)), 10);
combatLevelsLeft -= 0.25 * hitpoints;
int prayer = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft * 8)) : 1;
combatLevelsLeft -= 0.125 * prayer;
int defence = combatLevelsLeft > 0 ? RandomFunction.random(Math.min(maxLevel, combatLevelsLeft * 4)) : 1;
combatLevelsLeft -= 0.25 * defence;
combatLevelsLeft = Math.min(combatLevelsLeft, 199);
int attack = combatLevelsLeft > 0 ? RandomFunction.normalRandDist(Math.min(maxLevel, combatLevelsLeft * 3)) : 1;
int strength = combatLevelsLeft > 0 ? combatLevelsLeft * 3 - attack : 1;
this.getSkills().setStaticLevel(Skills.HITPOINTS, hitpoints);
this.getSkills().setStaticLevel(Skills.PRAYER, prayer);
this.getSkills().setStaticLevel(Skills.DEFENCE, defence);
this.getSkills().setStaticLevel(Skills.ATTACK, attack);
this.getSkills().setStaticLevel(Skills.STRENGTH, strength);
this.getSkills().setStaticLevel(Skills.RANGE, combatLevelsLeft / 2);
this.getSkills().setStaticLevel(Skills.MAGIC, combatLevelsLeft / 2);
}
private void giveArmor() {
//name:cblevel:helmet2:cape3:neck4:weapon5:chest6:shield7:unknown8:legs9:unknown10:gloves11:boots12:
//sicriona:103:1163: 1023: 1725 :1333: 1127 :1201 :0: 1079 :0: 2922: 1061:0:
equipIfExists(new Item(parseOSRS(2)), EquipmentContainer.SLOT_HAT);
equipIfExists(new Item(parseOSRS(3)), EquipmentContainer.SLOT_CAPE);
equipIfExists(new Item(parseOSRS(4)), EquipmentContainer.SLOT_AMULET);
equipIfExists(new Item(parseOSRS(5)), EquipmentContainer.SLOT_WEAPON);
equipIfExists(new Item(parseOSRS(6)), EquipmentContainer.SLOT_CHEST);
equipIfExists(new Item(parseOSRS(7)), EquipmentContainer.SLOT_SHIELD);
equipIfExists(new Item(parseOSRS(9)), EquipmentContainer.SLOT_LEGS);
equipIfExists(new Item(parseOSRS(11)), EquipmentContainer.SLOT_HANDS);
equipIfExists(new Item(parseOSRS(12)), EquipmentContainer.SLOT_FEET);
}
private int parseOSRS(int index) {
return Integer.parseInt(OSRScopyLine.split(":")[index]);
}
private void equipIfExists(Item e, int slot) {
if (e == null || e.getName().equalsIgnoreCase("null")) {
return;
}
if (e.getId() != 0)
getEquipment().replace(e, slot);
}
/**
* Load a list of bot names into memory
*/
public static void loadNames(String fileName){
try {
Scanner sc = new Scanner(new File(ServerConstants.BOT_DATA_PATH + fileName));
while(sc.hasNextLine()){
botNames.add(sc.next());
}
} catch (Exception e){
e.printStackTrace();
}
}
public static String getRandomName(){
int index = (RandomFunction.random(botNames.size()));
String name = botNames.get(index);
while(usedNames.contains(name)){
index = (RandomFunction.random(botNames.size()));
name = botNames.get(index);
}
usedNames.add(name);
return name;
}
/**
* Get a bot content
*/
public static void updateRandomOSRScopyLine(String fileName) {
Random rand = new Random();
int n = 0;
try {
for (Scanner sc = new Scanner(new File(ServerConstants.BOT_DATA_PATH + fileName)); sc.hasNext(); ) {
++n;
String line = sc.nextLine();
if (rand.nextInt(n) == 0) { //Chance of overwriting line is lower and lower
if (line.length() < 3 || line.startsWith("#")) //probably an empty line
{
continue;
}
OSRScopyLine = line;
}
}
} catch (FileNotFoundException e) {
System.out.println("Missing " + fileName);
e.printStackTrace();
}
}
private static String retrieveRandomName(String fileName) {
do {
updateRandomOSRScopyLine(fileName);
} while (OSRScopyLine.startsWith("#") || OSRScopyLine.contains("_") || OSRScopyLine.contains(" ")); //Comment
return OSRScopyLine.split(":")[0];
}
private static String retrieveRandomName() {
return retrieveRandomName("namesandarmor.txt");
}
@Override
public void init() {
getProperties().setSpawnLocation(startLocation);
getInterfaceManager().openDefaultTabs();
getSession().setObject(this);
botMapping.put(uid, this);
super.init();
getSettings().setRunToggled(true);
CharacterDesign.randomize(this, false);
getInteraction().set(new Option("Control", 7).setHandler(new OptionHandler() {
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
return null;
}
@Override
public boolean handle(Player p, Node node, String option) {
DialoguePlugin dial = CONTROL_DIAL.newInstance(p);
if (dial != null && dial.open(AIPlayer.this)) {
p.getDialogueInterpreter().setDialogue(dial);
}
return true;
}
@Override
public boolean isWalk() {
return false;
}
}));
getPlayerFlags().setLastSceneGraph(location);
}
/**
* Handles the following.
*
* @param e The entity to follow.
*/
public void follow(final Entity e) {
getPulseManager().run(new MovementPulse(this, e, DestinationFlag.FOLLOW_ENTITY) {
@Override
public boolean pulse() {
face(e);
return false;
}
}, "movement");
}
public void randomWalkAroundPoint(Location point, int radius) {
Pathfinder.find(this, point.transform(RandomFunction.random(radius, (radius * -1)), RandomFunction.random(radius, (radius * -1)), 0), true, Pathfinder.SMART).walk(this);
}
public void randomWalk(int radiusX, int radiusY) {
Pathfinder.find(this, this.getLocation().transform(RandomFunction.random(radiusX, (radiusX * -1)), RandomFunction.random(radiusY, (radiusY * -1)), 0), false, Pathfinder.SMART).walk(this);
}
public void walkToPosSmart(int x, int y) {
walkToPosSmart(new Location(x, y));
}
public void walkToPosSmart(Location loc) {
Pathfinder.find(this, loc, true, Pathfinder.SMART).walk(this);
}
public void walkPos(int x, int y) {
Pathfinder.find(this, new Location(x, y));
}
public boolean checkVictimIsPlayer() {
if (this.getProperties().getCombatPulse().getVictim() != null)
if (this.getProperties().getCombatPulse().getVictim().isPlayer())
return true;
return false;
}
@Override
public void tick() {
super.tick();
if(getSkullManager().isWilderness()) {
getSkullManager().setLevel(WildernessZone.getWilderness(this));
}
if(getSkills().getLifepoints() <= 0){
//deregister(this.uid);
}
}
public Item getItemById(int id) {
for (int i = 0; i < 28; i++) {
Item item = this.getInventory().get(i);
if (item != null) {
if (item.getId() == id)
return item;
}
}
return null;
}
public void handleIncomingChat(MessageContext ctx){
}
private ArrayList<Node> getNodeInRange(int range, int entry) {
int meX = this.getLocation().getX();
int meY = this.getLocation().getY();
ArrayList<Node> nodes = new ArrayList<Node>();
for (NPC npc : RegionManager.getLocalNpcs(this, range)) {
if (npc.getId() == entry)
nodes.add(npc);
}
for (int x = 0; x < range; x++) {
for (int y = 0; y < range - x; y++) {
Node node = RegionManager.getObject(0, meX + x, meY + y);
if (node != null)
if (node.getId() == entry)
nodes.add(node);
Node node2 = RegionManager.getObject(0, meX + x, meY - y);
if (node2 != null)
if (node2.getId() == entry)
nodes.add(node2);
Node node3 = RegionManager.getObject(0, meX - x, meY + y);
if (node3 != null)
if (node3.getId() == entry)
nodes.add(node3);
Node node4 = RegionManager.getObject(0, meX - x, meY - y);
if (node4 != null)
if (node4.getId() == entry)
nodes.add(node4);
}
}
return nodes;
}
private ArrayList<Node> getNodeInRange(int range, List<Integer> entrys) {
int meX = this.getLocation().getX();
int meY = this.getLocation().getY();
//int meX2 = this.getLocation().getX();
//System.out.println("local " + meX + " real x? " + meX2 );
ArrayList<Node> nodes = new ArrayList<Node>();
for (NPC npc : RegionManager.getLocalNpcs(this, range)) {
if (entrys.contains(npc.getId()))
nodes.add(npc);
}
for (int x = 0; x < range; x++) {
for (int y = 0; y < range - x; y++) {
Node node = RegionManager.getObject(0, meX + x, meY + y);
if (node != null)
if (entrys.contains(node.getId()))
nodes.add(node);
Node node2 = RegionManager.getObject(0, meX + x, meY - y);
if (node2 != null)
if (entrys.contains(node2.getId()))
nodes.add(node2);
Node node3 = RegionManager.getObject(0, meX - x, meY + y);
if (node3 != null)
if (entrys.contains(node3.getId()))
nodes.add(node3);
Node node4 = RegionManager.getObject(0, meX - x, meY - y);
if (node4 != null)
if (entrys.contains(node4.getId()))
nodes.add(node4);
}
}
return nodes;
}
public Node getClosestNodeWithEntryAndDirection(int range, int entry, Direction direction) {
ArrayList<Node> nodeList = getNodeInRange(range, entry);
if (nodeList.isEmpty()) {
//System.out.println("nodelist empty");
return null;
}
Node node = getClosestNodeinNodeListWithDirection(nodeList, direction);
return node;
}
public Node getClosestNodeWithEntry(int range, int entry) {
ArrayList<Node> nodeList = getNodeInRange(range, entry);
if (nodeList.isEmpty()) {
//System.out.println("nodelist empty");
return null;
}
Node node = getClosestNodeinNodeList(nodeList);
return node;
}
public Node getClosestNodeWithEntry(int range, List<Integer> entrys) {
ArrayList<Node> nodeList = getNodeInRange(range, entrys);
if (nodeList.isEmpty()) {
//System.out.println("nodelist empty");
return null;
}
Node node = getClosestNodeinNodeList(nodeList);
return node;
}
public Node getClosesCreature(int radius) {
int distance = radius + 1;
Node npcReturn = null;
for (NPC npc : RegionManager.getLocalNpcs(this, radius)) {
double distanceToNpc = npc.getLocation().getDistance(this.getLocation());
if ((distanceToNpc) < distance) {
distance = (int) distanceToNpc;
npcReturn = npc;
}
}
return npcReturn;
}
public Node getClosesCreature(int radius, int entry) {
int distance = radius + 1;
Node npcReturn = null;
for (NPC npc : RegionManager.getLocalNpcs(this, radius)) {
double distanceToNpc = npc.getLocation().getDistance(this.getLocation());
if (npc.getId() == entry) {
if ((distanceToNpc) < distance) {
distance = (int) distanceToNpc;
npcReturn = npc;
}
}
}
return npcReturn;
}
public Node getClosesCreature(int radius, ArrayList<Integer> entrys) {
int distance = radius + 1;
Node npcReturn = null;
for (NPC npc : RegionManager.getLocalNpcs(this, radius)) {
double distanceToNpc = npc.getLocation().getDistance(this.getLocation());
if (entrys.contains(npc.getId())) {
if ((distanceToNpc) < distance) {
distance = (int) distanceToNpc;
npcReturn = npc;
}
}
}
return npcReturn;
}
private Node getClosestNodeinNodeListWithDirection(ArrayList<Node> nodes, Direction direction) {
if (nodes.isEmpty()) {
//System.out.println("nodelist empty");
return null;
}
double distance = 0;
Node nodeReturn = null;
for (Node node : nodes) {
double nodeDistance = this.getLocation().getDistance(node.getLocation());
if ((nodeReturn == null || nodeDistance < distance) && node.getDirection() == direction) {
distance = nodeDistance;
nodeReturn = node;
}
}
return nodeReturn;
}
private Node getClosestNodeinNodeList(ArrayList<Node> nodes) {
if (nodes.isEmpty()) {
//System.out.println("nodelist empty");
return null;
}
double distance = 0;
Node nodeReturn = null;
for (Node node : nodes) {
double nodeDistance = this.getLocation().getDistance(node.getLocation());
if (nodeReturn == null || nodeDistance < distance) {
distance = nodeDistance;
nodeReturn = node;
}
}
return nodeReturn;
}
@Override
public void clear() {
botMapping.remove(uid);
super.clear(true);
}
@Override
public void reset() {
if (getPlayerFlags().isUpdateSceneGraph()) {
getPlayerFlags().setLastSceneGraph(getLocation());
}
super.reset();
}
@Override
public void finalizeDeath(Entity killer) {
super.finalizeDeath(killer);
fullRestore();
}
/**
* Gets the UID.
*
* @return the UID.
*/
public int getUid() {
return uid;
}
/**
* Deregisters an AIP.
*
* @param uid The player's UID.
*/
public static void deregister(int uid) {
AIPlayer player = botMapping.get(uid);
if (player != null) {
player.clear();
Repository.getPlayers().remove(player);
return;
}
//SystemLogger.logErr("Could not deregister AIP#" + uid + ": UID not added to the mapping!");
}
@Override
public String getUsername() {
return username;
}
/**
* Gets the AIP for the given UID.
*
* @param uid The UID.
* @return The AIPlayer.
*/
public static AIPlayer get(int uid) {
return botMapping.get(uid);
}
/**
* @return the startLocation.
*/
public Location getStartLocation() {
return startLocation;
}
/**
* Gets the controler.
*
* @return The controler.
*/
public Player getControler() {
return controler;
}
/**
* Sets the controler.
*
* @param controler The controler to set.
*/
public void setControler(Player controler) {
this.controler = controler;
}
public void interact(Node n) {
InteractionPacket.handleObjectInteraction(this, 0, n.getLocation(), n.getId());
}
}
@@ -0,0 +1,53 @@
package plugin.ai;
import java.nio.ByteBuffer;
import core.net.IoSession;
/**
* Represents an artificial networking session.
* @author Emperor
*/
public final class ArtificialSession extends IoSession {
/**
* The artificial session singleton.
*/
private static final ArtificialSession SINGLETON = new ArtificialSession();
/**
* Constructs a new {@code ArtificialSession} {@code Object}.
*/
private ArtificialSession() {
super(null, null);
}
@Override
public String getRemoteAddress() {
return "127.0.0.1";
}
@Override
public void write(Object context, boolean instant) {
}
@Override
public void queue(ByteBuffer buffer) {
}
@Override
public void write() {
}
@Override
public void disconnect() {
}
/**
* @return the singleton.
*/
public static ArtificialSession getSingleton() {
return SINGLETON;
}
}
@@ -0,0 +1,52 @@
package plugin.ai.general.scriptrepository;
import core.game.node.entity.player.Player;
import plugin.ai.general.ScriptAPI;
import core.game.node.item.Item;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public abstract class Script {
public ScriptAPI scriptAPI;
public ArrayList<Item> inventory = new ArrayList<>();
public ArrayList<Item> equipment = new ArrayList<>();
public Map<Integer, Integer> skills = new HashMap<>();
public Player bot;
public boolean running = true;
public void init(boolean isPlayer)
{
//bot.init();
scriptAPI = new ScriptAPI(bot);
if(!isPlayer) {
for (Item i : equipment) {
bot.getEquipment().add(i, true, false);
}
bot.getInventory().clear();
for (Item i : inventory) {
bot.getInventory().add(i);
}
for (Map.Entry<Integer, Integer> skill : skills.entrySet()) {
setLevel(skill.getKey(), skill.getValue());
}
}
}
public abstract void tick();
public void setLevel(int skill, int level) {
bot.getSkills().setLevel(skill, level);
bot.getSkills().setStaticLevel(skill, level);
bot.getSkills().updateCombatLevel();
bot.getAppearance().sync();
}
public abstract Script newInstance();
}
@@ -0,0 +1,34 @@
package plugin.ai.lumbridge;
import plugin.ai.AIPlayer;
import core.game.world.map.Location;
import core.game.world.map.zone.ZoneBorders;
import core.tools.RandomFunction;
public class DeadIdler extends AIPlayer {
//Recreation of players I saw in w417 who seemed to have quit their computer after dying.
private int tick = RandomFunction.random(500);
public DeadIdler()
{
super(getRandomRespawnLoc());
this.setCustomState("Lumbridge Bot");
}
@Override
public void tick()
{
super.tick();
if (this.tick > 0)
{
tick --;
} else {
AIPlayer.deregister(this.getUid());
}
}
private static Location getRandomRespawnLoc() {
return new ZoneBorders(3219, 3218, 3223, 3219).getRandomLoc();
}
}
@@ -0,0 +1,33 @@
package plugin.ai.lumbridge;
import core.game.world.GameWorld;
import core.tools.RandomFunction;
import java.util.concurrent.Executors;
/**
* Creates a few random bots around Lumbridge area.
* Code by Red Bracket
*/
public class LumbridgeBotHandler {
public static void immersiveLumbridge()
{
//Generate a few random bots here and there
System.out.println("[" + GameWorld.getSettings().getName() + "]: LumbridgeBotHandler: Initialized dead idlers.");
generateDeadIdlers();
}
private static void generateDeadIdlers() {
Executors.newSingleThreadExecutor().execute(() -> {
while (true) //Would probably be better if this could be "while game is running"
{
new DeadIdler();
try {
Thread.sleep(RandomFunction.random(300_000));
} catch (InterruptedException e) {
System.out.println("LumbridgeBotHandler can't sleep!!?");
}
}
});
}
}
@@ -0,0 +1,66 @@
package plugin.ai.pvmbots;
import core.game.node.entity.skill.Skills;
import plugin.ai.AIPlayer;
import core.game.node.entity.player.link.prayer.*;
import core.game.world.map.Location;
import core.game.world.map.zone.impl.WildernessZone;
public class DragonKiller extends PvMBots{
private int tick = 0;
public DragonKiller(Location l) {
super(l);
// TODO Auto-generated constructor stub
}
@Override
public void tick()
{
super.tick();
//Despawn
if (this.getSkills().getLifepoints() == 0 || this.getLocation().equals(new Location(0, 0)))
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
AIPlayer.deregister(this.getUid());
if (this.checkVictimIsPlayer())
{
tryEscape();
}
//Npc Combat
if (tick == 0)
{
if (!this.inCombat())
AttackNpcsInRadius(this, 15);
this.tick = 10;
}
else
this.tick--;
this.eat(379);
this.getSkills().setLevel(Skills.PRAYER, 99);
this.getSkills().setStaticLevel(Skills.PRAYER, 99);
if (!(this.getPrayer().getActive().contains(PrayerType.PROTECT_FROM_MELEE)))
this.getPrayer().toggle(PrayerType.PROTECT_FROM_MELEE);
//this.getPrayer().toggle()
}
public void tryEscape()
{
if (this.isTeleBlocked() == false)
{
if (WildernessZone.getWilderness(this) <= 20)
{
System.out.println("not Teleblocked");
this.teleport(new Location(0, 0));
}
}
else
return;
//run away
}
}
@@ -0,0 +1,68 @@
package plugin.ai.pvmbots;
import plugin.ai.AIPlayer;
import core.game.node.entity.player.link.prayer.PrayerType;
import core.game.node.item.Item;
import core.game.world.map.Location;
public class GiantMoleBot extends PvMBots{
public GiantMoleBot(Location l) {
super(l);
// TODO Auto-generated constructor stub
}
int tick = 0;
int movetimer = 5;
private void checkLightSource()
{
if (!this.getInventory().containItems(33))
{
if (this.getInventory().containItems(36))
this.getInventory().remove(new Item(36));
this.getInventory().add(new Item(33));
}
}
@Override
public void tick()
{
checkLightSource();
super.tick();
PrayerType type[] = {PrayerType.PROTECT_FROM_MELEE, PrayerType.PIETY};
this.CheckPrayer(type);
//Despawn
if (this.getSkills().getLifepoints() == 0)
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
AIPlayer.deregister(this.getUid());
//Npc Combat
if (this.tick == 0)
{
if (!this.inCombat())
AttackNpcsInRadius(this, 50);
this.tick = 5;
}
else
this.tick--;
/*if (this.movetimer == 0)
{
if (!this.inCombat())
{
this.randomWalk(10, 10);
}
this.movetimer = 4;
}
else
this.movetimer--;*/
//if (this.getSkills().getLifepoints() > 1)
//this.eat();
//this.getPrayer().toggle()
}
}
@@ -0,0 +1,38 @@
package plugin.ai.pvmbots;
import plugin.ai.AIPlayer;
import core.game.world.map.Location;
public class LowestBot extends PvMBots{
public LowestBot(Location l) {
super(l);
}
private int tick = 0;
@Override
public void tick(){
super.tick();
this.tick++;
//Despawn
if (this.getSkills().getLifepoints() == 0)
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
AIPlayer.deregister(this.getUid());
//Npc Combat
if (this.tick % 10 == 0) {
if (!this.inCombat())
AttackNpcsInRadius(this, 5);
}
if (this.tick == 100) this.tick = 0;
this.eat(329);
//this.getPrayer().toggle()
}
}
@@ -0,0 +1,54 @@
package plugin.ai.pvmbots;
import plugin.ai.AIPlayer;
import core.game.world.map.Location;
public class NoobBot extends PvMBots{
private int tick = 0;
private int movetimer = 0;
public NoobBot(Location l) {
super(l);
// TODO Auto-generated constructor stub
}
@Override
public void tick()
{
super.tick();
//Despawn
if (this.getSkills().getLifepoints() == 0)
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
AIPlayer.deregister(this.getUid());
//Npc Combat
if (tick == 0)
{
if (!this.inCombat())
AttackNpcsInRadius(this, 5);
this.tick = 5;
}
else
this.tick--;
this.eat(329);
//this.getPrayer().toggle()
//System.out.println(this.getPulseManager().getCurrent());
if (!this.inCombat())
{
if (movetimer == 0)
{
if (this.FindTargets(this, 5) == null)
this.randomWalk(5, 5);
this.movetimer = 10;
}
else
movetimer --;
}
}
}
@@ -0,0 +1,150 @@
package plugin.ai.pvmbots;
import java.util.ArrayList;
import java.util.List;
import core.game.content.consumable.Consumable;
import core.game.content.consumable.Consumables;
import core.game.content.consumable.Food;
import core.game.content.consumable.effects.HealingEffect;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.Entity;
import core.game.node.entity.npc.NPC;
import core.game.node.entity.player.Player;
import plugin.ai.AIPlayer;
import core.game.node.entity.player.link.prayer.PrayerType;
import core.game.node.item.Item;
import core.game.world.map.Location;
import core.game.world.map.RegionManager;
import core.tools.RandomFunction;
public class PvMBots extends AIPlayer {
//Used so the bot doesn't spam actions
private int tick = 0;
public PvMBots(Location l) {
super(l);
}
public PvMBots(String copyFromFile, Location l) {
super(copyFromFile, l);
}
public List<Entity> FindTargets(Entity entity, int radius) {
List<Entity> targets = new ArrayList<>();
Object[] localNPCs = RegionManager.getLocalNpcs(entity,radius).toArray();
int length = localNPCs.length;
if(length > 5){length = 5;}
for (int i = 0; i < length; i++) {
NPC npc = (NPC) localNPCs[i];
{
if (checkValidTargets(npc))
targets.add(npc);
}
}
if (targets.size() == 0)
return null;
return targets;
}
public boolean checkValidTargets(NPC target) {
if (!target.isActive()) {
return false;
}
if (!target.getProperties().isMultiZone() && target.inCombat()) {
return false;
}
if (!target.getDefinition().hasAction("attack")) {
return false;
}
return true;
}
public boolean AttackNpcsInRadius(int radius)
{
return AttackNpcsInRadius(this, radius);
}
/**
* Attacks NPCs in radius of bot
* @param bot
* @param radius
* @return true if bot will be fighting
*/
public boolean AttackNpcsInRadius(Player bot, int radius) {
if (bot.inCombat())
return true;
List<Entity> creatures = FindTargets(bot, radius);
if (creatures == null) {
return false;
}
bot.attack(creatures.get(RandomFunction.getRandom((creatures.size() - 1))));
if (!creatures.isEmpty()) {
return true;
} else {
creatures = FindTargets(bot, radius);
if (!creatures.isEmpty())
{
bot.attack(creatures.get(RandomFunction.getRandom((creatures.size() - 1))));
return true;
}
return false;
}
}
@Override
public void tick() {
super.tick();
this.tick++;
//Despawn
if (this.getSkills().getLifepoints() <= 5){
//TODO: Just respawn a new bot (not sure how you'd do that :L)
// Maybe make all PvMBots know what to do if they aren't in right area? I.e. pest control bots teleport to PC
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
this.getSkills().setLifepoints(20);
}
//Npc Combat
/*if (this.tick % 10 == 0) {
if (!this.inCombat())
AttackNpcsInRadius(this, 5);
}*/
if (this.tick == 100) this.tick = 0;
//this.eat();
//this.getPrayer().toggle()
}
public void CheckPrayer(PrayerType type[]) {
for (int i = 0; i < type.length; i++)
this.getPrayer().toggle(type[i]);
}
public void eat(int foodId) {
Item foodItem = new Item(foodId);
if ((this.getSkills().getStaticLevel(Skills.HITPOINTS) >= this.getSkills().getLifepoints() * 3) && this.getInventory().containsItem(foodItem)) {
this.lock(3);
//this.animate(new Animation(829));
Item food = this.getInventory().getItem(foodItem);
Consumable consumable = Consumables.getConsumableById(food.getId());
if (consumable == null) {
consumable = new Food(new int[] {food.getId()}, new HealingEffect(1));
}
consumable.consume(food, this);
this.getProperties().getCombatPulse().delayNextAttack(3);
}
if (this.checkVictimIsPlayer() == false)
if (!(this.getInventory().contains(foodId, 1)))
this.getInventory().add(new Item(foodId, 5)); //Add Food to Inventory
}
}
@@ -0,0 +1,196 @@
package plugin.ai.pvp;
import java.util.List;
import core.game.container.impl.EquipmentContainer;
import core.game.content.consumable.Consumable;
import core.game.content.consumable.Consumables;
import core.game.content.consumable.Food;
import core.game.content.consumable.effects.HealingEffect;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.player.Player;
import plugin.ai.AIPlayer;
import core.game.node.item.Item;
import core.game.system.task.Pulse;
import core.game.world.GameWorld;
import core.game.world.map.path.Pathfinder;
import core.game.world.update.flag.context.ChatMessage;
import core.game.world.update.flag.player.ChatFlag;
import core.tools.RandomFunction;
public class PVPAIPActions {
public static List<AIPlayer> pvp_players = null;
private static final String[] trashMessages = {
"I'll do your bloody nan in m8",
"Your sister smells like a tuna sandwich",
"You suck at bridding bro lmao",
"Gf your bank :)",
"Just delete your cache ur bad",
"FFS mate get wrekt",
"Dylan is a better pkr than u, kid..l0l"
};
private static final String[] safeMessages = {
"Safe up n00b",
"No safe",
"Get rekt m8",
"Stop fkin eating scrub",
"Dw, you're gunna die anyhow.. :)",
"Either ur eating shrimps or I'm hitting high asf",
"Once i kill u wanna rematch?",
};
public static void syncBotThread(final Player player) {
if (pvp_players == null || pvp_players.size() == 0) {
return;
}
for (int aip_index = 0; aip_index < pvp_players.size(); aip_index++) {
final AIPlayer bot = pvp_players.get(aip_index);
final AIPlayer[] target = {
pvp_players.get(RandomFunction.getRandom(pvp_players.size() - 1))
};
bot.getProperties().setRetaliating(true);
bot.setAttribute("dead", false);
GameWorld.getPulser().submit(new Pulse(1, bot) {
int ticks;
@Override
public boolean pulse() {
if (bot.getAttribute("dead", true)) {
AIPlayer.deregister(bot.getUid());
pvp_players.remove(bot);
return true;
}
if (!bot.getInventory().contains(385, 1)) {
flee(bot);
return true;
}
//Inactivity logout timer.
if (ticks++ == 5000 && !bot.getProperties().getCombatPulse().isInCombat() && !bot.getProperties().getCombatPulse().isAttacking() && bot.getWalkingQueue().getQueue().isEmpty()) {
AIPlayer.deregister(bot.getUid());
pvp_players.remove(bot);
return true;
}
if (!pvp_players.contains(target) || !Pathfinder.find(bot, target[0]).isSuccessful() || !canAttack(bot, target[0])) {
target[0] = pvp_players.get(RandomFunction.getRandom(pvp_players.size() - 1));
}
attackTarget(player, bot, target[0]);
//prayer(bot, target[0]);
eat(bot, target[0]);
return false;
}
});
}
}
private static void attackTarget(Player player, AIPlayer bot, AIPlayer target) {
//If bots target is not himself we continue.
if (bot != target) {
//If they are in combat or attacking:
if (bot.getProperties().getCombatPulse().isInCombat() || bot.getProperties().getCombatPulse().isAttacking()) {
//TODO: Pray
Item weapon = bot.getEquipment().get(EquipmentContainer.SLOT_WEAPON);
if (RandomFunction.getRandom(25) == 1) {
if(bot.getSettings().getSpecialEnergy() == 100) { //TODO: Change 100 to their weielded weapons spec max amount
bot.getSettings().toggleSpecialBar();
}
}
} else {
if (RandomFunction.getRandom(25) == 1) {
bot.attack(player);
} else {
//If a 1/50 chance is true, the attacker screams his opponents name hoping his team will dogpile him.
int chatRandom = RandomFunction.getRandom(50);
switch(chatRandom) {
case 1:
String target_name = target.getName().substring(0, 1).toUpperCase() + target.getName().substring(1);
bot.getUpdateMasks().register(new ChatFlag(new ChatMessage(bot, target_name, 0, 0)));
break;
case 2:
bot.getUpdateMasks().register(new ChatFlag(new ChatMessage(bot, trashMessages[RandomFunction.getRandom(trashMessages.length - 1)], 0, 0)));
break;
}
bot.attack(target);
}
}
}
}
/**
* A basic flee method to run them to another part of the wilderness.
* @param bot
* TODO: Possibly make them run away and hop the ditch (I did not do this because we have no other actions than pking at the moment).
*/
private static void flee(final AIPlayer bot) {
bot.sendChat("Outta food m8! Off!");
bot.sendChat("Ahh!");
bot.sendChat("GTFO M8");
bot.sendChat("Someone spec him!");
GameWorld.getPulser().submit(new Pulse(1, bot) {
int ticks;
@Override
public boolean pulse() {
switch(ticks++) {
case 1:
bot.getProperties().getCombatPulse().stop();
bot.getProperties().getCombatPulse().setNextAttack(RandomFunction.getRandom(10));
Pathfinder.find(bot, bot.getLocation().transform(RandomFunction.random(-100, 100), RandomFunction.random(-100, 100), 0), false, Pathfinder.SMART).walk(bot);
break;
case 500:
AIPlayer.deregister(bot.getUid());
pvp_players.remove(bot);
return true;
}
if (bot.getAttribute("dead", true)) {
AIPlayer.deregister(bot.getUid());
pvp_players.remove(bot);
return true;
}
return false;
}
});
}
/**
* Handles the eating of the AI player bots.
* @param bot
* TODO: Possibly add more food choices.
*/
private static void eat(Player bot, AIPlayer target) {
Item shark = new Item(385);
//385 is shark, you can add more from there easier.
if((bot.getSkills().getStaticLevel(Skills.HITPOINTS) > bot.getSkills().getLifepoints() * 3) && bot.getInventory().containsItem(shark)) {
bot.lock(3);
Item food = bot.getInventory().getItem(shark);
Consumable consumable = Consumables.getConsumableById(food.getId());
if (consumable == null) {
consumable = new Food(new int[] {food.getId()}, new HealingEffect(1));
}
consumable.consume(food, bot);
bot.getProperties().getCombatPulse().delayNextAttack(3);
int chatRandom = RandomFunction.getRandom(50);
if (chatRandom == 1) {
bot.getUpdateMasks().register(new ChatFlag(new ChatMessage(bot, safeMessages[RandomFunction.getRandom(safeMessages.length - 1)], 0, 0)));
}
}
}
private static boolean canAttack(Player p, Player t) {
int level = p.getSkullManager().getLevel();
if (t.getSkullManager().getLevel() < level) {
level = t.getSkullManager().getLevel();
}
int combat = p.getProperties().getCombatLevel();
int targetCombat = t.getProperties().getCombatLevel();
if (combat - level > targetCombat || combat + level < targetCombat) {
return false;
}
return true;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,71 @@
package plugin.ai.resource;
import core.game.node.entity.skill.gather.SkillingResource;
import core.game.node.entity.player.Player;
import plugin.ai.AIPlayer;
import core.game.system.task.Pulse;
import core.game.world.GameWorld;
import core.game.world.repository.Repository;
import java.util.List;
public class ResourceAIPActions {
public static List<AIPlayer> resource_players = null;
protected SkillingResource resource;
public static void syncBotThread(final Player player) {
if (resource_players == null || resource_players.size() == 0) {
return;
}
for (int aip_index = 0; aip_index < resource_players.size(); aip_index++) {
final AIPlayer bot = resource_players.get(aip_index);
GameWorld.getPulser().submit(new Pulse(1, bot) {
int ticks;
int ov;
@Override
public boolean pulse() {
/*if (bot.getInventory().freeSlots() < 1) {
//flee(bot);
return true;
}*/
//Inactivity logout timer.
if (ticks++ == 5000/* && bot.getWalkingQueue().getQueue().isEmpty()*/) {
AIPlayer.deregister(bot.getUid());
resource_players.remove(bot);
return true;
}
if (ov++ >= 3) {
chopTree(bot);
ov = 0;
}
// ov = 0;
System.out.println("ResourceAIPActions" + ov);
return false;
}
});
}
}
private static boolean chopTree(final AIPlayer bot) {
/*for (GameObject[] o : RegionManager.forId(bot.getLocation().getRegionId()).getPlanes()[0].getObjects()) {
for (GameObject obj : o) {
if (obj != null) {
for (SkillingResource r : SkillingResource.values()) {
if (obj.getId() == r.getId()) {
Pathfinder.find(bot, obj).walk(bot);
bot.sendChat("WE CHOPPIN");
}
}
}
}
}*/
bot.attack(Repository.getNpcs().get(106));
// Pulse pulse = new GatheringSkillPulse(bot, node);
// bot.getPulseManager().run(new GatheringSkillPulse(bot, node));
// pulse.start();
return true;
}
}
@@ -0,0 +1,168 @@
package plugin.ai.resource;
import core.game.node.entity.player.Player;
import plugin.ai.resource.task.ResourceTask;
import plugin.ai.resource.task.ResourceTasks;
import core.game.system.task.Pulse;
import core.game.world.GameWorld;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* Package -> org.keldagrim.game.node.entity.player.ai.resource
* Created on -> 9/13/2016 @12:42 PM for 530
*
* @author Ethan Kyle Millard
*/
public class ResourceAIPManager {
private long time = 0;
private Player player;
private static Map<ResourceTask, Long> TASKS = new HashMap<>();
public ResourceAIPManager init() {
getTasks().put(ResourceTasks.WOODCUTTING.getResourceTask(), 0L);
return this;
}
public ResourceAIPManager runTask(Player player, String taskName) {
for (Map.Entry<ResourceTask, Long> entry : getTasks().entrySet()) {
if (entry.getKey().getTaskName().equalsIgnoreCase(taskName)) {
if (entry.getValue() != 0) {
message(player, "You have extended the task " + taskName + ".");
} else {
message(player, "You have activated the task " + taskName + ".");
}
}
entry.getKey().setTaskName(taskName);
entry.setValue(entry.getValue() + 70);
this.player = player;
}
return this;
}
public void reActivate(String name, long time) {
for (Map.Entry<ResourceTask, Long> entry : TASKS.entrySet()) {
if (entry.getKey().getTaskName().equalsIgnoreCase(name)) {
entry.setValue(time);
}
}
}
public ResourceAIPManager load(Player player) {
try {
Statement statement = GameWorld.getDatabaseManager().connections().get("global").createStatement();
ResultSet result = statement.executeQuery("SELECT * FROM `members` WHERE username='" + player.getUsername() + "'");
// Results result = new Results(GameWorld.getDatabaseManager().query("global", "SELECT * FROM `members` WHERE username='" + player.getUsername() + "'"));
while (result.next()) {
String eventName = result.getString("taskName");
String eventTime = result.getString("taskTime");
reActivate(eventName, Long.valueOf(eventTime));
}
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
public ResourceAIPManager save(Player player) {
/*if (GameWorld.getDatabaseManager().update("global", "DELETE FROM `members` WHERE worldid='" + GameWorld.getSettings().getWorldId() + "'") < 0)
return this;*/
System.out.println("Saving...");
Iterator<Map.Entry<ResourceTask, Long>> iterator = getTasks().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<ResourceTask, Long> entry = iterator.next();
if (entry.getValue() <= 0)
continue;
StringBuilder query = new StringBuilder();
query.append("UPDATE `members` SET `taskName`='" + entry.getKey().getTaskName() + "',`taskTime`='" + entry.getValue() + "' WHERE `username`='" + player.getUsername() + "'");
System.out.println("ResourceAIPManager: " + query.toString());
GameWorld.getDatabaseManager().update("global", query.toString());
}
return this;
}
public void pulse(Player player) {
GameWorld.getPulser().submit(new Pulse(1) {
@Override
public boolean pulse() {
time++;
Iterator<Map.Entry<ResourceTask, Long>> iterator = getTasks().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<ResourceTask, Long> entry = iterator.next();
if (entry.getValue() > 0) {
entry.setValue(entry.getValue() - 1);
if (entry.getValue() == 50)
message(player, "You have 30 minutes before " + entry.getKey().getTaskName() + " task ends.");
if (entry.getValue() <= 0) {
entry.getKey().setTime(0);
entry.getKey().reward(player, entry.getKey().getTaskName());
message(player, "The task " + entry.getKey().getTaskName() + " has now ended.");
save(player);
}
if (time == 50) {
entry.getKey().setTime(0);
save(player);
}
}
}
return false;
}
});
}
public ResourceAIPManager message(Player player, String message) {
return message(player, message, true, "<col=027fc7>");
}
public ResourceAIPManager message(Player player, String message, boolean tag) {
return message(player, message, tag, "<col=027fc7>");
}
public ResourceAIPManager notify(Player player, String message) {
return message(player, message, true, "<col=800000>");
}
public ResourceAIPManager notify(Player player, String message, boolean tag) {
return message(player, message, tag, "<col=800000>");
}
public ResourceAIPManager message(Player player, String message, boolean tag, String color) {
player.getPacketDispatch().sendMessage(color + (tag ? "[Resource Manager] - " : "") + message);
return this;
}
public static Map<ResourceTask, Long> getTasks() {
return TASKS;
}
private static ResourceAIPManager INSTANCE = new ResourceAIPManager();
public static ResourceAIPManager get() {
return INSTANCE;
}
public Player getPlayer() {
return player;
}
public void setPlayer(Player player) {
this.player = player;
}
}
@@ -0,0 +1,39 @@
package plugin.ai.resource.task;
import core.game.node.entity.player.Player;
/**
* Package -> org.keldagrim.game.node.entity.player.ai.resource.task
* Created on -> 9/13/2016 @12:44 PM for 530
*
* @author Ethan Kyle Millard
*/
public abstract class ResourceTask {
private String taskName;
private long time;
public ResourceTask(String taskName, long time) {
this.taskName = taskName;
this.time = time;
}
public abstract void reward(Player player, String eventName);
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
}
@@ -0,0 +1,49 @@
package plugin.ai.resource.task;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.tools.RandomFunction;
/**
* Package -> org.keldagrim.game.node.entity.player.ai.resource.task
* Created on -> 9/13/2016 @12:43 PM for 530
*
* @author Ethan Kyle Millard
*/
public enum ResourceTasks {
WOODCUTTING(new ResourceTask("Willow Logs", 6000) {
@Override
public void reward(Player player, String eventName) {
if (player.getSkills().getLevel(Skills.WOODCUTTING) < 30) {
player.sendMessage(reqirementMessage());
return;
}
if (getTime() == 0) {
player.getBank().add(new Item(1519, RandomFunction.random(700, 1000)));
player.getSkills().addExperience(Skills.WOODCUTTING, RandomFunction.random(100000, 150000));
}
}
});
private ResourceTask resourceTask;
ResourceTasks(ResourceTask resourceTask) {
this.resourceTask = resourceTask;
}
public ResourceTask getResourceTask() {
return resourceTask;
}
public void setResourceTask(ResourceTask resourceTask) {
this.resourceTask = resourceTask;
}
private static String reqirementMessage() {
return "You do not meet the requirements for this task.";
}
}
@@ -0,0 +1,128 @@
package plugin.ai.skillingbot;
import core.game.world.map.Location;
import java.util.ArrayList;
import core.game.node.entity.skill.Skills;
import core.game.interaction.Option;
import core.game.node.Node;
import plugin.ai.AIPlayer;
import core.game.node.item.Item;
import core.net.packet.in.InteractionPacket;
public class SkillingBot extends AIPlayer {
private int tick = 5;
private ArrayList<Integer> interactNodeIds;
private int fromWhereDoIdrop;
private int skill;
private int interactionRange;
public SkillingBot(Location l)
{
super(l);
this.fromWhereDoIdrop = 0;
this.interactionRange = 15;
}
public SkillingBot(Location l, int skill, ArrayList<Integer> entrys)
{
super(l);
this.skill = skill;
this.fromWhereDoIdrop = 0;
this.interactNodeIds = entrys;
this.interactionRange = 15;
switch (this.skill)
{
case Skills.MINING:
default:
break;
}
}
@Override
public void tick()
{
super.tick();
//Despawn
if (this.getSkills().getLifepoints() == 0)
AIPlayer.deregister(this.getUid());
//Interact with object
if (this.tick <= 0)
{
this.tick = 5;
if (this.skill == Skills.FISHING)
this.tick = 20;
// Node test = getClosestNodeWithEntry(15, 15503);
Node node;
if (this.skill != Skills.FISHING)
{
node = getClosestNodeWithEntry(interactionRange, interactNodeIds);
}
else
{
node = getClosesCreature(interactionRange, interactNodeIds);
// if (test != null)
// System.out.println("interact with " + test.getName());
}
if (node == null) {
System.out.println("SkillingBot.java: Object not found " + this.skill);
return;
}
//System.out.println("free slots " + this.getInventory().freeSlots());
if (this.getInventory().isFull())
{
// System.out.println(this.getName() + " starts droping from " + fromWhereDoIdrop);
for (int i = fromWhereDoIdrop; i < 28; i++)
{
Item drop = this.getInventory().get(i);
final Option option = drop.getInteraction().get(4);
drop.getInteraction().handleItemOption(this, option, this.getInventory());
// System.out.println("drop item " + i);
}
}
int x = node.getLocation().getX();
int y = node.getLocation().getY();
if (this.skill != Skills.FISHING)
{
InteractionPacket.handleObjectInteraction(this, 0, x, y, node.getId());
}
else
{
InteractionPacket.handleNPCInteraction(this, 0, node.getIndex());
}
}
else
this.tick--;
}
public int getSkill()
{
return this.skill;
}
public int getFromWhereToDrop()
{
return this.fromWhereDoIdrop;
}
public void setFromWhereDoIdrop(int id)
{
this.fromWhereDoIdrop = id;
}
public void setInteractionRange(int range)
{
this.interactionRange = range;
}
}
@@ -0,0 +1,209 @@
package plugin.ai.skillingbot;
import java.util.ArrayList;
import core.game.container.impl.EquipmentContainer;
import core.game.content.quest.tutorials.tutorialisland.CharacterDesign;
import core.game.node.entity.skill.Skills;
import plugin.ai.AIPlayer;
import core.game.node.entity.player.link.appearance.Gender;
import core.game.node.item.Item;
import core.game.world.map.Location;
import core.tools.RandomFunction;
public final class SkillingBotsBuilder extends AIPlayer {
public SkillingBotsBuilder(Location l) {
super(l);
// TODO Auto-generated constructor stub
}
private static SkillingBot generateMiningBot(Location loc, ArrayList<Integer> entrys)
{
SkillingBot bot = new SkillingBot(loc, Skills.MINING, entrys);
bot.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
bot.getEquipment().replace(new Item(1265), EquipmentContainer.SLOT_WEAPON);
return bot;
}
private static SkillingBot generateWoodcuttingBot(Location loc, ArrayList<Integer> entrys)
{
SkillingBot bot = new SkillingBot(loc, Skills.WOODCUTTING, entrys);
bot.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
bot.getEquipment().replace(new Item(1351), EquipmentContainer.SLOT_WEAPON);
return bot;
}
private static SkillingBot generateFishingBot(Location loc, ArrayList<Integer> entrys)
{
SkillingBot bot = new SkillingBot(loc, Skills.FISHING, entrys);
bot.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
CharacterDesign.randomize(bot, false);
return bot;
}
public static void spawnClayBotVarrock(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(15503);
entrys.add(15505);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 10);
}
public static void spawnIronBotVarrock(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(11954);
entrys.add(11955);
entrys.add(11956);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 25);
}
public static void spawnSilverBotVarrock(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(11948);
entrys.add(11949);
entrys.add(11950);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 30);
}
public static void spawnTinBotVarrock(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(11957);
entrys.add(11959);
entrys.add(11958);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 5);
}
public static void spawnTinBotLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(11933);
entrys.add(11934);
entrys.add(11935);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 5);
}
public static void spawnCopperBotLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(11936);
entrys.add(11937);
entrys.add(11938);
SkillingBot bot = generateMiningBot(loc, entrys);
bot.getSkills().setLevel(Skills.MINING, 5);
}
public static void spawnOakTreeBotLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(1281);
entrys.add(1278);
entrys.add(1276);
SkillingBot bot = generateWoodcuttingBot(loc, entrys);
bot.getSkills().setLevel(Skills.WOODCUTTING, 25);
bot.setInteractionRange(25);
}
public static void spawnDeadTreeBotLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(1282);
entrys.add(1286);
SkillingBot bot = generateWoodcuttingBot(loc, entrys);
bot.getSkills().setLevel(Skills.WOODCUTTING, 25);
bot.setInteractionRange(15);
}
public static void spawnShrimpFisherLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(323);
entrys.add(326);
SkillingBot bot = generateFishingBot(loc, entrys);
bot.getInventory().add(new Item(303));
// don't drop net
bot.setFromWhereDoIdrop(1);
bot.getSkills().setLevel(Skills.FISHING, 25);
bot.setInteractionRange(25);
}
public static void spawnTroutLumbridge(Location loc)
{
ArrayList<Integer> entrys = new ArrayList<Integer>();
entrys.add(310);
SkillingBot bot = generateFishingBot(loc, entrys);
bot.getInventory().add(new Item(309));
bot.getInventory().add(new Item(314, 20000));
// don't drop net
bot.setFromWhereDoIdrop(2);
bot.getSkills().setLevel(Skills.FISHING, 25);
bot.setInteractionRange(25);
}
//These bots are disabled because they somehow break pets
public static void immersiveSpawnsSkillingBots()
{
// Varrock Mine
SkillingBotsBuilder.spawnClayBotVarrock(new Location(3181, 3368));
SkillingBotsBuilder.spawnSilverBotVarrock(new Location(3181, 3368));
SkillingBotsBuilder.spawnIronBotVarrock(new Location(3181, 3368));
SkillingBotsBuilder.spawnTinBotVarrock(new Location(3181, 3368));
// Lumbridge woodcutting
spawnOakTreeBotLumbridge(new Location(3227, 3243));
spawnOakTreeBotLumbridge(new Location(3186, 3251));
spawnOakTreeBotLumbridge(new Location(3188, 3223));
spawnOakTreeBotLumbridge(new Location(3162, 3222));
spawnOakTreeBotLumbridge(new Location(3162, 3219));
spawnOakTreeBotLumbridge(new Location(3152, 3228));
spawnOakTreeBotLumbridge(new Location(3146, 3244));
spawnDeadTreeBotLumbridge(new Location(3247, 3240));
// Lumbridge mining
spawnTinBotLumbridge(new Location(3224, 3147));
spawnCopperBotLumbridge(new Location(3224, 3147));
// Lumbridge Fishing
spawnShrimpFisherLumbridge(new Location(3242, 3151));
spawnShrimpFisherLumbridge(new Location(3238, 3148));
spawnShrimpFisherLumbridge(new Location(3245, 3161));
spawnTroutLumbridge(new Location(3241, 3242));
}
}
@@ -0,0 +1,32 @@
package plugin.ai.system;
import plugin.ai.AIPlayer;
import java.util.HashMap;
import java.util.Map;
public class GlobalAIManager {
/**
* The active Artificial intelligent players mapping.
*/
private static final Map<Integer, AIPlayer> BOT_MAPPING = new HashMap<>();
/**
* Constructs a new {@code GlobalAIManager} {@code Object}.
*/
public GlobalAIManager() {
}
public static void addBot(int uid, AIPlayer player) {
BOT_MAPPING.put(uid, player);
}
public static AIPlayer getBot(int uid) {
return BOT_MAPPING.get(uid);
}
}
@@ -0,0 +1,4 @@
package plugin.ai.system.android;
public class CombatDroid {
}
@@ -0,0 +1,4 @@
package plugin.ai.system.android;
public class GatheringDroid {
}
@@ -0,0 +1,102 @@
package plugin.ai.system.predicate;
import javax.security.auth.Destroyable;
import plugin.ai.system.GlobalAIManager;
/**
* An android predicate.
*
* @author Viper
* @version 1.0 - 13/07/2016
*/
public abstract class Predicate implements Cloneable, Runnable, Destroyable {
protected GlobalAIManager bot;
/**
* Predicate started.
*/
private boolean started;
/**
* The predicate priority factor.
*/
private byte priority;
/**
* The predicate type.
*/
public abstract PredicateType getType();
/**
* Constructs a new {@link Predicate} {@code Object}.
*
* @param priority
* The priority of this predicate.
*/
public Predicate(int priority) {
this.priority = (byte) priority;
}
public Predicate clone() {
final Predicate pred = this;
return new Predicate(priority) {
@Override
public void run() {
pred.run();
}
@Override
public PredicateType getType() {
return pred.getType();
}
}.setStarted(pred.started);
}
/**
* @return the priority
*/
public byte getPriority() {
return priority;
}
/**
* @param priority the priority to set
*/
public void setPriority(byte priority) {
this.priority = priority;
}
/**
* @return the bot
*/
public GlobalAIManager getBot() {
return bot;
}
/**
* @param bot the bot to set
*/
public Predicate setBot(GlobalAIManager bot) {
this.bot = bot;
return this;
}
/**
* @return the started
*/
public boolean hasStarted() {
return started;
}
/**
* @param started the started to set
*/
public Predicate setStarted(boolean started) {
this.started = started;
return this;
}
}
@@ -0,0 +1,13 @@
package plugin.ai.system.predicate;
/**
* Types of predicates.
*
* @author Viper
* @version 1.0 - 13/07/2016
*/
public enum PredicateType {
BOOT, TRANSCENDING, PARSING, TRIVIAL;
}
@@ -0,0 +1,60 @@
package plugin.ai.system.predicate.impl;
import plugin.ai.system.predicate.Predicate;
import plugin.ai.system.predicate.PredicateType;
/**
* Generates random appearance for the droid.
*
* @author Viper
* @version 1.0 - 13/07/2016
*/
public class AppearancePredicate extends Predicate {
/**
* If the bot is a male.
*/
private boolean male;
/**
* Constructs a new appearance predicate.
*/
public AppearancePredicate(boolean male) {
super(-1);
this.male = male;
}
@Override
public PredicateType getType() {
return PredicateType.PARSING;
}
@Override
public void run() {
if (isMale()) {
/*bot.getAppearence().getBodyStyle()[0] = Utility.random(0, 8);
bot.getAppearence().getBodyStyle()[1] = Utility.random(10, 17);
bot.getAppearence().getBodyStyle()[2] = Utility.random(18, 25);
bot.getAppearence().getBodyStyle()[3] = Utility.random(26, 32);
bot.getAppearence().getBodyStyle()[4] = Utility.random(33, 34);
bot.getAppearence().getBodyStyle()[5] = Utility.random(36, 41);
bot.getAppearence().getBodyStyle()[6] = Utility.random(42, 44);
bot.getAppearence().getBodyColors()[2] = (byte) Utility.random(0, 127);
bot.getAppearence().getBodyColors()[1] = (byte) Utility.random(0, 127);
bot.getAppearence().getBodyColors()[0] = (byte) Utility.random(0, 24);*/
} else {
}
// bot.getAppearence().generateAppearenceData();
}
/**
* @return the male
*/
public boolean isMale() {
return male;
}
}
@@ -0,0 +1,550 @@
package plugin.ai.wilderness;
import java.util.ArrayList;
import core.game.container.impl.EquipmentContainer;
import core.game.node.entity.skill.Skills;
import core.game.node.entity.combat.CombatSpell;
import plugin.ai.AIPlayer;
import plugin.ai.pvmbots.DragonKiller;
import plugin.ai.pvmbots.NoobBot;
import plugin.ai.pvmbots.PvMBots;
import core.game.node.entity.player.link.SpellBookManager;
import core.game.node.entity.player.link.appearance.Gender;
import core.game.node.item.Item;
import core.game.world.map.Location;
import core.tools.RandomFunction;
public final class PvPBotsBuilder{
public static WildernessBot create(Location l)
{
return new WildernessBot(l);
}
public static void generateClass(WildernessBot p) {
int combatType = RandomFunction.getRandom(1);
switch(combatType) {
case 0:
buildMeleeStats(p);
buildMeleeEquipment(p);
correctHitpointsStat(p);
break;
case 1:
//max rune
buildMaxMeleeStats(p);
buildMaxMeleeEquipment(p);
correctHitpointsStat(p);
break;
}
p.getInventory().add(new Item(385, 20));
p.getProperties().setCombatLevel(126);
p.getSkills().setLevel(Skills.PRAYER, 98);
p.getSkills().setStaticLevel(Skills.PRAYER, 98);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildMeleeStats(WildernessBot p) {
int attackLevel = RandomFunction.random(80, 98);
int strengthLevel = RandomFunction.random(attackLevel - 10, attackLevel + 10);
int defenceLevel = RandomFunction.random(60, 98);
p.getSkills().setLevel(Skills.ATTACK, attackLevel);
p.getSkills().setStaticLevel(Skills.ATTACK, attackLevel);
p.getSkills().setLevel(Skills.STRENGTH, strengthLevel);
p.getSkills().setStaticLevel(Skills.STRENGTH, strengthLevel);
p.getSkills().setLevel(Skills.DEFENCE, defenceLevel);
p.getSkills().setStaticLevel(Skills.DEFENCE, defenceLevel);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildMeleeEquipment(WildernessBot p) {
int[] helms = {
1163, //Rune Full Helm
3751, //Berserker Helm
3753, //Warrior Helm
10828,
1038,
4753,
};
int[] shield = {
1185, //Rune sq shield
1201, //Rune kiteshield
6524, //Obsidian shield
8850, //Rune defender
11286,
14767,
};
int[] platebody = {
1113, //Rune chainmail.
1127, //Rune platebody.
10551,
4757,
11724,
4720,
};
int[] platelegs = {
1079, //Rune platelegs.
4759,
11726,
1075,
};
p.getEquipment().replace(new Item(helms[RandomFunction.random(helms.length)]), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(shield[RandomFunction.random(shield.length)]), EquipmentContainer.SLOT_SHIELD);
p.getEquipment().replace(new Item(platebody[RandomFunction.random(platebody.length)]), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(platelegs[RandomFunction.random(platelegs.length)]), EquipmentContainer.SLOT_LEGS);
Item weapon = new Item(weapons[RandomFunction.random(weapons.length)]);
p.setMainWeapon(weapon.getId());
p.getEquipment().replace(weapon, EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(generateNecklace()), EquipmentContainer.SLOT_AMULET);
p.getEquipment().replace(new Item(generateBoots()), EquipmentContainer.SLOT_FEET);
p.getEquipment().replace(new Item(generateCape()), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(generateGloves()), EquipmentContainer.SLOT_HANDS);
}
public static final int[] weapons = {
4151, //Whip
4587, //Dragon Scimitar
};
private static void buildMaxMeleeStats(AIPlayer p)
{
p.getSkills().setLevel(Skills.ATTACK, 99);
p.getSkills().setStaticLevel(Skills.ATTACK, 99);
p.getSkills().setLevel(Skills.STRENGTH, 99);
p.getSkills().setStaticLevel(Skills.STRENGTH, 99);
p.getSkills().setLevel(Skills.DEFENCE, 99);
p.getSkills().setStaticLevel(Skills.DEFENCE, 99);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildMaxMeleeEquipment(AIPlayer p) {
int[] helms = {
3751, //Berserker Helm
};
int[] shield = {
14767, //Dragon defender
};
int[] platebody = {
11724, //Bandos chainmail.
};
int[] platelegs = {
11726, //Bandos Tassets.
};
int[] amulets = {
6585, //fury
};
int[] boots = {
3105, //Climbing boots.
};
int[] cape = {
6570, //Fire cape.
};
int[] gloves = {
7462, //Barrows Gloves.
};
p.getEquipment().replace(new Item(helms[RandomFunction.random(helms.length)]), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(shield[RandomFunction.random(shield.length)]), EquipmentContainer.SLOT_SHIELD);
p.getEquipment().replace(new Item(platebody[RandomFunction.random(platebody.length)]), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(platelegs[RandomFunction.random(platelegs.length)]), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(weapons2[RandomFunction.random(weapons2.length)]), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(amulets[RandomFunction.random(amulets.length)]), EquipmentContainer.SLOT_AMULET);
p.getEquipment().replace(new Item(boots[RandomFunction.random(boots.length)]), EquipmentContainer.SLOT_FEET);
p.getEquipment().replace(new Item(cape[RandomFunction.random(cape.length)]), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(gloves[RandomFunction.random(gloves.length)]), EquipmentContainer.SLOT_HANDS);
}
public static final int[] weapons2 = {
4151, //Whip
};
private static int generateCape() {
int[] capes = {
1052, //Legends Cape
6570, //Fire cape
};
return capes[RandomFunction.random(capes.length)];
}
private static int generateNecklace() {
int[] amulets = {
1712, //Glory
1725, //Strength ammy
6585, //fury
};
return amulets[RandomFunction.random(amulets.length)];
}
private static int generateGloves() {
int[] gloves = {
1059,
7462
};
return gloves[RandomFunction.random(gloves.length)];
}
private static int generateBoots() {
int[] boots = {
1061, //Leather boots.
1837, //Desert boots.
3105, //Climbing boots.
3791, //Fremmy boots.
11732,
};
return boots[RandomFunction.random(boots.length)];
}
public static void generateMinLevels(PvMBots p)
{
//Slayer so they can attack alls monsters
p.getSkills().setLevel(Skills.SLAYER, 99);
p.getSkills().setStaticLevel(Skills.SLAYER, 99);
int combatType = RandomFunction.getRandom(2);
p.getSkills().setLevel(Skills.HITPOINTS, 15);
p.getSkills().setStaticLevel(Skills.HITPOINTS, 15);
p.getInventory().add(new Item(329, 5));
switch(combatType)
{
case 0:
{
buildArcherStats(p);
buildArcherEquipment(p);
break;
}
case 1:
{
buildMeleeStats(p);
buildMeleeEquipment(p);
break;
}
case 2:
{
buildMageStats(p);
buildMagicEquipment(p);
setupWizard(p);
break;
}
default:
{
buildMeleeStats(p);
buildMeleeEquipment(p);
break;
}
}
}
public static void createDragonKiller(DragonKiller p)
{
p.getSkills().setLevel(Skills.SLAYER, 99);
p.getSkills().setStaticLevel(Skills.SLAYER, 99);
int combatType = RandomFunction.getRandom(2);
p.getSkills().setLevel(Skills.HITPOINTS, 55);
p.getSkills().setStaticLevel(Skills.HITPOINTS, 55);
switch(combatType)
{
case 0:
{
buildDragonArcherStats(p);
buildDragonArcherEquipment(p);
break;
}
case 1:
{
buildDragonMeleeStats(p);
buildDragonMeleeEquipment(p);
break;
}
default:
{
buildDragonMeleeStats(p);
buildDragonMeleeEquipment(p);
break;
}
}
}
public static void createNoob(NoobBot p)
{
p.getSkills().setLevel(Skills.SLAYER, 99);
p.getSkills().setStaticLevel(Skills.SLAYER, 99);
int combatType = RandomFunction.getRandom(3);
p.getSkills().setLevel(Skills.HITPOINTS, 10 + RandomFunction.getRandom(10));
p.getSkills().setStaticLevel(Skills.HITPOINTS, 10 + RandomFunction.getRandom(10));
p.getSkills().setLevel(Skills.DEFENCE, 1 + RandomFunction.getRandom(9));
p.getSkills().setStaticLevel(Skills.DEFENCE, 1 + RandomFunction.getRandom(9));
p.getInventory().add(new Item(329, 5));
switch(combatType)
{
case 0:
{
buildNoobArcherStats(p);
buildNoobArcherEquipment(p);
break;
}
case 1:
{
buildNoobMeleeStats(p);
buildNoobMeleeEquipment(p);
break;
}
case 2:
{
buildNoobMageStats(p);
buildNoobMagicEquipment(p);
setupWizard(p);
}
default:
{
buildNoobMeleeStats(p);
buildNoobMeleeEquipment(p);
break;
}
}
}
private static void buildArcherStats(PvMBots p)
{
p.getSkills().setLevel(Skills.RANGE, 10);
p.getSkills().setStaticLevel(Skills.RANGE, 10);
p.getSkills().setLevel(Skills.DEFENCE, 10);
p.getSkills().setStaticLevel(Skills.DEFENCE, 10);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildDragonArcherStats(DragonKiller p)
{
p.getSkills().setLevel(Skills.RANGE, 55);
p.getSkills().setStaticLevel(Skills.RANGE, 55);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildNoobArcherStats(NoobBot p)
{
p.getSkills().setLevel(Skills.RANGE, 1 + RandomFunction.getRandom(10));
p.getSkills().setStaticLevel(Skills.RANGE, 1 + RandomFunction.getRandom(10));
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
public static void buildMeleeStats(PvMBots p)
{
p.getSkills().setLevel(Skills.ATTACK, 10);
p.getSkills().setStaticLevel(Skills.ATTACK, 10);
p.getSkills().setLevel(Skills.STRENGTH, 10);
p.getSkills().setStaticLevel(Skills.STRENGTH, 10);
p.getSkills().setLevel(Skills.DEFENCE, 10);
p.getSkills().setStaticLevel(Skills.DEFENCE, 10);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
public static void buildDragonMeleeStats(DragonKiller p)
{
p.getSkills().setLevel(Skills.ATTACK, 55);
p.getSkills().setStaticLevel(Skills.ATTACK, 55);
p.getSkills().setLevel(Skills.STRENGTH, 55);
p.getSkills().setStaticLevel(Skills.STRENGTH, 55);
p.getSkills().setLevel(Skills.DEFENCE, 45);
p.getSkills().setStaticLevel(Skills.DEFENCE, 45);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildNoobMeleeStats(NoobBot p)
{
p.getSkills().setLevel(Skills.ATTACK, 1 + RandomFunction.getRandom(10));
p.getSkills().setStaticLevel(Skills.ATTACK, 1 + RandomFunction.getRandom(10));
p.getSkills().setLevel(Skills.STRENGTH, 1 + RandomFunction.getRandom(10));
p.getSkills().setStaticLevel(Skills.STRENGTH, 1 + RandomFunction.getRandom(10));
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildMageStats(PvMBots p)
{
p.getSkills().setLevel(Skills.MAGIC, 10);
p.getSkills().setStaticLevel(Skills.MAGIC, 10);
p.getSkills().setLevel(Skills.DEFENCE, 10);
p.getSkills().setStaticLevel(Skills.DEFENCE, 10);
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void buildNoobMageStats(NoobBot p)
{
p.getSkills().setLevel(Skills.MAGIC, 1 + RandomFunction.getRandom(10));
p.getSkills().setStaticLevel(Skills.MAGIC, 1 + RandomFunction.getRandom(10));
p.getSkills().updateCombatLevel();
p.getAppearance().sync();
}
private static void setupWizard(PvMBots p)
{
//final int SPELL_IDS[] = new int[] {1, 4, 6, 8, 10, 14, 17, 20, 24, 27, 33, 38, 45, 48, 52, 55 };
p.getProperties().setAutocastSpell(((CombatSpell) SpellBookManager.SpellBook.MODERN.getSpell(1)));
p.getInventory().add(new Item(556, 1000)); //Air runes
p.getInventory().add(new Item(558, 1000)); //Mind runes
}
private static void buildArcherEquipment(PvMBots p)
{
p.getEquipment().replace(new Item(1169), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(1129), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(1095), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(841), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884, 5000), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1478), EquipmentContainer.SLOT_AMULET);
}
private static void buildDragonArcherEquipment(DragonKiller p)
{
p.getEquipment().replace(new Item(1169), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(13483), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(1099), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(9185), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(1540), EquipmentContainer.SLOT_SHIELD);
p.getEquipment().replace(new Item(9140, 500), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(10498), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1478), EquipmentContainer.SLOT_AMULET);
}
private static void buildNoobArcherEquipment(PvMBots p)
{
int hats[] = {1169, 1169, 1139, 1137, 1153, 579};
int legs[] = {1095, 7366, 1075, 1087, 1095};
int chest[] = {1129, 1103, 1101, 1129, 1117, 577};
p.getEquipment().replace(new Item(hats[RandomFunction.getRandom(hats.length - 1)]), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(chest[RandomFunction.getRandom(chest.length - 1)]), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(legs[RandomFunction.getRandom(legs.length - 1)]), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(841), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884, 5000), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1478), EquipmentContainer.SLOT_AMULET);
}
private static void buildMeleeEquipment(PvMBots p)
{
p.getEquipment().replace(new Item(1153), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(1115), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(1067), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(1309), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1725), EquipmentContainer.SLOT_AMULET);
}
private static void buildDragonMeleeEquipment(DragonKiller p)
{
p.getEquipment().replace(new Item(1163), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(1127), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(1079), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(1333), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(1540), EquipmentContainer.SLOT_SHIELD);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1725), EquipmentContainer.SLOT_AMULET);
}
private static void buildNoobMeleeEquipment(PvMBots p)
{
int hats[] = {1169, 1169, 1139, 1137, 1153, 579};
int legs[] = {1095, 7366, 1075, 1087, 1095};
int chest[] = {1129, 1103, 1101, 1129, 1117, 577};
int weapons[] = {1307, 1321, 1375, 1203, 1239, 1267, 1293, 1323, 1335};
p.getEquipment().replace(new Item(hats[RandomFunction.getRandom(hats.length - 1)]), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(chest[RandomFunction.getRandom(chest.length - 1)]), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(legs[RandomFunction.getRandom(legs.length - 1)]), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(weapons[RandomFunction.getRandom(weapons.length - 1)]), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1725), EquipmentContainer.SLOT_AMULET);
}
private static void buildMagicEquipment(PvMBots p)
{
p.getEquipment().replace(new Item(579), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(577), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(1011), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(1389), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1727), EquipmentContainer.SLOT_AMULET);
}
private static void buildNoobMagicEquipment(PvMBots p)
{
int hats[] = {1169, 1169, 1139, 1137, 1153, 579};
int legs[] = {1095, 7366, 1075, 1087, 1095};
int chest[] = {1129, 1103, 1101, 1129, 1117, 577};
int weapons[] = {1379, 1383, 1385, 1387, 1389};
p.getEquipment().replace(new Item(hats[RandomFunction.getRandom(hats.length - 1)]), EquipmentContainer.SLOT_HAT);
p.getEquipment().replace(new Item(chest[RandomFunction.getRandom(chest.length - 1)]), EquipmentContainer.SLOT_CHEST);
p.getEquipment().replace(new Item(legs[RandomFunction.getRandom(legs.length - 1)]), EquipmentContainer.SLOT_LEGS);
p.getEquipment().replace(new Item(weapons[RandomFunction.getRandom(weapons.length - 1)]), EquipmentContainer.SLOT_WEAPON);
p.getEquipment().replace(new Item(884), EquipmentContainer.SLOT_ARROWS);
p.getEquipment().replace(new Item(1007), EquipmentContainer.SLOT_CAPE);
p.getEquipment().replace(new Item(1727), EquipmentContainer.SLOT_AMULET);
}
public static void spawn(Location loc)
{
final WildernessBot bot = PvPBotsBuilder.create(new Location(0, 0));
bot.teleport(loc);
bot.getAppearance().setGender(RandomFunction.random(3) == 1 ? Gender.FEMALE : Gender.MALE);
generateClass(bot);
}
private static void correctHitpointsStat(AIPlayer player) {
player.getSkills().setLevel(Skills.HITPOINTS, 10);
player.getSkills().setStaticLevel(Skills.HITPOINTS, 10);
player.getSkills().updateCombatLevel();
int rangedLevel = RandomFunction.random(80, 98);
int defenceLevel = RandomFunction.random(80, 98);
player.getSkills().setLevel(Skills.HITPOINTS, rangedLevel);
player.getSkills().setStaticLevel(Skills.HITPOINTS, rangedLevel);
player.getSkills().setLevel(Skills.HITPOINTS, defenceLevel);
player.getSkills().setStaticLevel(Skills.HITPOINTS, defenceLevel);
player.getSkills().updateCombatLevel();
player.getAppearance().sync();
}
public void RandomItem()
{
Item test = null;
ArrayList<Item> tests = new ArrayList<Item>();
for (int x = 0; x < 9999; x++)
test = new Item(x);
if (test.getDefinition().getEquipId() != 0)
tests.add(test);
}
}
@@ -0,0 +1,281 @@
package plugin.ai.wilderness;
import java.util.ArrayList;
import java.util.List;
import core.game.container.impl.EquipmentContainer;
import core.game.content.consumable.Consumable;
import core.game.content.consumable.Consumables;
import core.game.content.consumable.Food;
import core.game.content.consumable.effects.HealingEffect;
import core.game.node.entity.skill.Skills;
import core.game.interaction.Option;
import core.game.node.entity.Entity;
import core.game.node.entity.player.Player;
import plugin.ai.AIPlayer;
import core.game.node.entity.player.link.prayer.PrayerType;
import core.game.node.item.Item;
import core.game.world.map.Location;
import core.game.world.map.RegionManager;
import core.tools.RandomFunction;
public class WildernessBot extends AIPlayer {
public WildernessBot(Location l) {
super(l);
this.specWeapon = 1215;
this.normalWeapon = 4151;
this.getInventory().add(new Item(specWeapon));
// TODO Auto-generated constructor stub
}
public WildernessBot(Location l, int normalWeaponId, int specWeaponId) {
super(l);
this.specWeapon = specWeaponId;
this.normalWeapon = normalWeaponId;
this.getInventory().add(new Item(specWeaponId));
}
int tick = 0;
int movetimer = 0;
int agressiveTimer = 2;
int eatdelay = 2;
boolean fleeing = false;
boolean riskIt = false;
int specWeapon;// = new Item(1215);
int normalWeapon;// = new Item(4151);
Item chest = this.getEquipment().get(EquipmentContainer.SLOT_CHEST);
Item legs = this.getEquipment().get(EquipmentContainer.SLOT_LEGS);
Item helmet = this.getEquipment().get(EquipmentContainer.SLOT_HAT);
Item weapon = this.getEquipment().get(EquipmentContainer.SLOT_WEAPON);
Item shield = this.getEquipment().get(EquipmentContainer.SLOT_SHIELD);
public List<Entity> FindTargets(Entity entity, int radius) {
List<Entity> targets = new ArrayList<>();
for (Player player : RegionManager.getLocalPlayers(entity, radius)) { {
if (checkValidTargets(player))
targets.add(player);
}
}
if (targets.size() == 0)
return null;
return targets;
}
public boolean checkValidTargets(Player target){
if (!target.isActive())
{
return false;
}
if (!target.getProperties().isMultiZone() && target.inCombat()) {
return false;
}
if (target.inCombat())
{
return false;
}
return true;
}
public void AttackPlayersInRadius(Player bot, int radius)
{
if (bot.inCombat())
return;
List<Entity> players = FindTargets(bot, radius);
if (players == null)
{
return;
}
if (!(players.isEmpty()))
{
if (agressiveTimer <= 0)
bot.attack(players.get(RandomFunction.getRandom((players.size() - 1))));
return;
}
}
private Entity getTarget()
{
return this.getProperties().getCombatPulse().getVictim();
}
private void checkSpecialAttack()
{
Entity target = getTarget();
if (target == null)
return;
if (target.getSkills().getLifepoints() <= 75 && this.getSettings().getSpecialEnergy() >= 25)
{
//System.out.println("try special");
Item weapon = this.getItemById(specWeapon);
if (weapon != null)
{
//System.out.println("found weapon " + weapon.getName());
final Option option = weapon.getInteraction().get(1);
if (option == null)
{
System.out.println("Option not found");
return;
}
weapon.getInteraction().handleItemOption(this, option, this.getInventory());
this.getSettings().setSpecialToggled(true);
this.attack(target);
}
if (!this.getSettings().isSpecialToggled())
{
//System.out.println("toggle special");
this.getSettings().setSpecialToggled(true);
this.attack(target);
}
}
else
{
//System.out.println("try normal again");
Item weapon = this.getItemById(normalWeapon);
if (weapon != null)
{
//System.out.println("found weapon " + weapon.getName());
final Option option = weapon.getInteraction().get(1);
if (option == null)
{
System.out.println("Option not found");
return;
}
weapon.getInteraction().handleItemOption(this, option, this.getInventory());
this.getSettings().setSpecialToggled(false);
this.attack(target);
}
}
}
private void checkBarrowsSwitch()
{
System.out.println("WildernessBot: " + this.getSkills().getLifepoints());
Entity target = getTarget();
if (target == null)
return;
if (this.getSkills().getLifepoints() <= 35 && target.isPlayer() && target.getSkills().getLifepoints() <= 60)
{
this.getEquipment().replace(new Item(4720) ,EquipmentContainer.SLOT_CHEST);
this.getEquipment().replace(new Item(4722) ,EquipmentContainer.SLOT_LEGS);
this.getEquipment().replace(new Item(4716) ,EquipmentContainer.SLOT_HAT);
this.getEquipment().replace(new Item(4719) ,EquipmentContainer.SLOT_WEAPON);
this.getEquipment().replace(new Item(-1) ,EquipmentContainer.SLOT_SHIELD);
riskIt = true;
}
else if (riskIt)
{
this.getEquipment().replace(chest, EquipmentContainer.SLOT_CHEST);
this.getEquipment().replace(legs, EquipmentContainer.SLOT_LEGS);
this.getEquipment().replace(helmet, EquipmentContainer.SLOT_HAT);
this.getEquipment().replace(weapon, EquipmentContainer.SLOT_WEAPON);
this.getEquipment().replace(shield, EquipmentContainer.SLOT_SHIELD);
riskIt = false;
}
}
private void checkPrayer()
{
if (this.inCombat())
{
if (!(this.getPrayer().getActive().contains(PrayerType.PIETY)))
this.getPrayer().toggle((PrayerType.PIETY));
}
}
@Override
public void tick()
{
super.tick();
//checkBarrowsSwitch();
checkSpecialAttack();
checkPrayer();
//Despawn
if (this.getSkills().getLifepoints() == 0)
//this.teleport(new Location(500, 500));
//Despawning not being delayed causes 3 errors in the console
AIPlayer.deregister(this.getUid());
if (agressiveTimer != 0)
{
agressiveTimer--;
}
//Combat
if (!fleeing)
{
if (tick == 0)
{
if (!this.inCombat())
AttackPlayersInRadius(this, 5);
this.tick = 10;
}
else
this.tick--;
if (!this.inCombat())
{
if (movetimer == 0)
{
//if (this.FindTargets(this, 5) == null)
this.randomWalk(20, 20);
this.movetimer = 10;
}
else
movetimer --;
}
}
this.sendChat("Tik");
this.checkFlee(385);
this.eat(385);
//this.getPrayer().toggle()
}
public void checkFlee(int foodId)
{
if (this.getInventory().contains(foodId, 18) == false)
{
//todo: add tp
// if ()
this.getProperties().setRetaliating(false);
this.sendChat("Oi");
walkPos(this.getLocation().getLocalX(), this.getLocation().getLocalY() - 5 - RandomFunction.getRandom(5));
fleeing = true;
}
}
public void eat(int foodId)
{
if (riskIt)
return;
Item foodItem = new Item(foodId);
if (!(this.getInventory().contains(foodId, 1)))
return;
if((this.getSkills().getStaticLevel(Skills.HITPOINTS) >= this.getSkills().getLifepoints() * 3) && this.getInventory().containsItem(foodItem))
{
this.lock(3);
//this.animate(new Animation(829));
Item food = this.getInventory().getItem(foodItem);
Consumable consumable = Consumables.getConsumableById(food.getId());
if (consumable == null) {
consumable = new Food(new int[] {food.getId()}, new HealingEffect(1));
}
consumable .consume(food, this);
this.getProperties().getCombatPulse().delayNextAttack(3);
}
}
public void setMainWeapon(int weapon)
{
this.normalWeapon = weapon;
}
}
@@ -0,0 +1,26 @@
package plugin.drops;
import core.game.node.item.Item;
import core.plugin.Plugin;
import java.util.List;
public abstract class DropPlugin implements Plugin<Object> {
//the list of NPCs this plugin can effect, if left blank it effects all NPCs.
public int[] accepted_npcs;
//allows a super constructor to define the npcs
public DropPlugin(int... accepted_npcs){
this.accepted_npcs = accepted_npcs;
}
//necessary for the plugin framework, doesnt need to be changed ever.
@Override
public Object fireEvent(String identifier, Object... args) {
return null;
}
//defines an abstract method all drop plugins must implement
public abstract List<Item> handle();
}
@@ -0,0 +1,42 @@
package plugin.drops;
import core.game.node.item.Item;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class DropPlugins {
public static HashMap<Integer,List<DropPlugin>> plugins = new HashMap<>();
public static List<DropPlugin> globalPlugins = new ArrayList<>();
public static List<Item> getDrops(int npc_id){
List<Item> drops = new ArrayList<>();
List<DropPlugin> toHandle = plugins.get(npc_id);
if(toHandle != null) {
for (DropPlugin plugin : toHandle) {
drops.addAll(plugin.handle());
}
}
if(!globalPlugins.isEmpty()) {
for (DropPlugin plugin : globalPlugins) {
drops.addAll(plugin.handle());
}
}
return drops;
}
public static void register(DropPlugin plugin){
if(plugin.accepted_npcs.length > 0) {
Arrays.stream(plugin.accepted_npcs).forEach(id -> {
if (plugins.get(id) == null) {
List<DropPlugin> newlist = new ArrayList<>();
plugins.putIfAbsent(id, newlist);
}
plugins.get(id).add(plugin);
});
} else {
globalPlugins.add(plugin);
}
}
}
@@ -0,0 +1,45 @@
package plugin.drops.mystery_box;
import core.game.node.item.Item;
import core.plugin.Initializable;
import core.plugin.Plugin;
import core.plugin.PluginManifest;
import core.tools.Items;
import core.tools.RandomFunction;
import plugin.drops.DropPlugin;
import plugin.drops.DropPlugins;
import java.util.ArrayList;
import java.util.List;
@Initializable
@PluginManifest(name="MysteryBox")
public class MysteryBoxDropper extends DropPlugin {
//percentage chance of it dropping, between 1 and 100.
private int chance = 15;
List<Item> drops = new ArrayList<>(); //the list of dropped items
//standard way to initialize a drop plugin
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
DropPlugins.register(this);
return this;
}
//default constructor used, called when the plugin manager initializes this plugin.
//super() for a drop plugin simply means all NPCs can use this drop
public MysteryBoxDropper(){
super();
}
@Override
public List<Item> handle() {
boolean willDrop = RandomFunction.random(chance) == RandomFunction.random(chance);
drops.clear();
if(willDrop){
drops.add(new Item(Items.MYSTERY_BOX_6199));
}
return drops;
}
}
@@ -0,0 +1,84 @@
package plugin.drops.mystery_box;
import core.cache.def.impl.ItemDefinition;
import core.game.interaction.OptionHandler;
import core.game.node.Node;
import core.game.node.entity.player.Player;
import core.game.node.item.Item;
import core.game.node.item.WeightedChanceItem;
import core.plugin.Plugin;
import core.plugin.PluginManifest;
import core.tools.Items;
import core.tools.RandomFunction;
import core.plugin.Initializable;
import core.tools.StringUtils;
/**
* Handles the mystery box item.
* @author Ceikry
*/
@Initializable
@PluginManifest(name="MysteryBox")
public final class MysteryBoxPlugin extends OptionHandler {
/**
* The rewards recieved from a mystery box.
*/
private static final WeightedChanceItem[] REWARDS = new WeightedChanceItem[] {
new WeightedChanceItem(Items.UNCUT_DIAMOND_1617,1,10),
new WeightedChanceItem(Items.UNCUT_RUBY_1619,1,50),
new WeightedChanceItem(Items.UNCUT_SAPPHIRE_1623,1,60),
new WeightedChanceItem(Items.UNCUT_JADE_1627,1,150),
new WeightedChanceItem(Items.UNCUT_DRAGONSTONE_1631,1,1),
new WeightedChanceItem(Items.MOLTEN_GLASS_1776,25,5),
new WeightedChanceItem(Items.UNCUT_EMERALD_1621,1,60),
new WeightedChanceItem(Items.COINS_995,25,30),
new WeightedChanceItem(Items.COINS_995,250,50),
new WeightedChanceItem(Items.COINS_995,10,80),
new WeightedChanceItem(0,1,100),
new WeightedChanceItem(Items.UNCUT_OPAL_1625,1,150),
new WeightedChanceItem(Items.VIAL_OF_WATER_228,10,25),
new WeightedChanceItem(Items.VARROCK_TELEPORT_8007,10,5),
new WeightedChanceItem(Items.FALADOR_TELEPORT_8009,10,5)
};
@Override
public Plugin<Object> newInstance(Object arg) throws Throwable {
ItemDefinition.forId(6199).getHandlers().put("option:open", this);
return this;
}
@Override
public boolean handle(Player player, Node node, String option) {
final Item item = RandomFunction.rollWeightedChanceTable(REWARDS);
String name = item.getName().toLowerCase();
if(item.getId() == 0){
name = "nothing";
}
final Item box = (Item) node;
if (player.getInventory().remove(box, box.getSlot(), true)) {
String message;
player.lock(1);
if(name.equals("notithing")){
message = "Inside the box you find nothing :(";
} else {
if(item.getAmount() > 1 && item.getId() != 995){
name = name + "s";
}
message = "Inside the box you find " + (item.getAmount() > 1 ? "some" : (StringUtils.isPlusN(name) ? "an" : "a")) + " " + name + "!";
}
player.sendMessage(message);
if(item.getId() != 0)
player.getInventory().add(item);
}
return true;
}
@Override
public boolean isWalk() {
return false;
}
}
@@ -0,0 +1,6 @@
/**
* Holds all the plugin classes.
*
* @author Emperor
*/
package plugin;