Merge pull request #47 from Parabot/Development

[FEATURE] Added Path Distance Calculations.
This commit is contained in:
Jeroen Ketelaar
2016-07-13 17:25:36 +02:00
committed by GitHub
18 changed files with 283 additions and 70 deletions
@@ -2,19 +2,19 @@ package org.rev317.min.accessors;
public interface Character {
public int getX();
int getX();
public int getY();
int getY();
public int getAnimation();
int getAnimation();
public int getLoopCycleStatus();
int getLoopCycleStatus();
public int getCurrentHealth();
int getCurrentHealth();
public int getMaxHealth();
int getMaxHealth();
public int getInteractingEntity();
int getInteractingEntity();
String getName();
}
@@ -2,56 +2,56 @@ package org.rev317.min.accessors;
public interface Client {
public Scene getScene();
Scene getScene();
public Player getMyPlayer();
Player getMyPlayer();
public Interface[] getInterfaceCache();
Interface[] getInterfaceCache();
public Npc[] getNpcs();
Npc[] getNpcs();
public Player[] getPlayers();
Player[] getPlayers();
public int getOpenInterfaceId();
int getOpenInterfaceId();
public int getBaseX();
int getBaseX();
public int getBaseY();
int getBaseY();
public void setInterface(int id);
void setInterface(int id);
public int[] getCurrentExp();
int[] getCurrentExp();
public Deque[][][] getGroundItems();
Deque[][][] getGroundItems();
public int getLoopCycle();
int getLoopCycle();
public int getBackDialogId();
int getBackDialogId();
public int getPlane();
int getPlane();
public int[] getMenuActionId();
int[] getMenuActionId();
public int[] getMenuAction1();
int[] getMenuAction1();
public int[] getMenuAction2();
int[] getMenuAction2();
public int[] getMenuAction3();
int[] getMenuAction3();
public int[] getMenuAction4();
int[] getMenuAction4();
public CollisionMap[] getCollisionMap();
CollisionMap[] getCollisionMap();
// args switched
public boolean walkTo(int clickType, int sizeX, int sizeY, int startX, int startY, int destX, int destY, int type, int face, boolean arbitrary, int rotation);
boolean walkTo(int clickType, int sizeX, int sizeY, int startX, int startY, int destX, int destY, int type, int face, boolean arbitrary, int rotation);
public void doAction(int i);
void doAction(int i);
public void dropClient();
void dropClient();
public int[] getCurrentStats();
int[] getCurrentStats();
public int[] getSettings();
int[] getSettings();
public boolean isLoggedIn();
boolean isLoggedIn();
}
@@ -3,7 +3,7 @@ package org.rev317.min.accessors;
public interface CollisionMap {
public int[][] getFlags();
int[][] getFlags();
}
@@ -2,8 +2,8 @@ package org.rev317.min.accessors;
public interface Deque {
public Node getHead();
Node getHead();
public Node getCurrent();
Node getCurrent();
}
@@ -2,14 +2,14 @@ package org.rev317.min.accessors;
public interface Ground {
public SceneObjectTile getWallObject();
SceneObjectTile getWallObject();
public SceneObjectTile getWallDecoration();
SceneObjectTile getWallDecoration();
public SceneObjectTile getGroundDecoration();
SceneObjectTile getGroundDecoration();
public SceneObjectTile getGroundItem();
SceneObjectTile getGroundItem();
public SceneObjectTile[] getInteractiveObjects();
SceneObjectTile[] getInteractiveObjects();
}
@@ -2,17 +2,17 @@ package org.rev317.min.accessors;
public interface Interface {
public int[] getItems();
int[] getItems();
public int[] getStackSizes();
int[] getStackSizes();
/**
* This is meant for the clients that have a long value as their stacksizes, simply because they have no logic...
*
* @return long version of #getStackSizes
*/
public long[] getLongStackSizes();
long[] getLongStackSizes();
public String getMessage();
String getMessage();
}
@@ -2,7 +2,7 @@ package org.rev317.min.accessors;
public interface Item {
public int getId();
int getId();
}
@@ -2,6 +2,6 @@ package org.rev317.min.accessors;
public interface Node {
public Node getNext();
Node getNext();
}
@@ -2,6 +2,6 @@ package org.rev317.min.accessors;
public interface Npc extends Character {
public NpcDef getDef();
NpcDef getDef();
}
@@ -2,6 +2,6 @@ package org.rev317.min.accessors;
public interface NpcDef {
public int getId();
int getId();
}
@@ -2,6 +2,6 @@ package org.rev317.min.accessors;
public interface Scene {
public Ground[][][] getGroundArray();
Ground[][][] getGroundArray();
}
@@ -2,6 +2,6 @@ package org.rev317.min.accessors;
public interface SceneObjectTile {
public int getHash();
int getHash();
}
@@ -7,6 +7,6 @@ import org.rev317.min.api.events.GameActionEvent;
*/
public interface GameActionListener {
public void onGameAction(GameActionEvent event);
void onGameAction(GameActionEvent event);
}
@@ -5,7 +5,7 @@ import org.rev317.min.api.events.MessageEvent;
public interface MessageListener {
public void messageReceived(MessageEvent event);
void messageReceived(MessageEvent event);
}
@@ -12,13 +12,13 @@ public interface Locatable {
*
* @return location
*/
public Tile getLocation();
Tile getLocation();
/**
* Gets distance to this locatable instance
*
* @return distance from player to locatable
*/
public int distanceTo();
int distanceTo();
}
@@ -2,17 +2,17 @@ package org.rev317.min.api.interfaces;
public interface TileFlags {
public int WALL_NORTHWEST = 0x1;
public int WALL_NORTH = 0x2;
public int WALL_NORTHEAST = 0x4;
public int WALL_EAST = 0x8;
public int WALL_SOUTHEAST = 0x10;
public int WALL_SOUTH = 0x20;
public int WALL_SOUTHWEST = 0x40;
public int WALL_WEST = 0x80;
public int OBJECT_TILE = 0x100;
public int UNKNOWN = 0x80000;
public int BLOCKED_TILE = 0x200000;
public int UNLOADED_TILE = 0x1000000;
int WALL_NORTHWEST = 0x1;
int WALL_NORTH = 0x2;
int WALL_NORTHEAST = 0x4;
int WALL_EAST = 0x8;
int WALL_SOUTHEAST = 0x10;
int WALL_SOUTH = 0x20;
int WALL_SOUTHWEST = 0x40;
int WALL_WEST = 0x80;
int OBJECT_TILE = 0x100;
int UNKNOWN = 0x80000;
int BLOCKED_TILE = 0x200000;
int UNLOADED_TILE = 0x1000000;
}
@@ -11,7 +11,6 @@ public class Calculations {
* Calculates distance between local player and given tile
*
* @param tile
*
* @return distance between local player and given tile
*/
public static final double distanceTo(Tile tile) {
@@ -23,7 +22,6 @@ public class Calculations {
*
* @param a
* @param b
*
* @return distance between a and b
*/
public static final double distanceBetween(Tile a, Tile b) {
@@ -39,7 +37,6 @@ public class Calculations {
* @param destX the destX (0 < destX < 104)
* @param destY the destY (0 < destY < 104)
* @param findAdjacent if it's an object, it will find path which touches it.
*
* @return The distance of the shortest path to the destination; or -1 if no valid path to the destination was
* found.
*/
@@ -153,6 +150,88 @@ public class Calculations {
}
}
/**
* Uses Dijkstra path finding algorithm to find shortest path returns false if path isn't found.
*
* @param from Start Tile.
* @param to Destination Tile.
* @return True if Path is found.
*/
public static boolean foundPath(Tile from, Tile to) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), false) != -1;
}
/**
* Uses Dijkstra path finding algorithm to find shortest path returns false if path isn't found.
*
* @param from Start Tile.
* @param to Destination Tile.
* @param isObject Is destination an Object.
* @return True if Path is found.
*/
public static boolean foundPath(Tile from, Tile to, boolean isObject) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), isObject) != -1;
}
/**
* Gets the Shortest Path distance between two tiles.
*
* @param from Start Tile.
* @param to Destination Tile.
* @return Shortest Path distance between two tiles using Dijkstra algorithm, returns -1 if path isn't found.
*/
public static int pathDistanceBetween(Tile from, Tile to) {
if (foundPath(from, to)) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), false);
}
return -1;
}
/**
* Gets the Shortest Path distance between two tiles.
*
* @param from Start Tile.
* @param to Destination Tile.
* @param isObject Is destination an Object.
* @return Shortest Path distance between two tiles using Dijkstra algorithm, returns -1 if path isn't found.
*/
public static int pathDistanceBetween(Tile from, Tile to, boolean isObject) {
if (foundPath(from, to)) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), isObject);
}
return -1;
}
/**
* Gets the shortest distance to a tile.
*
* @param tile Destination Tile.
* @return Shortest distance to tile.
*/
public static int pathDistanceTo(Tile tile) {
return pathDistanceBetween(Players.getMyPlayer().getLocation(), tile);
}
/**
* Gets the shortest distance to a tile.
*
* @param tile Destination Tile.
* @param isObject Is destination an Object.
* @return Shortest distance to tile.
*/
public static int pathDistanceTo(Tile tile, boolean isObject) {
return pathDistanceBetween(Players.getMyPlayer().getLocation(), tile, isObject);
}
/**
* Compares Coordinate data from the first and second tile data.
*
* @param first First tile.
* @param second Second tile.
* @return True if Coordinate data from first and second tiles match.
*/
public static boolean isSameTile(Tile first, Tile second) {
return first.getX() == second.getX() && first.getY() == second.getY() && first.getPlane() == second.getPlane();
}
}
@@ -0,0 +1,134 @@
package org.rev317.min.api.methods;
import org.parabot.environment.api.utils.Time;
import org.parabot.environment.scripts.framework.SleepCondition;
import org.rev317.min.Loader;
import org.rev317.min.api.wrappers.Item;
/**
* @author Piet Jetse Heeringa
*/
public class Equipment {
/**
* Equips an Item based on the ID of that item.
*
* @param id Item ID to Equip.
*/
public static void equip(final int id) {
Item item = Inventory.getItem(id);
if (item != null) {
item.interact(Items.Option.WEAR);
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return isWearing(id);
}
}, 3000);
}
}
/**
* Unequips an Item based on the ID of that item.
*
* @param id Item ID to Unequip.
*/
public static void unequip(int id) {
for (Slot slot : Slot.values()) {
if (slot.id() == id) {
unequip(slot);
}
}
}
/**
* Unequips the item from the given Slot.
*
* @param slot Slot to Unequip the item from.
*/
public static void unequip(final Slot slot) {
Menu.sendAction(632, slot.id() - 1, slot.slot, 1688, -1, 3);
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return slot.id() == 0;
}
}, 3000);
}
/**
* Check if the Player is Wearing an Item based on the ID.
*
* @param id ID of the item to check for.
* @return True if the Player is wearing the Item.
*/
public static boolean isWearing(int id) {
for (Slot slot : Slot.values()) {
if (slot.id() == id) {
return true;
}
}
return false;
}
/**
* Get's the item ID in slot.
*
* @param slot Slot to get the item ID from.
* @return Item ID from given slot.
*/
public static int getItemId(Slot slot) {
return slot.id();
}
/**
* Check's if there is an item in the given slot.
*
* @param slot Slot to check for Item.
* @return True if there is an Item in the given slot.
*/
public static boolean hasItem(Slot slot) {
return getItemId(slot) != 0;
}
/**
* Check's if the given slot is empty.
*
* @param slot Slot to check for Item.
* @return True if the given slot is empty.
*/
public static boolean isEmpty(Slot slot) {
return getItemId(slot) == 0;
}
public enum Slot {
HEAD(0),
CAPE(1),
AMMULET(2),
WEAPON(3),
BODY(4),
SHIELD(5),
LEGS(7),
GLOVES(9),
BOOTS(10),
RING(12),
AMMO(13);
private int slot;
private final int INTERFACE_ID = 1688;
Slot(int slot) {
this.slot = slot;
}
/**
* Get's the ID of the item in slot.
*
* @return ID of the item in slot.
*/
public int id() {
return Loader.getClient().getInterfaceCache()[INTERFACE_ID].getItems()[slot];
}
}
}