forked from 2009Scape/Server
Script API fixes
This commit is contained in:
parent
16dceba4bc
commit
0d31085a36
6 changed files with 59 additions and 17 deletions
|
|
@ -61,23 +61,30 @@ public final class Interaction {
|
|||
* @param option The option used.
|
||||
*/
|
||||
public void handle(final Player player, final Option option) {
|
||||
System.out.println("In handle");
|
||||
if (player.getLocks().isInteractionLocked()) {
|
||||
System.out.println("Locked!");
|
||||
return;
|
||||
}
|
||||
boolean hasHandler = option.getHandler() != null;
|
||||
String pulseType = "interaction:" + option.getName() + ":" + node.hashCode();
|
||||
boolean walk = hasHandler && option.getHandler().isWalk();
|
||||
System.out.println("Which one will he take?");
|
||||
if (!walk && hasHandler && option.getHandler().isWalk(player, node)) {
|
||||
walk = true;
|
||||
}
|
||||
if (!hasHandler || walk) {
|
||||
handleWalkOption(player, option, pulseType);
|
||||
System.out.println("A");
|
||||
} else if (hasHandler) {
|
||||
player.debug("Option handler being used=" + option.getHandler().getClass().getSimpleName());
|
||||
handleDefaultOption(player, option, pulseType);
|
||||
System.out.println("D");
|
||||
} else {
|
||||
player.getPulseManager().runUnhandledAction(player, pulseType);
|
||||
System.out.println("C");
|
||||
}
|
||||
System.out.println("Done");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.crandor.game.world.repository.Repository;
|
|||
|
||||
public class GeneralBotCreator {
|
||||
|
||||
//org/crandor/net/packet/in/InteractionPacket.java <<< This is a very useful class for learning to code bots
|
||||
public GeneralBotCreator(String botName, Location loc, Script botScript)
|
||||
{
|
||||
AIPlayer bot = AIPBuilder.create(botName, loc);
|
||||
|
|
|
|||
|
|
@ -1,34 +1,44 @@
|
|||
package org.crandor.game.node.entity.player.ai.general;
|
||||
|
||||
import org.crandor.game.interaction.MovementPulse;
|
||||
import org.crandor.game.node.Node;
|
||||
import org.crandor.game.node.entity.Entity;
|
||||
import org.crandor.game.node.entity.npc.NPC;
|
||||
import org.crandor.game.node.entity.player.Player;
|
||||
import org.crandor.game.node.object.GameObject;
|
||||
import org.crandor.game.world.map.Location;
|
||||
import org.crandor.game.world.map.Point;
|
||||
import org.crandor.game.world.map.RegionManager;
|
||||
import org.crandor.game.world.map.RegionPlane;
|
||||
import org.crandor.game.world.map.path.Path;
|
||||
import org.crandor.game.world.map.path.Pathfinder;
|
||||
|
||||
public class ScriptAPI {
|
||||
|
||||
public double distance(Location l1, Location l2) {
|
||||
return Pathfinder.find(l1, l2).getPoints().size();
|
||||
public double distance(Node n1, Node n2)
|
||||
{
|
||||
return Math.sqrt(Math.pow(n1.getLocation().getX() - n2.getLocation().getX(), 2) + Math.pow(n2.getLocation().getY() - n1.getLocation().getY(), 2));
|
||||
}
|
||||
|
||||
public NPC getNearestNPC(Location loc, String npcName) {
|
||||
NPC npc = null;
|
||||
public Node getNearestEntity(Player me, String entityName)
|
||||
{
|
||||
Node entity = null;
|
||||
double minDistance = Double.MAX_VALUE;
|
||||
for (RegionPlane p : RegionManager.forId(loc.getRegionId()).getPlanes()) {
|
||||
for (NPC n : p.getNpcs()) {
|
||||
if (n != null) {
|
||||
if (n.getName().equals(npcName) && distance(loc, n.getLocation()) < minDistance) {
|
||||
npc = n;
|
||||
}
|
||||
}
|
||||
for (Node e : RegionManager.forId(me.getLocation().getRegionId()).getPlanes()[me.getLocation().getZ()].getEntities())
|
||||
{
|
||||
if (e != null && e.getName().equals(entityName) && distance(me, e) < minDistance && Pathfinder.find(me, e).isSuccessful())
|
||||
{
|
||||
/*if (entity != null)
|
||||
{
|
||||
System.out.println("I'm at " + me.getLocation() + ". " + e.getLocation() + distance(me, e) + " is closer to me than " + entity.getLocation() + distance(me, entity));
|
||||
}*/
|
||||
entity = e;
|
||||
minDistance = distance(me, e);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Returning " + npc.getName());
|
||||
return npc;
|
||||
System.out.println("Start: " + me.getLocation() + ". End: " + entity.getLocation());
|
||||
return entity;
|
||||
}
|
||||
|
||||
public GameObject getNearestGameObject(Location loc, int objectId) {
|
||||
|
|
@ -37,7 +47,7 @@ public class ScriptAPI {
|
|||
for (GameObject[] o : RegionManager.forId(loc.getRegionId()).getPlanes()[0].getObjects()) {
|
||||
for (GameObject obj : o) {
|
||||
if (obj != null) {
|
||||
if (distance(loc, obj.getLocation()) < minDistance) {
|
||||
if (distance(loc, obj) < minDistance) {
|
||||
nearestObject = obj;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
package org.crandor.game.node.entity.player.ai.general.scriptrepository;
|
||||
|
||||
import org.crandor.game.node.entity.player.Player;
|
||||
import plugin.skill.thieving.ThievingOptionPlugin;
|
||||
import org.crandor.game.node.Node;
|
||||
|
||||
public class ManThiever extends Script {
|
||||
|
||||
@Override
|
||||
public void runLoop() {
|
||||
new ThievingOptionPlugin().handle(me, scriptAPI.getNearestNPC(me.getLocation(), "Man"), "pickpocket");
|
||||
Node man = scriptAPI.getNearestEntity(me, "Man");
|
||||
|
||||
System.out.println("Current pulse: " + me.getPulseManager().getCurrent());
|
||||
System.out.println("Is moving pulse? " + me.getPulseManager().isMovingPulse());
|
||||
if (!me.getPulseManager().isMovingPulse())
|
||||
{
|
||||
man.getInteraction().handle(me, man.getInteraction().get(2));
|
||||
}
|
||||
/*scriptAPI.walk(me, man);
|
||||
new ThievingOptionPlugin().handle(me, man, "pickpocket");*/
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package org.crandor.game.world.map;
|
||||
|
||||
import org.crandor.game.node.Node;
|
||||
import org.crandor.game.node.entity.Entity;
|
||||
import org.crandor.game.node.entity.npc.NPC;
|
||||
import org.crandor.game.node.entity.player.Player;
|
||||
import org.crandor.game.node.item.GroundItem;
|
||||
|
|
@ -13,6 +15,8 @@ import org.crandor.net.packet.context.BuildItemContext;
|
|||
import org.crandor.net.packet.out.ClearGroundItem;
|
||||
import org.crandor.net.packet.out.ConstructGroundItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
|
|
@ -320,6 +324,17 @@ public final class RegionPlane {
|
|||
return npcs;
|
||||
}
|
||||
|
||||
public List<Node> getEntities()
|
||||
{
|
||||
List<Node> entities = new ArrayList<>(npcs);
|
||||
for (GameObject[] o : getObjects())
|
||||
{
|
||||
entities.addAll(Arrays.asList(o));
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the players.
|
||||
* @return The players.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.crandor.game.world.map.path;
|
|||
|
||||
import org.crandor.game.world.map.Location;
|
||||
import org.crandor.game.world.map.Point;
|
||||
import org.crandor.game.world.map.RegionManager;
|
||||
|
||||
public final class SmartPathfinder extends Pathfinder {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue