Pest control fixes & pc bot modularization

This commit is contained in:
dginovker 2019-06-15 20:41:29 -04:00
parent 0ecae80828
commit 236fec4824
10 changed files with 172 additions and 56 deletions

View file

@ -298,6 +298,11 @@ public class Player extends Entity {
*/
protected SkillerTasks skillTasks = new SkillerTasks();
/**
* A custom state for bot debugging
*/
private String customState = "";
/**
* Constructs a new {@code Player} {@code Object}.
* @param details The player's details.
@ -1261,5 +1266,12 @@ public class Player extends Entity {
}
public String getCustomState() {
return customState;
}
public void setCustomState(String state)
{
this.customState = state;
}
}

View file

@ -13,7 +13,6 @@ import org.crandor.game.interaction.Option;
import org.crandor.game.interaction.OptionHandler;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.Entity;
import org.crandor.game.node.entity.combat.CombatStyle;
import org.crandor.game.node.entity.npc.NPC;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.node.entity.player.info.PlayerDetails;
@ -194,7 +193,7 @@ public class AIPlayer extends Player {
return nodes;
}
private ArrayList<Node> getNodeInRange(int range, ArrayList<Integer> entrys)
private ArrayList<Node> getNodeInRange(int range, List<Integer> entrys)
{
int meX = this.getLocation().getX();
int meY = this.getLocation().getY();
@ -238,7 +237,7 @@ public class AIPlayer extends Player {
return node;
}
public Node getClosestNodeWithEntry(int range, ArrayList<Integer> entrys)
public Node getClosestNodeWithEntry(int range, List<Integer> entrys)
{
ArrayList<Node> nodeList = getNodeInRange(range, entrys);
if (nodeList.isEmpty())

View file

@ -1,14 +1,11 @@
package org.crandor.game.node.entity.player.ai.minigamebots;
import java.util.ArrayList;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.node.Node;
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 plugin.activity.pestcontrol.PCLanderZone;
import static plugin.activity.pestcontrol.PestControlHelper.*;
@ -16,37 +13,68 @@ public class PestControlTestBot extends PvMBots {
private int tick = 0;
private int movetimer = 0;
enum State {
OUTSIDE_GANGPLANK,
WAITING_IN_BOAT,
NPC_COMBAT,
GET_TO_PC
}
public PestControlTestBot(String name, Location l) {
super(name, legitimizeLocation(l));
// TODO Auto-generated constructor stub
}
private static Location legitimizeLocation(Location l) {
return PCLanderZone.landerContainsLoc(l) ? new Location(2657, 2639, 0) : l;
return landerContainsLoc(l) ? new Location(2657, 2639, 0) : l;
}
@Override
public void tick()
{
super.tick();
Node test = getClosestNodeWithEntry(15, NOVICE_GANGPLANK);
if (test != null) {
int x = test.getLocation().getX();
int y = test.getLocation().getY();
if (!this.getLocation().equals(new Location(2660, 2638)))
InteractionPacket.handleObjectInteraction(this, 0, x, y, test.getId());
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;
}
ArrayList<Integer> doorEntrys = new ArrayList<Integer>();
doorEntrys.add(14233);
doorEntrys.add(14235);
test = getClosestNodeWithEntry(5, doorEntrys);
}
private State getState() {
if (landerContainsLoc(this.getLocation()))
{
return State.WAITING_IN_BOAT;
}
if (isInPestControlInstance(this))
{
return State.NPC_COMBAT;
}
if (outsideGangplankContainsLoc(this.getLocation()))
{
return State.OUTSIDE_GANGPLANK;
}
return State.GET_TO_PC;
}
private void attackNPCs() {
Node test = getClosestNodeWithEntry(5, GATE_ENTRIES);
if (!this.inCombat() && test != null) {
int x = test.getLocation().getX();
int y = test.getLocation().getY();
InteractionPacket.handleObjectInteraction(this, 0, x, y, test.getId());
InteractionPacket.handleObjectInteraction(this, 0, test.getLocation(), test.getId());
}
//Npc Combat
@ -56,26 +84,49 @@ public class PestControlTestBot extends PvMBots {
AttackNpcsInRadius(this, 15);
this.tick = 10;
}
else
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);
if (!this.inCombat())
{
if (movetimer == 0)
{
if (this.FindTargets(this, 5) == null)
this.randomWalk(5, 5);
this.movetimer = 5;
this.movetimer = 5;
}
else
else
movetimer --;
}
}
private void idleInBoat() {
}
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!");
}
}
private void getToPC() {
Node test = getClosestNodeWithEntry(15, NOVICE_GANGPLANK);
if (test == null)
{
this.teleport(PestControlIslandLocation);
} else {
InteractionPacket.handleObjectInteraction(this, test);
}
}
}

View file

@ -4,22 +4,12 @@ import org.crandor.game.world.map.Location;
import java.util.ArrayList;
import org.crandor.cache.def.impl.ObjectDefinition;
import org.crandor.game.content.skill.Skills;
import org.crandor.game.content.skill.free.gather.*;
import org.crandor.game.interaction.Interaction;
import org.crandor.game.interaction.Option;
import org.crandor.game.interaction.OptionHandler;
import org.crandor.game.node.Node;
import org.crandor.game.node.entity.player.ai.AIPlayer;
import org.crandor.game.node.item.Item;
import org.crandor.game.node.object.GameObject;
import org.crandor.game.world.map.RegionManager;
import org.crandor.game.world.map.path.Pathfinder;
import org.crandor.net.packet.in.InteractionPacket;
import org.crandor.tools.RandomFunction;
import plugin.skill.gather.*;
public class SkillingBot extends AIPlayer{

View file

@ -4,6 +4,7 @@ import org.crandor.ServerConstants;
import org.crandor.game.interaction.Interaction;
import org.crandor.game.interaction.MovementPulse;
import org.crandor.game.interaction.Option;
import org.crandor.game.node.Node;
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;
@ -178,6 +179,27 @@ public final class InteractionPacket implements IncomingPacket {
npc.getInteraction().handle(player, option);
}
/**
* Handles Node interaction with the first index
* @param player The interacting player.
* @param n The node to interact with.
*/
public static void handleObjectInteraction(final Player player, Node n)
{
handleObjectInteraction(player, 0, n.getLocation(), n.getId());
}
/**
* Handles object interaction
* @param player The interacting player.
* @param optionIndex The option index.
* @param l The (x,y) location of the object.
* @param objectId The object id.
*/
public static void handleObjectInteraction(final Player player, int optionIndex, Location l, int objectId) {
handleObjectInteraction(player, optionIndex, l.getX(), l.getY(), objectId);
}
/**
* Handles object interaction
* @param player The interacting player.

View file

@ -90,20 +90,15 @@ public final class PCLanderZone extends MapZone {
return super.leave(e, logout);
}
private static ZoneBorders boatA = new ZoneBorders(2659, 2637, 2664, 2664); //I should probably find the real names
private static ZoneBorders boatB = new ZoneBorders(2637, 2641, 2642, 2648);
private static ZoneBorders boatC = new ZoneBorders(2631, 2648, 2636, 2655);
@Override
public void configure() {
ZoneBorders boatA = new ZoneBorders(2659, 2637, 2664, 2664);
ZoneBorders boatB = new ZoneBorders(2637, 2641, 2642, 2648);
ZoneBorders boatC = new ZoneBorders(2631, 2648, 2636, 2655);
register(boatA);
register(boatB);
register(boatC);
}
public static boolean landerContainsLoc(Location l)
{
return boatA.insideBorder(l) || boatB.insideBorder(l) || boatC.insideBorder(l);
}
}

View file

@ -40,7 +40,7 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
/**
* The minimum team size.
*/
protected static final int MIN_TEAM_SIZE = GameWorld.getSettings().isDevMode() ? 1 : 5;
protected static final int MIN_TEAM_SIZE = 5; //GameWorld.getSettings().isDevMode() ? 1 : 5;
/**
* The maximum team size.
@ -76,11 +76,11 @@ public final class PestControlActivityPlugin extends ActivityPlugin {
public boolean pulse() {
sessions.removeIf(session -> session != null && session.update());
ticks++;
if (waitingPlayers.size() >= MAX_TEAM_SIZE && ticks < 575)
if (waitingPlayers.size() >= MAX_TEAM_SIZE && ticks < 475);
{
ticks = 585;
ticks = 485;
}
if ((ticks < 450 && ticks % 100 == 0) || (ticks % 50 == 0) || ticks == 596) {
if ((ticks < 450 && ticks % 100 == 0) || (ticks % 50 == 0) || ticks == 485) {
for (Player p : waitingPlayers) {
updateTime(p);
}

View file

@ -1,5 +1,53 @@
package plugin.activity.pestcontrol;
import org.crandor.game.node.entity.player.Player;
import org.crandor.game.world.map.Location;
import org.crandor.game.world.map.zone.ZoneBorders;
import java.util.Arrays;
import java.util.List;
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));
BoatInfo(ZoneBorders boatBorder, ZoneBorders outsideBoatBorder)
{
this.boatBorder = boatBorder;
this.outsideBoatBorder = outsideBoatBorder;
}
public ZoneBorders boatBorder;
public ZoneBorders outsideBoatBorder;
}
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);
public static boolean isInPestControlInstance(Player p)
{
return p.getAttribute("pc_zeal") != null;
}
public static boolean landerContainsLoc(Location l)
{
for (BoatInfo i : BoatInfo.values())
if (i.boatBorder.insideBorder(l))
return true;
return false;
}
public static boolean outsideGangplankContainsLoc(Location l)
{
for (BoatInfo i : BoatInfo.values())
if (i.outsideBoatBorder.insideBorder(l))
return true;
return false;
}
}

View file

@ -160,8 +160,7 @@ public final class PestControlSession {
/**
* Sends a string on the interface to all players in the region.
* @param message The message to send.
* @param child The child id.
* @param value The message value to send.
*/
public void sendConfig(int value) {
for (Player p : region.getPlanes()[0].getPlayers()) {

View file

@ -53,11 +53,11 @@ public class PlayerExamineInterfacePlugin extends ComponentPlugin {
player.getPacketDispatch().sendString("Total Level -> ", 31, 9);
player.getPacketDispatch().sendString("Inventory items -> ", 31, 10);
player.getPacketDispatch().sendString("Inventory value -> ", 31, 16);
player.getPacketDispatch().sendString("Bank value-> ", 31, 19);
player.getPacketDispatch().sendString("Custom state-> ", 31, 19);
player.getPacketDispatch().sendString("" + examined.getSkills().getTotalLevel(), 31, 11);
player.getPacketDispatch().sendString("" + examined.getInventory().itemCount(), 31, 12);
player.getPacketDispatch().sendString("" + examined.getInventory().getWealth(), 31, 17);
player.getPacketDispatch().sendString("" + examined.getBank().getWealth(), 31, 20);
player.getPacketDispatch().sendString("" + examined.getCustomState(), 31, 20);
player.getPacketDispatch().sendString("Close", 31, 5);
}
}