forked from 2009Scape/Server
Made Pest Control bots amazing
This commit is contained in:
parent
236fec4824
commit
68da747944
8 changed files with 146 additions and 62 deletions
|
|
@ -266,5 +266,4 @@ public abstract class Node {
|
|||
public void setRenderable(boolean renderable) {
|
||||
this.renderable = renderable;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -133,12 +133,16 @@ public class AIPlayer extends Player {
|
|||
{
|
||||
Pathfinder.find(this, this.getLocation().transform(RandomFunction.random(radiusX, (radiusX * -1)), RandomFunction.random(radiusY, (radiusY * -1)), 0), false, Pathfinder.SMART).walk(this);
|
||||
}
|
||||
|
||||
|
||||
protected 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)
|
||||
|
|
@ -146,8 +150,8 @@ public class AIPlayer extends Player {
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Item getItemById(int id)
|
||||
|
||||
public Item getItemById(int id)
|
||||
{
|
||||
for (int i = 0; i < 28; i++)
|
||||
{
|
||||
|
|
@ -160,7 +164,7 @@ public class AIPlayer extends Player {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Node> getNodeInRange(int range, int entry)
|
||||
{
|
||||
int meX = this.getLocation().getX();
|
||||
|
|
@ -175,24 +179,24 @@ public class AIPlayer extends Player {
|
|||
Node node = RegionManager.getObject(0, meX + x, meY + y);
|
||||
if (node != null)
|
||||
if (node.getId() == entry)
|
||||
nodes.add(node);
|
||||
nodes.add(node);
|
||||
Node node2 = RegionManager.getObject(0, meX + x, meY - y);
|
||||
if (node2 != null)
|
||||
if (node2.getId() == entry)
|
||||
nodes.add(node2);
|
||||
nodes.add(node2);
|
||||
Node node3 = RegionManager.getObject(0, meX - x, meY + y);
|
||||
if (node3 != null)
|
||||
if (node3.getId() == entry)
|
||||
nodes.add(node3);
|
||||
nodes.add(node3);
|
||||
Node node4 = RegionManager.getObject(0, meX - x, meY - y);
|
||||
if (node4 != null)
|
||||
if (node4.getId() == entry)
|
||||
nodes.add(node4);
|
||||
nodes.add(node4);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
||||
private ArrayList<Node> getNodeInRange(int range, List<Integer> entrys)
|
||||
{
|
||||
int meX = this.getLocation().getX();
|
||||
|
|
@ -207,24 +211,24 @@ public class AIPlayer extends Player {
|
|||
Node node = RegionManager.getObject(0, meX + x, meY + y);
|
||||
if (node != null)
|
||||
if (entrys.contains(node.getId()))
|
||||
nodes.add(node);
|
||||
nodes.add(node);
|
||||
Node node2 = RegionManager.getObject(0, meX + x, meY - y);
|
||||
if (node2 != null)
|
||||
if (entrys.contains(node2.getId()))
|
||||
nodes.add(node2);
|
||||
nodes.add(node2);
|
||||
Node node3 = RegionManager.getObject(0, meX - x, meY + y);
|
||||
if (node3 != null)
|
||||
if (entrys.contains(node3.getId()))
|
||||
nodes.add(node3);
|
||||
nodes.add(node3);
|
||||
Node node4 = RegionManager.getObject(0, meX - x, meY - y);
|
||||
if (node4 != null)
|
||||
if (entrys.contains(node4.getId()))
|
||||
nodes.add(node4);
|
||||
nodes.add(node4);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
|
||||
public Node getClosestNodeWithEntry(int range, int entry)
|
||||
{
|
||||
ArrayList<Node> nodeList = getNodeInRange(range, entry);
|
||||
|
|
@ -236,7 +240,7 @@ public class AIPlayer extends Player {
|
|||
Node node = getClosestNodeinNodeList(nodeList);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
public Node getClosestNodeWithEntry(int range, List<Integer> entrys)
|
||||
{
|
||||
ArrayList<Node> nodeList = getNodeInRange(range, entrys);
|
||||
|
|
@ -248,7 +252,7 @@ public class AIPlayer extends Player {
|
|||
Node node = getClosestNodeinNodeList(nodeList);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
public Node getClosesCreature(int radius) {
|
||||
int distance = radius + 1;
|
||||
Node npcReturn = null;
|
||||
|
|
@ -261,7 +265,7 @@ public class AIPlayer extends Player {
|
|||
}
|
||||
return npcReturn;
|
||||
}
|
||||
|
||||
|
||||
public Node getClosesCreature(int radius, int entry) {
|
||||
int distance = radius + 1;
|
||||
Node npcReturn = null;
|
||||
|
|
@ -276,7 +280,7 @@ public class AIPlayer extends Player {
|
|||
}
|
||||
return npcReturn;
|
||||
}
|
||||
|
||||
|
||||
public Node getClosesCreature(int radius, ArrayList<Integer> entrys) {
|
||||
int distance = radius + 1;
|
||||
Node npcReturn = null;
|
||||
|
|
@ -291,7 +295,7 @@ public class AIPlayer extends Player {
|
|||
}
|
||||
return npcReturn;
|
||||
}
|
||||
|
||||
|
||||
private Node getClosestNodeinNodeList(ArrayList<Node> nodes)
|
||||
{
|
||||
if (nodes.isEmpty())
|
||||
|
|
@ -299,7 +303,7 @@ public class AIPlayer extends Player {
|
|||
//System.out.println("nodelist empty");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
double distance = 0;
|
||||
Node nodeReturn = null;
|
||||
for (Node node : nodes)
|
||||
|
|
@ -387,5 +391,4 @@ public class AIPlayer extends Player {
|
|||
public void setControler(Player controler) {
|
||||
this.controler = controler;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -6,14 +6,21 @@ import org.crandor.game.node.entity.player.ai.pvmbots.PvMBots;
|
|||
import org.crandor.game.node.entity.player.link.prayer.*;
|
||||
import org.crandor.game.world.map.Location;
|
||||
import org.crandor.net.packet.in.InteractionPacket;
|
||||
import org.crandor.tools.RandomFunction;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static plugin.activity.pestcontrol.PestControlHelper.*;
|
||||
|
||||
public class PestControlTestBot extends PvMBots {
|
||||
|
||||
private int tick = 0;
|
||||
private int combatMoveTimer = 0;
|
||||
private int movetimer = 0;
|
||||
|
||||
private int randomType;
|
||||
private BoatInfo myBoat = BoatInfo.NOVICE;
|
||||
|
||||
enum State {
|
||||
OUTSIDE_GANGPLANK,
|
||||
WAITING_IN_BOAT,
|
||||
|
|
@ -23,7 +30,7 @@ public class PestControlTestBot extends PvMBots {
|
|||
|
||||
public PestControlTestBot(String name, Location l) {
|
||||
super(name, legitimizeLocation(l));
|
||||
// TODO Auto-generated constructor stub
|
||||
randomType = new Random().nextInt(100);
|
||||
}
|
||||
|
||||
private static Location legitimizeLocation(Location l) {
|
||||
|
|
@ -34,24 +41,29 @@ public class PestControlTestBot extends PvMBots {
|
|||
public void tick()
|
||||
{
|
||||
super.tick();
|
||||
movetimer --;
|
||||
|
||||
State state = getState();
|
||||
this.setCustomState(String.valueOf(state));
|
||||
|
||||
switch (state)
|
||||
if (movetimer <= 0)
|
||||
{
|
||||
case GET_TO_PC:
|
||||
getToPC();
|
||||
break;
|
||||
case OUTSIDE_GANGPLANK:
|
||||
enterBoat();
|
||||
break;
|
||||
case WAITING_IN_BOAT:
|
||||
idleInBoat();
|
||||
break;
|
||||
case NPC_COMBAT:
|
||||
attackNPCs();
|
||||
break;
|
||||
movetimer = 0;
|
||||
State state = getState();
|
||||
this.setCustomState(String.valueOf(state));
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case GET_TO_PC:
|
||||
getToPC();
|
||||
break;
|
||||
case OUTSIDE_GANGPLANK:
|
||||
enterBoat();
|
||||
break;
|
||||
case WAITING_IN_BOAT:
|
||||
idleInBoat();
|
||||
break;
|
||||
case NPC_COMBAT:
|
||||
attackNPCs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,32 +107,66 @@ public class PestControlTestBot extends PvMBots {
|
|||
|
||||
if (!this.inCombat())
|
||||
{
|
||||
if (movetimer == 0)
|
||||
if (combatMoveTimer <= 0)
|
||||
{
|
||||
if (this.FindTargets(this, 5) == null)
|
||||
this.randomWalk(5, 5);
|
||||
this.movetimer = 5;
|
||||
this.combatMoveTimer = 5;
|
||||
}
|
||||
else
|
||||
movetimer --;
|
||||
}
|
||||
}
|
||||
|
||||
private int insideBoatWalks = 3;
|
||||
private void idleInBoat() {
|
||||
if (randomType < 15) //He's the type of guy to walk around the boat
|
||||
{
|
||||
if (new Random().nextInt(insideBoatWalks) <= 1)
|
||||
{
|
||||
insideBoatWalks *= 1.5;
|
||||
if (new Random().nextInt(7) == 1)
|
||||
{
|
||||
this.walkToPosSmart(new Location(2660, 2638));
|
||||
} else {
|
||||
this.walkToPosSmart(myBoat.boatBorder.getRandomLoc());
|
||||
}
|
||||
}
|
||||
if (new Random().nextInt(3) == 1)
|
||||
{
|
||||
insideBoatWalks += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void enterBoat() {
|
||||
Node test = getClosestNodeWithEntry(15, NOVICE_GANGPLANK);
|
||||
if (test != null) {
|
||||
if (!this.getLocation().equals(new Location(2660, 2638)))
|
||||
InteractionPacket.handleObjectInteraction(this, 0, test.getLocation(), test.getId());
|
||||
} else {
|
||||
System.out.println("Warning: " + this.getName() + " can't find the gangplank!");
|
||||
if (new Random().nextInt(3) <= 1) //Don't join instantly
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (randomType > 20 && new Random().nextInt(4) == 0) //Idle outside ladder
|
||||
{
|
||||
if (new Random().nextInt(16) == 0)
|
||||
{
|
||||
this.walkToPosSmart(myBoat.outsideBoatBorder.getRandomLoc());
|
||||
movetimer += RandomFunction.normalPlusWeightRandDist(400, 200);
|
||||
//System.out.println("Rare movetimer set on " + this.getName());
|
||||
}
|
||||
movetimer = RandomFunction.normalPlusWeightRandDist(100, 50);
|
||||
//System.out.println("Set movetimer to " + movetimer + " on " + this.getName());
|
||||
return;
|
||||
}
|
||||
if (randomType < 60 && new Random().nextInt(6) == 1) //Missclick the ladder
|
||||
{
|
||||
movetimer = new Random().nextInt(2);
|
||||
this.walkToPosSmart(myBoat.outsideBoatBorder.getWeightedRandomLoc(3));
|
||||
return;
|
||||
}
|
||||
Node test = getClosestNodeWithEntry(15, myBoat.ladderId);
|
||||
InteractionPacket.handleObjectInteraction(this, 0, test.getLocation(), test.getId());
|
||||
insideBoatWalks = 3;
|
||||
}
|
||||
|
||||
private void getToPC() {
|
||||
Node test = getClosestNodeWithEntry(15, NOVICE_GANGPLANK);
|
||||
Node test = getClosestNodeWithEntry(25, myBoat.ladderId);
|
||||
if (test == null)
|
||||
{
|
||||
this.teleport(PestControlIslandLocation);
|
||||
|
|
|
|||
|
|
@ -11,16 +11,12 @@ import org.crandor.game.content.global.consumable.Food;
|
|||
import org.crandor.game.content.skill.Skills;
|
||||
import org.crandor.game.interaction.Option;
|
||||
import org.crandor.game.node.entity.Entity;
|
||||
import org.crandor.game.node.entity.combat.equipment.Weapon;
|
||||
import org.crandor.game.node.entity.npc.NPC;
|
||||
import org.crandor.game.node.entity.player.Player;
|
||||
import org.crandor.game.node.entity.player.ai.AIPlayer;
|
||||
import org.crandor.game.node.entity.player.link.prayer.PrayerType;
|
||||
import org.crandor.game.node.item.Item;
|
||||
import org.crandor.game.world.map.Location;
|
||||
import org.crandor.game.world.map.RegionManager;
|
||||
import org.crandor.game.world.update.flag.context.ChatMessage;
|
||||
import org.crandor.game.world.update.flag.player.ChatFlag;
|
||||
import org.crandor.tools.RandomFunction;
|
||||
|
||||
public class WildernessBot extends AIPlayer {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@ package org.crandor.game.world.map.zone;
|
|||
|
||||
import org.crandor.game.node.Node;
|
||||
import org.crandor.game.world.map.Location;
|
||||
import org.crandor.tools.RandomFunction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Represents the borders of a zone.
|
||||
|
|
@ -210,6 +212,20 @@ public final class ZoneBorders {
|
|||
return exceptions;
|
||||
}
|
||||
|
||||
public Location getWeightedRandomLoc(int intensity)
|
||||
{
|
||||
int x = northEastX - southWestX == 0 ? southWestX : RandomFunction.normalRandDist(northEastX - southWestX, intensity) + southWestX;
|
||||
int y = northEastY - southWestY == 0 ? southWestY : RandomFunction.normalRandDist(northEastY - southWestY, intensity) + southWestY;
|
||||
return new Location(x, y);
|
||||
}
|
||||
|
||||
public Location getRandomLoc() {
|
||||
int x = northEastX - southWestX == 0 ? southWestX : new Random().nextInt(northEastX - southWestX) + southWestX;
|
||||
int y = northEastY - southWestY == 0 ? southWestY : new Random().nextInt(northEastY - southWestY) + southWestY;
|
||||
//System.out.println("Generated x,y " + x + ", " + y);
|
||||
return new Location(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an exception.
|
||||
* @param exception The exception to add.
|
||||
|
|
|
|||
|
|
@ -88,6 +88,29 @@ public class RandomFunction {
|
|||
return RANDOM.nextInt(maxValue);
|
||||
}
|
||||
|
||||
public static int nextInt(int val)
|
||||
{
|
||||
return RANDOM.nextInt(val);
|
||||
}
|
||||
|
||||
public static int normalRandDist(int i, int intensity) {
|
||||
int sum = 0;
|
||||
for (int j = 0; j < intensity; j++) {
|
||||
sum += RANDOM.nextInt(i);
|
||||
}
|
||||
return sum/intensity;
|
||||
}
|
||||
|
||||
public static int normalRandDist(int i) {
|
||||
return (RANDOM.nextInt(i) + RANDOM.nextInt(i))/2;
|
||||
}
|
||||
|
||||
public static int normalPlusWeightRandDist(int val, int weight)
|
||||
{
|
||||
int normalDistRand = (RANDOM.nextInt(val) + RANDOM.nextInt(val))/2;
|
||||
return normalDistRand/2 + weight < val ? normalDistRand/2 + weight : normalPlusWeightRandDist(val, weight - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a chance item.
|
||||
* @param items the items.
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
|
|||
public boolean pulse() {
|
||||
sessions.removeIf(session -> session != null && session.update());
|
||||
ticks++;
|
||||
if (waitingPlayers.size() >= MAX_TEAM_SIZE && ticks < 475);
|
||||
if (waitingPlayers.size() >= MAX_TEAM_SIZE && ticks < 475)
|
||||
{
|
||||
ticks = 485;
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
|
|||
updateTime(p);
|
||||
}
|
||||
}
|
||||
if (ticks >= 500) { // 500
|
||||
if (ticks >= 500) {
|
||||
if (waitingPlayers.size() >= MIN_TEAM_SIZE) {
|
||||
PestControlActivityPlugin.this.start();
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -11,21 +11,22 @@ public class PestControlHelper {
|
|||
|
||||
public enum BoatInfo
|
||||
{
|
||||
NOVICE(new ZoneBorders(2660, 2638, 2663, 2643), new ZoneBorders(2657, 2638, 2657, 2641)),
|
||||
INTERMEDIATE(new ZoneBorders(2638, 2642, 2641, 2647), new ZoneBorders(2644, 2642, 2644, 2646)),
|
||||
VERTERAN(new ZoneBorders(2632, 2649, 2635, 2654), new ZoneBorders(2639, 2652, 2638, 2655));
|
||||
NOVICE(new ZoneBorders(2660, 2638, 2664, 2644), new ZoneBorders(2657, 2637, 2657, 2643), 14315),
|
||||
INTERMEDIATE(new ZoneBorders(2638, 2642, 2641, 2647), new ZoneBorders(2644, 2642, 2644, 2646), 25629),
|
||||
VERTERAN(new ZoneBorders(2632, 2649, 2635, 2654), new ZoneBorders(2639, 2652, 2638, 2655), 25632);
|
||||
|
||||
BoatInfo(ZoneBorders boatBorder, ZoneBorders outsideBoatBorder)
|
||||
BoatInfo(ZoneBorders boatBorder, ZoneBorders outsideBoatBorder, int ladderId)
|
||||
{
|
||||
this.boatBorder = boatBorder;
|
||||
this.outsideBoatBorder = outsideBoatBorder;
|
||||
this.ladderId = ladderId;
|
||||
}
|
||||
|
||||
public ZoneBorders boatBorder;
|
||||
public ZoneBorders outsideBoatBorder;
|
||||
public int ladderId;
|
||||
}
|
||||
|
||||
public static final int NOVICE_GANGPLANK = 14315;
|
||||
public static List<Integer> GATE_ENTRIES = Arrays.asList(14233, 14235);
|
||||
|
||||
public static final Location PestControlIslandLocation = Location.create(2659, 2649, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue