Merge pull request #70 from Parabot/feature/getlongid

[FEATURE] Added getLongId
This commit is contained in:
Jeroen Ketelaar
2017-02-06 16:58:07 +01:00
committed by GitHub
59 changed files with 313 additions and 291 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
+8 -6
View File
@@ -23,8 +23,8 @@ import java.io.File;
import java.net.URL; import java.net.URL;
/** /**
* @author Everel, JKetelaar * @author Everel, JKetelaar
*/ */
@ServerManifest(author = "Everel & JKetelaar", name = "Server name here", type = Type.INJECTION, version = 2.1) @ServerManifest(author = "Everel & JKetelaar", name = "Server name here", type = Type.INJECTION, version = 2.1)
public class Loader extends ServerProvider { public class Loader extends ServerProvider {
private boolean extended = true; private boolean extended = true;
@@ -40,9 +40,11 @@ public class Loader extends ServerProvider {
final ASMClassLoader classLoader = context.getASMClassLoader(); final ASMClassLoader classLoader = context.getASMClassLoader();
final Class<?> clientClass = classLoader.loadClass(Context.getInstance().getServerProviderInfo().getClientClass()); final Class<?> clientClass = classLoader.loadClass(Context.getInstance().getServerProviderInfo().getClientClass());
Object instance = clientClass.newInstance(); Object instance = clientClass.newInstance();
return (Applet) instance; return (Applet) instance;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
} }
@@ -70,7 +72,7 @@ public class Loader extends ServerProvider {
try { try {
super.injectHooks(); super.injectHooks();
} catch (Exception e) { } catch (Exception e) {
if (Core.inVerboseMode()){ if (Core.inVerboseMode()) {
e.printStackTrace(); e.printStackTrace();
} }
this.extended = false; this.extended = false;
@@ -86,9 +88,9 @@ public class Loader extends ServerProvider {
@Override @Override
public HookFile getHookFile() { public HookFile getHookFile() {
if (this.extended){ if (this.extended) {
return new HookFile(Context.getInstance().getServerProviderInfo().getExtendedHookFile(), HookFile.TYPE_XML); return new HookFile(Context.getInstance().getServerProviderInfo().getExtendedHookFile(), HookFile.TYPE_XML);
}else{ } else {
return new HookFile(Context.getInstance().getServerProviderInfo().getHookFile(), HookFile.TYPE_XML); return new HookFile(Context.getInstance().getServerProviderInfo().getHookFile(), HookFile.TYPE_XML);
} }
} }
@@ -100,4 +102,4 @@ public class Loader extends ServerProvider {
@Override @Override
public void init() { public void init() {
} }
} }
@@ -44,7 +44,6 @@ public interface Client {
CollisionMap[] getCollisionMap(); CollisionMap[] getCollisionMap();
// args switched
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);
boolean walkToPKH(boolean flag1, boolean flag2, int clickType, int sizeX, int sizeY, int startX, int startY, int destX, int destY, int type, int face, boolean arbitrary, int rotation); boolean walkToPKH(boolean flag1, boolean flag2, int clickType, int sizeX, int sizeY, int startX, int startY, int destX, int destY, int type, int face, boolean arbitrary, int rotation);
@@ -4,6 +4,5 @@ package org.rev317.min.accessors;
public interface CollisionMap { public interface CollisionMap {
int[][] getFlags(); int[][] getFlags();
} }
@@ -5,5 +5,4 @@ public interface Deque {
Node getHead(); Node getHead();
Node getCurrent(); Node getCurrent();
} }
@@ -8,8 +8,7 @@ public interface Ground {
SceneObjectTile getGroundDecoration(); SceneObjectTile getGroundDecoration();
SceneObjectTile getGroundItem(); SceneObjectTile getGroundItem();
SceneObjectTile[] getInteractiveObjects();
SceneObjectTile[] getInteractiveObjects();
} }
@@ -7,12 +7,9 @@ public interface Interface {
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 * @return long version of #getStackSizes
*/ */
long[] getLongStackSizes(); long[] getLongStackSizes();
String getMessage(); String getMessage();
} }
@@ -3,6 +3,5 @@ package org.rev317.min.accessors;
public interface Item { public interface Item {
int getId(); int getId();
} }
@@ -3,5 +3,4 @@ package org.rev317.min.accessors;
public interface Node { public interface Node {
Node getNext(); Node getNext();
} }
@@ -3,5 +3,4 @@ package org.rev317.min.accessors;
public interface Npc extends Character { public interface Npc extends Character {
NpcDef getDef(); NpcDef getDef();
} }
@@ -4,4 +4,5 @@ public interface NpcDef {
int getId(); int getId();
long getLongId();
} }
@@ -1,5 +1,6 @@
package org.rev317.min.accessors; package org.rev317.min.accessors;
public interface Player extends Character { public interface Player extends Character {
String getName(); String getName();
} }
@@ -3,5 +3,4 @@ package org.rev317.min.accessors;
public interface Scene { public interface Scene {
Ground[][][] getGroundArray(); Ground[][][] getGroundArray();
} }
@@ -3,5 +3,4 @@ package org.rev317.min.accessors;
public interface SceneObjectTile { public interface SceneObjectTile {
int getHash(); int getHash();
} }
@@ -38,5 +38,4 @@ public final class GameActionEvent {
public int getIndex() { public int getIndex() {
return index; return index;
} }
} }
@@ -29,5 +29,4 @@ public final class MessageEvent {
public final String getSender() { public final String getSender() {
return name; return name;
} }
}
}
@@ -20,5 +20,4 @@ public interface Locatable {
* @return distance from player to locatable * @return distance from player to locatable
*/ */
int distanceTo(); int distanceTo();
} }
@@ -14,5 +14,4 @@ public interface TileFlags {
int UNKNOWN = 0x80000; int UNKNOWN = 0x80000;
int BLOCKED_TILE = 0x200000; int BLOCKED_TILE = 0x200000;
int UNLOADED_TILE = 0x1000000; int UNLOADED_TILE = 0x1000000;
} }
@@ -63,10 +63,10 @@ public class Bank {
* @return <b>true</b> if successfully interacted * @return <b>true</b> if successfully interacted
*/ */
public static boolean open() { public static boolean open() {
if (isOpen()) { if (isOpen()) {
return false; return false;
} }
SceneObject bank = getBank(); SceneObject bank = getBank();
Npc banker = getBanker(); Npc banker = getBanker();
@@ -100,7 +100,6 @@ public class Bank {
} }
Item b = getItem(id); Item b = getItem(id);
if (b == null) { if (b == null) {
return; return;
} }
@@ -124,7 +123,6 @@ public class Bank {
* Gets bank item with given id * Gets bank item with given id
* *
* @param id * @param id
*
* @return bank item * @return bank item
*/ */
public static Item getItem(int id) { public static Item getItem(int id) {
@@ -140,6 +138,7 @@ public class Bank {
} }
} }
} }
return null; return null;
} }
@@ -147,7 +146,6 @@ public class Bank {
* Counts the amount of items with given id in bank * Counts the amount of items with given id in bank
* *
* @param id * @param id
*
* @return count * @return count
*/ */
public static int getCount(int id) { public static int getCount(int id) {
@@ -155,6 +153,7 @@ public class Bank {
return 0; return 0;
} }
Item item; Item item;
return ((item = getItem(id)) != null ? item.getStackSize() : 0); return ((item = getItem(id)) != null ? item.getStackSize() : 0);
} }
@@ -167,7 +166,6 @@ public class Bank {
if (isOpen()) { if (isOpen()) {
return; return;
} }
if (bank.getLocation().distanceTo() > 8) { if (bank.getLocation().distanceTo() > 8) {
bank.getLocation().walkTo(); bank.getLocation().walkTo();
Time.sleep(new SleepCondition() { Time.sleep(new SleepCondition() {
@@ -178,6 +176,7 @@ public class Bank {
}, 5000); }, 5000);
return; return;
} }
bank.interact(SceneObjects.Option.USE); bank.interact(SceneObjects.Option.USE);
} }
@@ -189,6 +188,7 @@ public class Bank {
if (!isOpen()) { if (!isOpen()) {
return; return;
} }
Menu.sendAction(200, -1, -1, settings.get("button_close_bank")); Menu.sendAction(200, -1, -1, settings.get("button_close_bank"));
} }
@@ -231,6 +231,7 @@ public class Bank {
if (!isOpen()) { if (!isOpen()) {
return null; return null;
} }
return Loader.getClient().getInterfaceCache()[settings.get("item_interface_id")].getItems(); return Loader.getClient().getInterfaceCache()[settings.get("item_interface_id")].getItems();
} }
@@ -243,6 +244,7 @@ public class Bank {
if (!isOpen()) { if (!isOpen()) {
return null; return null;
} }
return Loader.getClient().getInterfaceCache()[settings.get("item_interface_id")].getStackSizes(); return Loader.getClient().getInterfaceCache()[settings.get("item_interface_id")].getStackSizes();
} }
@@ -255,6 +257,7 @@ public class Bank {
if (!isOpen()) { if (!isOpen()) {
return null; return null;
} }
ArrayList<Item> items = new ArrayList<Item>(); ArrayList<Item> items = new ArrayList<Item>();
int[] ids = getBankItemIDs(); int[] ids = getBankItemIDs();
int[] stacks = getBankStacks(); int[] stacks = getBankStacks();
@@ -265,6 +268,7 @@ public class Bank {
} }
} }
} }
return items.toArray(new Item[items.size()]); return items.toArray(new Item[items.size()]);
} }
@@ -277,6 +281,7 @@ public class Bank {
if (!isOpen()) { if (!isOpen()) {
return 0; return 0;
} }
int[] items; int[] items;
return ((items = getBankItemIDs()) != null ? items.length : 0); return ((items = getBankItemIDs()) != null ? items.length : 0);
} }
@@ -289,5 +294,4 @@ public class Bank {
public static boolean isOpen() { public static boolean isOpen() {
return Loader.getClient().getOpenInterfaceId() == settings.get("bank_interface_id"); return Loader.getClient().getOpenInterfaceId() == settings.get("bank_interface_id");
} }
} }
@@ -28,6 +28,7 @@ public class Calculations {
public static final double distanceBetween(Tile a, Tile b) { public static final double distanceBetween(Tile a, Tile b) {
int x = b.getX() - a.getX(); int x = b.getX() - a.getX();
int y = b.getY() - a.getY(); int y = b.getY() - a.getY();
return Math.sqrt((x * x) + (y * y)); return Math.sqrt((x * x) + (y * y));
} }
@@ -145,6 +146,7 @@ public class Calculations {
dist[curr_x + 1][curr_y + 1] = cost; dist[curr_x + 1][curr_y + 1] = cost;
} }
} }
return foundPath ? dist[curr_x][curr_y] : -1; return foundPath ? dist[curr_x][curr_y] : -1;
} catch (Exception e) { } catch (Exception e) {
return -1; return -1;
@@ -185,6 +187,7 @@ public class Calculations {
if (foundPath(from, to)) { if (foundPath(from, to)) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), false); return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), false);
} }
return -1; return -1;
} }
@@ -200,6 +203,7 @@ public class Calculations {
if (foundPath(from, to)) { if (foundPath(from, to)) {
return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), isObject); return dijkstraDist(from.getX(), from.getY(), to.getX(), to.getY(), isObject);
} }
return -1; return -1;
} }
@@ -267,5 +271,4 @@ public class Calculations {
public static int gainedPerHour(Timer runtime, int start, int current) { public static int gainedPerHour(Timer runtime, int start, int current) {
return runtime.getPerHour(gained(start, current)); return runtime.getPerHour(gained(start, current));
} }
}
}
@@ -69,6 +69,7 @@ public class Equipment {
return true; return true;
} }
} }
return false; return false;
} }
@@ -115,8 +116,8 @@ public class Equipment {
RING(12), RING(12),
AMMO(13); AMMO(13);
private int slot;
private final int INTERFACE_ID = 1688; private final int INTERFACE_ID = 1688;
private int slot;
Slot(int slot) { Slot(int slot) {
this.slot = slot; this.slot = slot;
@@ -146,16 +146,18 @@ public class Game {
Time.sleep(new SleepCondition() { Time.sleep(new SleepCondition() {
@Override @Override
public boolean isValid() { public boolean isValid() {
return isLoggedIn(); return !isLoggedIn();
} }
}, 2500); }, 2500);
return !isLoggedIn(); return !isLoggedIn();
} }
/** /**
* Login to a server * Login to a server
* @param username String *
* @param password String * @param username String
* @param password String
* @param reconnecting True if it's a retry, false if not * @param reconnecting True if it's a retry, false if not
*/ */
public static void login(String username, String password, boolean reconnecting) { public static void login(String username, String password, boolean reconnecting) {
@@ -164,6 +166,7 @@ public class Game {
/** /**
* Login to a server * Login to a server
*
* @param username String * @param username String
* @param password String * @param password String
*/ */
@@ -173,6 +176,7 @@ public class Game {
/** /**
* Adds friend * Adds friend
*
* @param username String * @param username String
*/ */
public static void addFriend(String username) { public static void addFriend(String username) {
@@ -181,6 +185,7 @@ public class Game {
/** /**
* Deletes friend * Deletes friend
*
* @param username String * @param username String
*/ */
public static void deleteFriend(String username) { public static void deleteFriend(String username) {
@@ -19,12 +19,10 @@ import java.util.HashMap;
*/ */
public class GroundItems { public class GroundItems {
private static final Comparator<GroundItem> NEAREST_SORTER = new Comparator<GroundItem>() { private static final Comparator<GroundItem> NEAREST_SORTER = new Comparator<GroundItem>() {
@Override @Override
public int compare(GroundItem n1, GroundItem n2) { public int compare(GroundItem n1, GroundItem n2) {
return n1.distanceTo() - n2.distanceTo(); return n1.distanceTo() - n2.distanceTo();
} }
}; };
private static final Filter<GroundItem> ALL_FILTER = new Filter<GroundItem>() { private static final Filter<GroundItem> ALL_FILTER = new Filter<GroundItem>() {
@@ -60,6 +58,7 @@ public class GroundItems {
} }
} }
} }
return items.toArray(new GroundItem[items.size()]); return items.toArray(new GroundItem[items.size()]);
} }
@@ -68,7 +67,6 @@ public class GroundItems {
* *
* @param x - local region x * @param x - local region x
* @param y - local region y * @param y - local region y
*
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest. * @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/ */
public static final GroundItem[] getGroundItemsAt(final int x, final int y) { public static final GroundItem[] getGroundItemsAt(final int x, final int y) {
@@ -76,10 +74,12 @@ public class GroundItems {
if (client == null) { if (client == null) {
client = Loader.getClient(); client = Loader.getClient();
} }
final Deque deque = client.getGroundItems()[Game.getPlane()][x][y]; final Deque deque = client.getGroundItems()[Game.getPlane()][x][y];
if (deque == null) { if (deque == null) {
return null; return null;
} }
ArrayList<GroundItem> list = new ArrayList<>(); ArrayList<GroundItem> list = new ArrayList<>();
final Node holder = deque.getHead(); final Node holder = deque.getHead();
Node curNode = holder.getNext(); Node curNode = holder.getNext();
@@ -89,10 +89,12 @@ public class GroundItems {
list.add(new GroundItem(groundItem, x, y)); list.add(new GroundItem(groundItem, x, y));
curNode = curNode.getNext(); curNode = curNode.getNext();
} }
return list.toArray(new GroundItem[list.size()]); return list.toArray(new GroundItem[list.size()]);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
} }
@@ -103,7 +105,7 @@ public class GroundItems {
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest. * @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/ */
public static final GroundItem[] getGroundItemsAt(final Tile tile) { public static final GroundItem[] getGroundItemsAt(final Tile tile) {
return getGroundItemsAt(tile.getX(),tile.getY()); return getGroundItemsAt(tile.getX(), tile.getY());
} }
/** /**
@@ -119,7 +121,6 @@ public class GroundItems {
* Gets the closest GroundItem which matches the given filter. * Gets the closest GroundItem which matches the given filter.
* *
* @param filter Filter that should be applied to the GroundItem. * @param filter Filter that should be applied to the GroundItem.
*
* @return closest GroundItem * @return closest GroundItem
*/ */
public static final GroundItem getClosest(final Filter<GroundItem> filter) { public static final GroundItem getClosest(final Filter<GroundItem> filter) {
@@ -127,6 +128,7 @@ public class GroundItems {
if (objects == null || objects.length == 0) { if (objects == null || objects.length == 0) {
return null; return null;
} }
return objects[0]; return objects[0];
} }
@@ -134,7 +136,6 @@ public class GroundItems {
* Gets the closest GroundItems which matches the given ids. * Gets the closest GroundItems which matches the given ids.
* *
* @param ids ID's of the GroundItems to look for. * @param ids ID's of the GroundItems to look for.
*
* @return closest GroundItems * @return closest GroundItems
*/ */
public static final GroundItem getClosest(int... ids) { public static final GroundItem getClosest(int... ids) {
@@ -142,6 +143,7 @@ public class GroundItems {
if (objects == null || objects.length == 0) { if (objects == null || objects.length == 0) {
return null; return null;
} }
return objects[0]; return objects[0];
} }
@@ -149,12 +151,12 @@ public class GroundItems {
* Returns Array of GroundItems with the first index to be the nearest. * Returns Array of GroundItems with the first index to be the nearest.
* *
* @param filter Filter that should be applied to the GroundItem. * @param filter Filter that should be applied to the GroundItem.
*
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest. * @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/ */
public static final GroundItem[] getNearest(Filter<GroundItem> filter) { public static final GroundItem[] getNearest(Filter<GroundItem> filter) {
final GroundItem[] objects = getGroundItems(filter); final GroundItem[] objects = getGroundItems(filter);
Arrays.sort(objects, NEAREST_SORTER); Arrays.sort(objects, NEAREST_SORTER);
return objects; return objects;
} }
@@ -171,12 +173,10 @@ public class GroundItems {
* Returns Array of GroundItems with the first index to be the nearest. * Returns Array of GroundItems with the first index to be the nearest.
* *
* @param ids GroundItem ID's to look for. * @param ids GroundItem ID's to look for.
*
* @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest. * @return GroundItems Array of the Nearest GroundItems with the first index to be the nearest.
*/ */
public static final GroundItem[] getNearest(final int... ids) { public static final GroundItem[] getNearest(final int... ids) {
return getNearest(new Filter<GroundItem>() { return getNearest(new Filter<GroundItem>() {
@Override @Override
public boolean accept(GroundItem object) { public boolean accept(GroundItem object) {
for (final int id : ids) { for (final int id : ids) {
@@ -184,13 +184,13 @@ public class GroundItems {
return true; return true;
} }
} }
return false; return false;
} }
}); });
} }
public enum Option{ public enum Option {
FIRST(settings.get("menu_ground_item_first_interaction")), FIRST(settings.get("menu_ground_item_first_interaction")),
SECOND(settings.get("menu_ground_item_second_interaction")), SECOND(settings.get("menu_ground_item_second_interaction")),
@@ -204,7 +204,7 @@ public class GroundItems {
EXAMINE(settings.get("menu_ground_item_examine_interaction")); EXAMINE(settings.get("menu_ground_item_examine_interaction"));
int actionId; private int actionId;
Option(int actionId) { Option(int actionId) {
this.actionId = actionId; this.actionId = actionId;
@@ -17,8 +17,6 @@ import java.util.HashMap;
*/ */
public class Inventory { public class Inventory {
private static HashMap<String, Integer> settings = Context.getInstance().getServerProviderInfo().getSettings();
private static final Filter<Item> ALL_FILTER = new Filter<Item>() { private static final Filter<Item> ALL_FILTER = new Filter<Item>() {
@Override @Override
@@ -27,6 +25,7 @@ public class Inventory {
} }
}; };
private static HashMap<String, Integer> settings = Context.getInstance().getServerProviderInfo().getSettings();
/** /**
* Clears the inventory * Clears the inventory
@@ -75,7 +74,6 @@ public class Inventory {
* Gets the amount of items with given ids in inventory, excludes the stack sizes * Gets the amount of items with given ids in inventory, excludes the stack sizes
* *
* @param ids * @param ids
*
* @return amount of items * @return amount of items
*/ */
public static int getCount(int... ids) { public static int getCount(int... ids) {
@@ -86,7 +84,6 @@ public class Inventory {
* Gets the amount of items in inventory * Gets the amount of items in inventory
* *
* @param includeStack - true for including stack sizes to the counting * @param includeStack - true for including stack sizes to the counting
*
* @return amount of items * @return amount of items
*/ */
public static int getCount(final boolean includeStack) { public static int getCount(final boolean includeStack) {
@@ -110,7 +107,6 @@ public class Inventory {
* *
* @param includeStack - true for including stack sizes to the counting * @param includeStack - true for including stack sizes to the counting
* @param ids * @param ids
*
* @return amount of items * @return amount of items
*/ */
public static int getCount(final boolean includeStack, int... ids) { public static int getCount(final boolean includeStack, int... ids) {
@@ -148,7 +144,6 @@ public class Inventory {
* Gets all items with given ids * Gets all items with given ids
* *
* @param ids * @param ids
*
* @return items * @return items
*/ */
public static Item[] getItems(final int... ids) { public static Item[] getItems(final int... ids) {
@@ -171,7 +166,6 @@ public class Inventory {
* Gets all items accepted by filter * Gets all items accepted by filter
* *
* @param filter * @param filter
*
* @return items * @return items
*/ */
public static Item[] getItems(final Filter<Item> filter) { public static Item[] getItems(final Filter<Item> filter) {
@@ -218,7 +212,6 @@ public class Inventory {
* Checks if an item exists in the inventory * Checks if an item exists in the inventory
* *
* @param id The item id that will be looked for * @param id The item id that will be looked for
*
* @return True if the item exists in the inventory * @return True if the item exists in the inventory
*/ */
public static boolean contains(int... id) { public static boolean contains(int... id) {
@@ -234,7 +227,6 @@ public class Inventory {
* Returns the item in the inventory based on the given id * Returns the item in the inventory based on the given id
* *
* @param id The item id that will be used to find the item in the inventory * @param id The item id that will be used to find the item in the inventory
*
* @return First found item in the inventory * @return First found item in the inventory
*/ */
public static Item getItem(int id) { public static Item getItem(int id) {
@@ -251,7 +243,6 @@ public class Inventory {
* *
* @param itemOne The first item id that will be used to combine * @param itemOne The first item id that will be used to combine
* @param itemTwo The second item id that will be used to combine * @param itemTwo The second item id that will be used to combine
*
* @return True if nothing unexpected happened * @return True if nothing unexpected happened
*/ */
public static boolean combine(int itemOne, int itemTwo) { public static boolean combine(int itemOne, int itemTwo) {
@@ -273,10 +264,9 @@ public class Inventory {
/** /**
* Combines two items by using it on each other * Combines two items by using it on each other
* *
* @param itemOne The first item id that will be used to combine * @param itemOne The first item id that will be used to combine
* @param itemTwo The second item id that will be used to combine * @param itemTwo The second item id that will be used to combine
* @param sleepCondition The sleep condition that will be used to check and wait until the condition is valid * @param sleepCondition The sleep condition that will be used to check and wait until the condition is valid
*
* @return True if the condition was true and nothing unexpected happened * @return True if the condition was true and nothing unexpected happened
*/ */
public static boolean combine(int itemOne, int itemTwo, SleepCondition sleepCondition) { public static boolean combine(int itemOne, int itemTwo, SleepCondition sleepCondition) {
@@ -24,11 +24,11 @@ public class Items {
private static HashMap<Integer, Long> prices = new HashMap<>(); private static HashMap<Integer, Long> prices = new HashMap<>();
private static HashMap<Integer, String> names = new HashMap<>(); private static HashMap<Integer, String> names = new HashMap<>();
public static String getName(int id){ public static String getName(int id) {
String name; String name;
if ((name = names.get(id)) != null){ if ((name = names.get(id)) != null) {
return name; return name;
}else { } else {
try { try {
String content = WebUtil.getContents(Configuration.ITEM_API + id); String content = WebUtil.getContents(Configuration.ITEM_API + id);
if (content.length() > 0) { if (content.length() > 0) {
@@ -40,80 +40,93 @@ public class Items {
return name; return name;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
} }
return null; return null;
} }
public static int[] getIds(String name){ public static int[] getIds(String name) {
try { try {
String content = WebUtil.getContents(Configuration.ITEM_API + name); String content = WebUtil.getContents(Configuration.ITEM_API + name);
if (content.length() > 0) { if (content.length() > 0) {
JSONObject jsonObject = (JSONObject) jsonParser.parse(content); JSONObject jsonObject = (JSONObject) jsonParser.parse(content);
JSONArray array = (JSONArray) jsonObject.get("result"); JSONArray array = (JSONArray) jsonObject.get("result");
if (array.size() > 0){ if (array.size() > 0) {
int[] ids = new int[array.size()]; int[] ids = new int[array.size()];
for (int i = 0; i < array.size(); i++){ for (int i = 0; i < array.size(); i++) {
ids[i] = Integer.parseInt((String) array.get(i)); ids[i] = Integer.parseInt((String) array.get(i));
} }
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) {} } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
}
return new int[0]; return new int[0];
} }
/** /**
* Returns an int array based on the string it starts with. getIdsStart(dragon) will return an int array with all items starting with dragon * Returns an int array based on the string it starts with. getIdsStart(dragon) will return an int array with all items starting with dragon
*
* @param name * @param name
* @return * @return
*/ */
public static int[] getIdsStart(String name){ public static int[] getIdsStart(String name) {
try { try {
String content = WebUtil.getContents(Configuration.ITEM_API + "starts/" + name); String content = WebUtil.getContents(Configuration.ITEM_API + "starts/" + name);
if (content.length() > 0) { if (content.length() > 0) {
JSONObject jsonObject = (JSONObject) jsonParser.parse(content); JSONObject jsonObject = (JSONObject) jsonParser.parse(content);
JSONArray array = (JSONArray) jsonObject.get("result"); JSONArray array = (JSONArray) jsonObject.get("result");
if (array.size() > 0){ if (array.size() > 0) {
int[] ids = new int[array.size()]; int[] ids = new int[array.size()];
for (int i = 0; i < array.size(); i++){ for (int i = 0; i < array.size(); i++) {
ids[i] = Integer.parseInt((String) array.get(i)); ids[i] = Integer.parseInt((String) array.get(i));
} }
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) {} } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
}
return new int[0]; return new int[0];
} }
/** /**
* Returns an int array based on the string it contains. getIdsContain(dragon) will return an int array with all items containingdragon * Returns an int array based on the string it contains. getIdsContain(dragon) will return an int array with all items containingdragon
*
* @param name * @param name
* @return * @return
*/ */
public static int[] getIdsContain(String name){ public static int[] getIdsContain(String name) {
try { try {
String content = WebUtil.getContents(Configuration.ITEM_API + "contains/" + name); String content = WebUtil.getContents(Configuration.ITEM_API + "contains/" + name);
if (content.length() > 0) { if (content.length() > 0) {
JSONObject jsonObject = (JSONObject) jsonParser.parse(content); JSONObject jsonObject = (JSONObject) jsonParser.parse(content);
JSONArray array = (JSONArray) jsonObject.get("result"); JSONArray array = (JSONArray) jsonObject.get("result");
if (array.size() > 0){ if (array.size() > 0) {
int[] ids = new int[array.size()]; int[] ids = new int[array.size()];
for (int i = 0; i < array.size(); i++){ for (int i = 0; i < array.size(); i++) {
ids[i] = Integer.parseInt((String) array.get(i)); ids[i] = Integer.parseInt((String) array.get(i));
} }
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) {} } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
}
return new int[0]; return new int[0];
} }
public static long getPrice(int id){ public static long getPrice(int id) {
if (prices.containsKey(id)){ if (prices.containsKey(id)) {
return prices.get(id); return prices.get(id);
}else { } else {
try { try {
String content = WebUtil.getContents(Configuration.ITEM_API + id + "/" + Context.getInstance().getServerProviderInfo().getServerName()); String content = WebUtil.getContents(Configuration.ITEM_API + id + "/" + Context.getInstance().getServerProviderInfo().getServerName());
if (content.length() > 0) { if (content.length() > 0) {
@@ -125,13 +138,14 @@ public class Items {
return price; return price;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
} }
return 0; return 0;
} }
public enum Option{ public enum Option {
TRANSFORM_FIRST(settings.get("menu_transform_one_interaction")), TRANSFORM_FIRST(settings.get("menu_transform_one_interaction")),
VALUE(settings.get("menu_transform_one_interaction")), VALUE(settings.get("menu_transform_one_interaction")),
TRANSFORM_ONE(settings.get("menu_transform_one_interaction")), TRANSFORM_ONE(settings.get("menu_transform_one_interaction")),
@@ -176,7 +190,7 @@ public class Items {
SEVENTH(settings.get("menu_item_seventh_interaction")), SEVENTH(settings.get("menu_item_seventh_interaction")),
USE_WITH(settings.get("menu_item_seventh_interaction")); USE_WITH(settings.get("menu_item_seventh_interaction"));
int actionId; private int actionId;
Option(int actionId) { Option(int actionId) {
this.actionId = actionId; this.actionId = actionId;
@@ -108,6 +108,7 @@ public class Menu {
actionId = 478; actionId = 478;
break; break;
} }
sendAction(actionId, character.getIndex(), 0, 0); sendAction(actionId, character.getIndex(), 0, 0);
} }
@@ -118,10 +119,8 @@ public class Menu {
* @param action * @param action
* @param interfaceParentId * @param interfaceParentId
*/ */
public static void transformItem(Item item, Items.Option action, public static void transformItem(Item item, Items.Option action, int interfaceParentId) {
int interfaceParentId) { sendAction(action.getActionId(), item.getId() - 1, item.getSlot(), interfaceParentId);
sendAction(action.getActionId(), item.getId() - 1, item.getSlot(),
interfaceParentId);
} }
/** /**
@@ -132,8 +131,7 @@ public class Menu {
* @param interfaceParentId * @param interfaceParentId
* @deprecated * @deprecated
*/ */
public static void transformItem(Item item, int actionIndex, public static void transformItem(Item item, int actionIndex, int interfaceParentId) {
int interfaceParentId) {
int actionId = Items.Option.TRANSFORM_FIRST.getActionId(); int actionId = Items.Option.TRANSFORM_FIRST.getActionId();
switch (actionIndex) { switch (actionIndex) {
case 0: case 0:
@@ -264,8 +262,7 @@ public class Menu {
* @param item * @param item
*/ */
public static void drop(Item item) { public static void drop(Item item) {
sendAction(settings.get("button_drop_item"), item.getId() - 1, item.getSlot(), sendAction(settings.get("button_drop_item"), item.getId() - 1, item.getSlot(), settings.get("inventory_index"));
settings.get("inventory_index"));
} }
/** /**
@@ -323,7 +320,6 @@ public class Menu {
} }
client.getMenuActionId()[index] = action; client.getMenuActionId()[index] = action;
client.doAction(index); client.doAction(index);
} }
} }
@@ -6,7 +6,10 @@ import org.rev317.min.Loader;
import org.rev317.min.accessors.Client; import org.rev317.min.accessors.Client;
import org.rev317.min.api.wrappers.Npc; import org.rev317.min.api.wrappers.Npc;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
/** /**
* @author Everel, JKetelaar * @author Everel, JKetelaar
@@ -36,7 +39,6 @@ public class Npcs {
* Gets all Npcs except local Npc * Gets all Npcs except local Npc
* *
* @param filter * @param filter
*
* @return all Npcs * @return all Npcs
*/ */
public static final Npc[] getNpcs(final Filter<Npc> filter) { public static final Npc[] getNpcs(final Filter<Npc> filter) {
@@ -52,6 +54,7 @@ public class Npcs {
npcList.add(npc); npcList.add(npc);
} }
} }
return npcList.toArray(new Npc[npcList.size()]); return npcList.toArray(new Npc[npcList.size()]);
} }
@@ -68,7 +71,6 @@ public class Npcs {
* Gets the closest npc which matches the given filter * Gets the closest npc which matches the given filter
* *
* @param filter * @param filter
*
* @return closest npc * @return closest npc
*/ */
public static final Npc getClosest(final Filter<Npc> filter) { public static final Npc getClosest(final Filter<Npc> filter) {
@@ -76,6 +78,7 @@ public class Npcs {
if (npcs == null || npcs.length == 0) { if (npcs == null || npcs.length == 0) {
return null; return null;
} }
return npcs[0]; return npcs[0];
} }
@@ -83,7 +86,6 @@ public class Npcs {
* Gets the closest npc which matches the given ids * Gets the closest npc which matches the given ids
* *
* @param ids * @param ids
*
* @return closest npc * @return closest npc
*/ */
public static final Npc getClosest(int... ids) { public static final Npc getClosest(int... ids) {
@@ -91,6 +93,7 @@ public class Npcs {
if (npcs == null || npcs.length == 0) { if (npcs == null || npcs.length == 0) {
return null; return null;
} }
return npcs[0]; return npcs[0];
} }
@@ -98,12 +101,12 @@ public class Npcs {
* Returns array with the first index to be the nearest Npc * Returns array with the first index to be the nearest Npc
* *
* @param filter * @param filter
*
* @return nearest Npcs * @return nearest Npcs
*/ */
public static final Npc[] getNearest(final Filter<Npc> filter) { public static final Npc[] getNearest(final Filter<Npc> filter) {
final Npc[] npcs = getNpcs(filter); final Npc[] npcs = getNpcs(filter);
Arrays.sort(npcs, NEAREST_SORTER); Arrays.sort(npcs, NEAREST_SORTER);
return npcs; return npcs;
} }
@@ -111,7 +114,6 @@ public class Npcs {
* Gets nearest npcs which hold given id(s) * Gets nearest npcs which hold given id(s)
* *
* @param ids * @param ids
*
* @return array of npcs with the first index to be the nearest * @return array of npcs with the first index to be the nearest
*/ */
public static final Npc[] getNearest(final int... ids) { public static final Npc[] getNearest(final int... ids) {
@@ -119,18 +121,20 @@ public class Npcs {
@Override @Override
public boolean accept(Npc npc) { public boolean accept(Npc npc) {
if (npc.getDef() != null){ if (npc.getDef() != null) {
for (final int id : ids) { for (final int id : ids) {
if (id == npc.getDef().getId()) { if (id == npc.getDef().getId()) {
return true; return true;
} }
} }
} }
return false; return false;
} }
}); });
Arrays.sort(npcs, NEAREST_SORTER); Arrays.sort(npcs, NEAREST_SORTER);
return npcs; return npcs;
} }
@@ -143,7 +147,7 @@ public class Npcs {
return getNearest(ALL_FILTER); return getNearest(ALL_FILTER);
} }
public enum Option{ public enum Option {
FIRST(settings.get("menu_character_first_interaction")), FIRST(settings.get("menu_character_first_interaction")),
ATTACK(settings.get("menu_character_first_interaction")), ATTACK(settings.get("menu_character_first_interaction")),
@@ -170,7 +174,7 @@ public class Npcs {
EXAMINE(settings.get("menu_character_examine")); EXAMINE(settings.get("menu_character_examine"));
int actionId; private int actionId;
Option(int actionId) { Option(int actionId) {
this.actionId = actionId; this.actionId = actionId;
@@ -6,7 +6,10 @@ import org.rev317.min.Loader;
import org.rev317.min.accessors.Client; import org.rev317.min.accessors.Client;
import org.rev317.min.api.wrappers.Player; import org.rev317.min.api.wrappers.Player;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
/** /**
* @author Everel, JKetelaar * @author Everel, JKetelaar
@@ -36,12 +39,11 @@ public class Players {
* Gets all players except local player * Gets all players except local player
* *
* @param filter * @param filter
*
* @return all players * @return all players
*/ */
public static final Player[] getPlayers(final Filter<Player> filter) { public static final Player[] getPlayers(final Filter<Player> filter) {
final Client client = Loader.getClient(); final Client client = Loader.getClient();
ArrayList<Player> playerList = new ArrayList<Player>(); ArrayList<Player> playerList = new ArrayList<>();
final org.rev317.min.accessors.Player[] accPlayers = client.getPlayers(); final org.rev317.min.accessors.Player[] accPlayers = client.getPlayers();
for (int i = 0; i < accPlayers.length; i++) { for (int i = 0; i < accPlayers.length; i++) {
if (accPlayers[i] == null) { if (accPlayers[i] == null) {
@@ -52,6 +54,7 @@ public class Players {
playerList.add(player); playerList.add(player);
} }
} }
return playerList.toArray(new Player[playerList.size()]); return playerList.toArray(new Player[playerList.size()]);
} }
@@ -68,7 +71,6 @@ public class Players {
* Returns array with the first index to be the nearest player * Returns array with the first index to be the nearest player
* *
* @param filter * @param filter
*
* @return nearest players * @return nearest players
*/ */
public static final Player[] getNearest(final Filter<Player> filter) { public static final Player[] getNearest(final Filter<Player> filter) {
@@ -95,7 +97,7 @@ public class Players {
return new Player(Loader.getClient().getMyPlayer(), -1); return new Player(Loader.getClient().getMyPlayer(), -1);
} }
public enum Option{ public enum Option {
FIRST(settings.get("menu_character_first_interaction")), FIRST(settings.get("menu_character_first_interaction")),
SECOND(settings.get("menu_character_second_interaction")), SECOND(settings.get("menu_character_second_interaction")),
@@ -115,7 +117,7 @@ public class Players {
EXAMINE(settings.get("menu_character_examine")); EXAMINE(settings.get("menu_character_examine"));
int actionId; private int actionId;
Option(int actionId) { Option(int actionId) {
this.actionId = actionId; this.actionId = actionId;
@@ -12,14 +12,63 @@ import java.util.ArrayList;
*/ */
public class Prayer { public class Prayer {
public interface Book { public static boolean isEnabled(Book book) {
public int getSetting(); return Game.getSetting(book.getSetting()) == 1;
}
public int getAction(); public static void enable(final Book book) {
if (!isEnabled(book)) {
Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return isEnabled(book);
}
}, 1500);
}
}
public int getLevel(); public static void disable(final Book book) {
if (isEnabled(book)) {
Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return !isEnabled(book);
}
}, 1500);
}
}
public String getName(); public static Book[] getActivePrayers() {
ArrayList<Book> prayers = new ArrayList<>();
for (Book normal : Normal.values()) {
if (isEnabled(normal)) {
prayers.add(normal);
}
}
for (Book curse : Curse.values()) {
if (isEnabled(curse)) {
prayers.add(curse);
}
}
return prayers.toArray(new Book[prayers.size()]);
}
public static void setActivePrayers(Book[] prayers) {
for (Book book : prayers) {
for (Book normal : Normal.values()) {
if (!isEnabled(normal) && normal.equals(book)) {
enable(normal);
}
}
for (Book curse : Curse.values()) {
if (!isEnabled(curse) && curse.equals(book)) {
enable(curse);
}
}
}
} }
public enum Normal implements Book { public enum Normal implements Book {
@@ -176,62 +225,13 @@ public class Prayer {
} }
public interface Book {
int getSetting();
public static boolean isEnabled(Book book) { int getAction();
return Game.getSetting(book.getSetting()) == 1;
}
public static void enable(final Book book) { int getLevel();
if (!isEnabled(book)) {
Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return isEnabled(book);
}
}, 1500);
}
}
public static void disable(final Book book) { String getName();
if (isEnabled(book)) {
Menu.sendAction(169, -1, -1, book.getAction());
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return !isEnabled(book);
}
}, 1500);
}
}
public static Book[] getActivePrayers() {
ArrayList<Book> prayers = new ArrayList<>();
for (Book normal : Normal.values()) {
if (isEnabled(normal)) {
prayers.add(normal);
}
}
for (Book curse : Curse.values()) {
if (isEnabled(curse)) {
prayers.add(curse);
}
}
return prayers.toArray(new Book[prayers.size()]);
}
public static void setActivePrayers(Book[] prayers) {
for (Book book : prayers) {
for (Book normal : Normal.values()) {
if (!isEnabled(normal) && normal.equals(book)) {
enable(normal);
}
}
for (Book curse : Curse.values()) {
if (!isEnabled(curse) && curse.equals(book)) {
enable(curse);
}
}
}
} }
} }
@@ -40,16 +40,17 @@ public class SceneObjects {
* @return scene objects * @return scene objects
*/ */
public static final SceneObject[] getSceneObjects(Filter<SceneObject> filter) { public static final SceneObject[] getSceneObjects(Filter<SceneObject> filter) {
ArrayList<SceneObject> sceneObjects = new ArrayList<SceneObject>(); ArrayList<SceneObject> sceneObjects = new ArrayList<>();
for (int x = 0; x < 104; x++) { for (int x = 0; x < 104; x++) {
for (int y = 0; y < 104; y++) { for (int y = 0; y < 104; y++) {
final SceneObject sceneObjectAtTile = getSceneObjectAtTile(x, y, true); final SceneObject sceneObjectAtTile = getSceneObjectAtTile(x, y);
if (sceneObjectAtTile != null && filter.accept(sceneObjectAtTile)) { if (sceneObjectAtTile != null && filter.accept(sceneObjectAtTile)) {
sceneObjects.add(sceneObjectAtTile); sceneObjects.add(sceneObjectAtTile);
} }
} }
} }
return sceneObjects.toArray(new SceneObject[sceneObjects.size()]); return sceneObjects.toArray(new SceneObject[sceneObjects.size()]);
} }
@@ -66,12 +67,12 @@ public class SceneObjects {
* Returns array of sceneobjects with the first index to be the nearest * Returns array of sceneobjects with the first index to be the nearest
* *
* @param filter * @param filter
*
* @return sceneobjects * @return sceneobjects
*/ */
public static final SceneObject[] getNearest(Filter<SceneObject> filter) { public static final SceneObject[] getNearest(Filter<SceneObject> filter) {
final SceneObject[] objects = getSceneObjects(filter); final SceneObject[] objects = getSceneObjects(filter);
Arrays.sort(objects, NEAREST_SORTER); Arrays.sort(objects, NEAREST_SORTER);
return objects; return objects;
} }
@@ -88,7 +89,6 @@ public class SceneObjects {
* Returns nearest objects with given id * Returns nearest objects with given id
* *
* @param ids * @param ids
*
* @return sceneobjects * @return sceneobjects
*/ */
public static final SceneObject[] getNearest(final int... ids) { public static final SceneObject[] getNearest(final int... ids) {
@@ -101,6 +101,7 @@ public class SceneObjects {
return true; return true;
} }
} }
return false; return false;
} }
@@ -109,7 +110,6 @@ public class SceneObjects {
public static final SceneObject getClosest(final int... ids) { public static final SceneObject getClosest(final int... ids) {
SceneObject[] nearestObjects = getNearest(new Filter<SceneObject>() { SceneObject[] nearestObjects = getNearest(new Filter<SceneObject>() {
@Override @Override
public boolean accept(SceneObject object) { public boolean accept(SceneObject object) {
for (final int id : ids) { for (final int id : ids) {
@@ -117,34 +117,37 @@ public class SceneObjects {
return true; return true;
} }
} }
return false; return false;
} }
}); });
if (nearestObjects == null || nearestObjects.length == 0) { if (nearestObjects == null || nearestObjects.length == 0) {
return null; return null;
} }
return nearestObjects[0]; return nearestObjects[0];
} }
private static SceneObject getSceneObjectAtTile(int x, int y, boolean useCached) { private static SceneObject getSceneObjectAtTile(int x, int y) {
Ground sceneTile = Loader.getClient().getScene().getGroundArray()[Game.getPlane()][x][y]; Ground sceneTile = Loader.getClient().getScene().getGroundArray()[Game.getPlane()][x][y];
if (sceneTile == null) { if (sceneTile == null) {
return null; return null;
} }
final SceneObjectTile[] interactiveObjects = sceneTile.getInteractiveObjects(); final SceneObjectTile[] interactiveObjects = sceneTile.getInteractiveObjects();
if (interactiveObjects != null) { if (interactiveObjects != null) {
for (final SceneObjectTile interactiveObject : interactiveObjects) { for (final SceneObjectTile interactiveObject : interactiveObjects) {
// get top
if (interactiveObject != null) { if (interactiveObject != null) {
return new SceneObject(interactiveObject, SceneObject.TYPE_INTERACTIVE); return new SceneObject(interactiveObject, SceneObject.TYPE_INTERACTIVE);
} }
} }
} }
SceneObjectTile sceneObjectTile = sceneTile.getWallObject(); SceneObjectTile sceneObjectTile = sceneTile.getWallObject();
if (sceneObjectTile != null) { if (sceneObjectTile != null) {
return new SceneObject(sceneObjectTile, SceneObject.TYPE_WALL); return new SceneObject(sceneObjectTile, SceneObject.TYPE_WALL);
} }
return null; return null;
} }
@@ -154,15 +157,16 @@ public class SceneObjects {
* @return every loaded scene object in game * @return every loaded scene object in game
*/ */
public static final SceneObject[] getAllSceneObjects() { public static final SceneObject[] getAllSceneObjects() {
ArrayList<SceneObject> sceneObjects = new ArrayList<SceneObject>(); ArrayList<SceneObject> sceneObjects = new ArrayList<>();
for (int x = 0; x < 104; x++) { for (int x = 0; x < 104; x++) {
for (int y = 0; y < 104; y++) { for (int y = 0; y < 104; y++) {
final Collection<SceneObject> sceneObjectsAtTile = getSceneObjectsAtTile(x, y, true); final Collection<SceneObject> sceneObjectsAtTile = getSceneObjectsAtTile(x, y);
if (sceneObjectsAtTile != null && !sceneObjectsAtTile.isEmpty()) { if (sceneObjectsAtTile != null && !sceneObjectsAtTile.isEmpty()) {
sceneObjects.addAll(sceneObjectsAtTile); sceneObjects.addAll(sceneObjectsAtTile);
} }
} }
} }
return sceneObjects.toArray(new SceneObject[sceneObjects.size()]); return sceneObjects.toArray(new SceneObject[sceneObjects.size()]);
} }
@@ -171,11 +175,9 @@ public class SceneObjects {
* *
* @param x * @param x
* @param y * @param y
* @param useCached
*
* @return array of sceneobjects, or null if there aren't any * @return array of sceneobjects, or null if there aren't any
*/ */
public static final Collection<SceneObject> getSceneObjectsAtTile(int x, int y, boolean useCached) { public static final Collection<SceneObject> getSceneObjectsAtTile(int x, int y) {
Ground sceneTile = Loader.getClient().getScene().getGroundArray()[Game.getPlane()][x][y]; Ground sceneTile = Loader.getClient().getScene().getGroundArray()[Game.getPlane()][x][y];
ArrayList<SceneObject> sceneObjects = null; ArrayList<SceneObject> sceneObjects = null;
if (sceneTile != null) { if (sceneTile != null) {
@@ -222,10 +224,12 @@ public class SceneObjects {
sceneObjects.add(new SceneObject(sceneObjectTile, SceneObject.TYPE_GROUNDITEM)); sceneObjects.add(new SceneObject(sceneObjectTile, SceneObject.TYPE_GROUNDITEM));
} }
} }
return sceneObjects; return sceneObjects;
} }
public enum Option{
public enum Option {
FIRST(settings.get("menu_scene_object_first_interaction")), FIRST(settings.get("menu_scene_object_first_interaction")),
TALK_TO(settings.get("menu_scene_object_first_interaction")), TALK_TO(settings.get("menu_scene_object_first_interaction")),
CHOP_DOWN(settings.get("menu_scene_object_first_interaction")), CHOP_DOWN(settings.get("menu_scene_object_first_interaction")),
@@ -256,7 +260,7 @@ public class SceneObjects {
EXAMINE(settings.get("menu_scene_object_examine")); EXAMINE(settings.get("menu_scene_object_examine"));
int actionId; private int actionId;
Option(int actionId) { Option(int actionId) {
this.actionId = actionId; this.actionId = actionId;
@@ -266,6 +270,4 @@ public class SceneObjects {
return actionId; return actionId;
} }
} }
} }
@@ -30,7 +30,6 @@ public enum Skill {
* Returns the experience of the provided skill. * Returns the experience of the provided skill.
* *
* @param index the skill index. * @param index the skill index.
*
* @return the experience. * @return the experience.
*/ */
public static final int getCurrentExperience(int index) { public static final int getCurrentExperience(int index) {
@@ -41,7 +40,6 @@ public enum Skill {
* Returns the real level of the provided skill. * Returns the real level of the provided skill.
* *
* @param index the skill index. * @param index the skill index.
*
* @return the real skill level. * @return the real skill level.
*/ */
public static final int getRealLevel(int index) { public static final int getRealLevel(int index) {
@@ -52,7 +50,6 @@ public enum Skill {
* Returns the current level of the provided skill. (Will return de-buffed/buffed levels) * Returns the current level of the provided skill. (Will return de-buffed/buffed levels)
* *
* @param index the skill index. * @param index the skill index.
*
* @return the current skill level. Done by Bears * @return the current skill level. Done by Bears
*/ */
public static final int getCurrentLevel(int index) { public static final int getCurrentLevel(int index) {
@@ -63,13 +60,13 @@ public enum Skill {
* Returns the exact experience at the provided level. * Returns the exact experience at the provided level.
* *
* @param level the level. * @param level the level.
*
* @return the experience at the provided level. * @return the experience at the provided level.
*/ */
public static final int getExperienceByLevel(int level) { public static final int getExperienceByLevel(int level) {
if (level > 99 || level < 1) { if (level > 99 || level < 1) {
return 0; return 0;
} }
return EXPERIENCE[level]; return EXPERIENCE[level];
} }
@@ -77,7 +74,6 @@ public enum Skill {
* Returns the exact level with the provided experience. * Returns the exact level with the provided experience.
* *
* @param experience the experience. * @param experience the experience.
*
* @return the level at the provided experience. * @return the level at the provided experience.
*/ */
public static final int getLevelByExperience(int experience) { public static final int getLevelByExperience(int experience) {
@@ -86,6 +82,7 @@ public enum Skill {
return i; return i;
} }
} }
return 1; return 1;
} }
@@ -93,7 +90,6 @@ public enum Skill {
* Returns the remaining experience for the provided skill to level up. * Returns the remaining experience for the provided skill to level up.
* *
* @param index the skill index. * @param index the skill index.
*
* @return the remaining experience. * @return the remaining experience.
*/ */
public static final int getRemainingExperience(int index) { public static final int getRemainingExperience(int index) {
@@ -101,6 +97,7 @@ public enum Skill {
if (level >= 99 || level < 1) { if (level >= 99 || level < 1) {
return 0; return 0;
} }
return EXPERIENCE[(level + 1)] - getCurrentExperience(index); return EXPERIENCE[(level + 1)] - getCurrentExperience(index);
} }
@@ -108,7 +105,6 @@ public enum Skill {
* Returns the percentage to the next level for the provided skill. * Returns the percentage to the next level for the provided skill.
* *
* @param index the skill index. * @param index the skill index.
*
* @return the remaining percentage. * @return the remaining percentage.
*/ */
public static final int getPercentToNextLevel(int index) { public static final int getPercentToNextLevel(int index) {
@@ -118,11 +114,12 @@ public enum Skill {
|| nextLevel < 1) { || nextLevel < 1) {
return 0; return 0;
} }
return (int) (100f * ((float) getCurrentExperience(index) / (float) EXPERIENCE[nextLevel])); return (int) (100f * ((float) getCurrentExperience(index) / (float) EXPERIENCE[nextLevel]));
} }
/** /**
* @Deprecated use Skill.ordinal() instead Returns the skill's index. * @deprecated use Skill.ordinal() instead Returns the skill's index.
*/ */
public int getIndex() { public int getIndex() {
return ordinal(); return ordinal();
@@ -132,22 +129,21 @@ public enum Skill {
* Returns the name of the skill. * Returns the name of the skill.
*/ */
public final String getName() { public final String getName() {
return Character.toUpperCase(name().charAt(0)) return Character.toUpperCase(name().charAt(0)) + name().toLowerCase().substring(1);
+ name().toLowerCase().substring(1);
} }
/** /**
* Returns the current experience. * Returns the current experience.
*/ */
public final int getExperience() { public final int getExperience() {
return Skill.getCurrentExperience(this.getIndex()); return Skill.getCurrentExperience(this.ordinal());
} }
/** /**
* Returns the real level. * Returns the real level.
*/ */
public final int getRealLevel() { public final int getRealLevel() {
return Skill.getRealLevel(this.getIndex()); return Skill.getRealLevel(this.ordinal());
} }
/** /**
@@ -155,21 +151,21 @@ public enum Skill {
* stat; it will return the buffed level.) Done by Bears * stat; it will return the buffed level.) Done by Bears
*/ */
public final int getLevel() { public final int getLevel() {
return Skill.getCurrentLevel(this.getIndex()); return Skill.getCurrentLevel(this.ordinal());
} }
/** /**
* Returns the remaining experience until the next level. * Returns the remaining experience until the next level.
*/ */
public final int getRemaining() { public final int getRemaining() {
return Skill.getRemainingExperience(this.getIndex()); return Skill.getRemainingExperience(this.ordinal());
} }
/** /**
* Returns the percentage until the next level. * Returns the percentage until the next level.
*/ */
public final int getPercentage() { public final int getPercentage() {
return Skill.getPercentToNextLevel(this.getIndex()); return Skill.getPercentToNextLevel(this.ordinal());
} }
/** /**
@@ -177,7 +173,6 @@ public enum Skill {
*/ */
@Override @Override
public final String toString() { public final String toString() {
return "Skill: [" + this.getName() + ": " + this.getLevel() + " / " return "Skill: [" + this.getName() + ": " + this.getLevel() + " / " + this.getRealLevel() + "]";
+ this.getRealLevel() + "]";
} }
} }
@@ -2,9 +2,7 @@ package org.rev317.min.api.methods;
import org.parabot.core.Context; import org.parabot.core.Context;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import org.parabot.environment.input.Mouse;
import org.parabot.environment.scripts.framework.SleepCondition; import org.parabot.environment.scripts.framework.SleepCondition;
import org.rev317.min.Loader;
import org.rev317.min.accessors.Interface; import org.rev317.min.accessors.Interface;
import org.rev317.min.api.wrappers.Item; import org.rev317.min.api.wrappers.Item;
@@ -20,26 +18,28 @@ public class Trading {
/** /**
* Checks if the first or the second screen is open, based on the given boolean * Checks if the first or the second screen is open, based on the given boolean
*
* @param first If true, the first trade screen will be checked. If false, the second screen will be checked * @param first If true, the first trade screen will be checked. If false, the second screen will be checked
* @return True if the requested screen is open * @return True if the requested screen is open
*/ */
public static boolean isOpen(boolean first){ public static boolean isOpen(boolean first) {
return Interfaces.getOpenInterfaceId() == (first ? settings.get("first_trade_interface_id") : settings.get("second_trade_interface_id")); return Interfaces.getOpenInterfaceId() == (first ? settings.get("first_trade_interface_id") : settings.get("second_trade_interface_id"));
} }
/** /**
* Checks if any of the trade screens are open * Checks if any of the trade screens are open
*
* @return True if open, false if not open * @return True if open, false if not open
*/ */
public static boolean isOpen(){ public static boolean isOpen() {
return Interfaces.getOpenInterfaceId() == settings.get("first_trade_interface_id") || Interfaces.getOpenInterfaceId() == settings.get("second_trade_interface_id"); return Interfaces.getOpenInterfaceId() == settings.get("first_trade_interface_id") || Interfaces.getOpenInterfaceId() == settings.get("second_trade_interface_id");
} }
/** /**
* Still in development * Still in development
* For now it simply walks away from the trade by walking to the location of the player * For now it simply walks away from the trade by walking to the location of the player
*/ */
public static void close(){ public static void close() {
Players.getMyPlayer().getLocation().walkTo(); Players.getMyPlayer().getLocation().walkTo();
Time.sleep(new SleepCondition() { Time.sleep(new SleepCondition() {
@Override @Override
@@ -98,7 +98,7 @@ public class Trading {
/** /**
* TODO: Add the id into the settings * TODO: Add the id into the settings
* * <p>
* Accepts the offer and hits the button to continue to the second screen * Accepts the offer and hits the button to continue to the second screen
*/ */
public static void acceptOffer() { public static void acceptOffer() {
@@ -113,7 +113,7 @@ public class Trading {
/** /**
* TODO: Add the id into the settings * TODO: Add the id into the settings
* * <p>
* Accepts the trade and hits the button to complete the trade * Accepts the trade and hits the button to complete the trade
*/ */
public static void acceptTrade() { public static void acceptTrade() {
@@ -42,6 +42,7 @@ public class Walking {
if (tilePath.hasReached()) { if (tilePath.hasReached()) {
return true; return true;
} }
tilePath.traverse(); tilePath.traverse();
return false; return false;
} }
@@ -61,8 +62,7 @@ public class Walking {
tile = new Tile((loc.getX() + tile.getX()) / 2, tile = new Tile((loc.getX() + tile.getX()) / 2,
(loc.getY() + tile.getY()) / 2); (loc.getY() + tile.getY()) / 2);
} }
return null; return null;
} }
} }
@@ -4,9 +4,7 @@ import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
*
* @author Matt, JKetelaar * @author Matt, JKetelaar
*
*/ */
public class Area { public class Area {
private Polygon p; private Polygon p;
@@ -14,8 +12,7 @@ public class Area {
/** /**
* Initializes a PolygonArea with the tiles given * Initializes a PolygonArea with the tiles given
* *
* @param tiles * @param tiles tiles to use in the area
* tiles to use in the area
*/ */
public Area(Tile... tiles) { public Area(Tile... tiles) {
this.p = new Polygon(); this.p = new Polygon();
@@ -27,8 +24,7 @@ public class Area {
/** /**
* Adds a tile to the area * Adds a tile to the area
* *
* @param t * @param t The tile to add the area
* The tile to add the area
*/ */
public void addTile(Tile t) { public void addTile(Tile t) {
p.addPoint(t.getX(), t.getY()); p.addPoint(t.getX(), t.getY());
@@ -41,8 +37,10 @@ public class Area {
*/ */
public Tile[] getPoints() { public Tile[] getPoints() {
Tile[] tiles = new Tile[p.npoints]; Tile[] tiles = new Tile[p.npoints];
for (int i = 0; i < tiles.length; i++) for (int i = 0; i < tiles.length; i++) {
tiles[i] = new Tile(p.xpoints[i], p.ypoints[i]); tiles[i] = new Tile(p.xpoints[i], p.ypoints[i]);
}
return tiles; return tiles;
} }
@@ -80,14 +78,14 @@ public class Area {
} }
} }
} }
return t.toArray(new Tile[t.size()]); return t.toArray(new Tile[t.size()]);
} }
/** /**
* Checks if a tile is in the area * Checks if a tile is in the area
* *
* @param tile * @param tile The tile to check
* The tile to check
* @return <b>true</b> if area does contain the tile, otherwise <b>false</b> * @return <b>true</b> if area does contain the tile, otherwise <b>false</b>
*/ */
public boolean contains(Tile tile) { public boolean contains(Tile tile) {
@@ -99,7 +97,6 @@ public class Area {
* *
* @param x The x-axis from the tile * @param x The x-axis from the tile
* @param y The y-axis from the tile * @param y The y-axis from the tile
*
* @return True if the area does contain the tile, otherwise false * @return True if the area does contain the tile, otherwise false
*/ */
public boolean contains(int x, int y) { public boolean contains(int x, int y) {
@@ -113,7 +110,7 @@ public class Area {
result = !result; result = !result;
} }
} }
return result; return result;
} }
} }
@@ -142,6 +142,7 @@ public class Character implements Locatable {
return Players.getMyPlayer(); return Players.getMyPlayer();
} }
} }
return null; return null;
} }
@@ -161,26 +162,32 @@ public class Character implements Locatable {
result = prime * result result = prime * result
+ ((accessor == null) ? 0 : accessor.hashCode()); + ((accessor == null) ? 0 : accessor.hashCode());
result = prime * result + index; result = prime * result + index;
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
Character other = (Character) obj; Character other = (Character) obj;
if (accessor == null) { if (accessor == null) {
if (other.accessor != null) if (other.accessor != null) {
return false; return false;
} else if (!accessor.equals(other.accessor)) }
} else if (!accessor.equals(other.accessor)) {
return false; return false;
if (index != other.index) }
return false;
return true; return index == other.index;
} }
public org.rev317.min.accessors.Character getAccessor() { public org.rev317.min.accessors.Character getAccessor() {
@@ -2,7 +2,10 @@ package org.rev317.min.api.wrappers;
import org.parabot.core.reflect.RefClass; import org.parabot.core.reflect.RefClass;
import org.rev317.min.api.interfaces.Locatable; import org.rev317.min.api.interfaces.Locatable;
import org.rev317.min.api.methods.*; import org.rev317.min.api.methods.Calculations;
import org.rev317.min.api.methods.Game;
import org.rev317.min.api.methods.GroundItems;
import org.rev317.min.api.methods.Menu;
/** /**
* @author Everel * @author Everel
@@ -57,9 +60,8 @@ public class GroundItem implements Locatable {
/** /**
* Interacts with this ground item * Interacts with this ground item
* *
* @deprecated
*
* @param actionIndex * @param actionIndex
* @deprecated
*/ */
public void interact(int actionIndex) { public void interact(int actionIndex) {
Menu.interact(this, actionIndex); Menu.interact(this, actionIndex);
@@ -98,5 +100,4 @@ public class GroundItem implements Locatable {
public RefClass getRefClass() { public RefClass getRefClass() {
return new RefClass(this.accessor); return new RefClass(this.accessor);
} }
} }
@@ -60,7 +60,6 @@ public class Item {
} }
/** /**
*
* @param option * @param option
* @param interfaceParentId * @param interfaceParentId
*/ */
@@ -71,9 +70,8 @@ public class Item {
/** /**
* Interacts with this item * Interacts with this item
* *
* @deprecated
*
* @param i * @param i
* @deprecated
*/ */
public void interact(int i) { public void interact(int i) {
Menu.interact(this, i); Menu.interact(this, i);
@@ -82,19 +80,17 @@ public class Item {
/** /**
* Interacts with this item * Interacts with this item
* *
* @deprecated
*
* @param s * @param s
* @deprecated
*/ */
public void interact(String s){ public void interact(String s) {
Menu.interact(this, s); Menu.interact(this, s);
} }
/** /**
* @deprecated
*
* @param actionIndex * @param actionIndex
* @param interfaceParentId * @param interfaceParentId
* @deprecated
*/ */
public void transform(int actionIndex, int interfaceParentId) { public void transform(int actionIndex, int interfaceParentId) {
Menu.transformItem(this, actionIndex, interfaceParentId); Menu.transformItem(this, actionIndex, interfaceParentId);
@@ -42,5 +42,4 @@ public final class Npc extends Character {
public void interact(Npcs.Option option) { public void interact(Npcs.Option option) {
Menu.interact(this, option); Menu.interact(this, option);
} }
} }
@@ -3,7 +3,7 @@ package org.rev317.min.api.wrappers;
import org.parabot.core.reflect.RefClass; import org.parabot.core.reflect.RefClass;
/** /**
* @author Everel * @author Everel, JKetelaar, EmmaStone
*/ */
public class NpcDef { public class NpcDef {
private org.rev317.min.accessors.NpcDef accessor; private org.rev317.min.accessors.NpcDef accessor;
@@ -18,10 +18,43 @@ public class NpcDef {
* @return id of this item * @return id of this item
*/ */
public int getId() { public int getId() {
if (accessor != null) { return getId(false);
}
/**
* Gets id of this item
*
* @param avoidLong defines if it should check if long id exists
* @return id of this item
*/
private int getId(boolean avoidLong) {
if (avoidLong) {
return accessor.getId(); return accessor.getId();
} else {
try {
long id = getLongId();
if (id > Integer.MAX_VALUE){
throw new NoSuchMethodException("This server only supports long ids; change NpcDef#getId to NpcDef#getLongId");
}
return (int) id;
} catch (Exception e) {
return accessor.getId();
}
}
}
/**
* Gets id of this item
* Meant for servers with longs as ids, instead of ints
*
* @return id of this item
*/
private long getLongId() {
try {
return accessor.getLongId();
} catch (Exception e) {
return getId(true);
} }
return -1;
} }
/** /**
@@ -32,6 +65,4 @@ public class NpcDef {
public RefClass getRefClass() { public RefClass getRefClass() {
return new RefClass(this.accessor); return new RefClass(this.accessor);
} }
} }
@@ -12,7 +12,7 @@ public class Player extends Character {
super(accessor, index); super(accessor, index);
} }
public String getName(){ public String getName() {
return getAccessor().getName(); return getAccessor().getName();
} }
@@ -101,9 +101,8 @@ public class SceneObject implements Locatable {
/** /**
* Interacts with this object * Interacts with this object
* *
* @deprecated
*
* @param actionIndex * @param actionIndex
* @deprecated
*/ */
public void interact(int actionIndex) { public void interact(int actionIndex) {
Menu.interact(this, actionIndex); Menu.interact(this, actionIndex);
@@ -122,5 +121,4 @@ public class SceneObject implements Locatable {
public String toString() { public String toString() {
return String.format("[ID: %d, X: %d, Y: %d]", getId(), getLocalRegionX(), getLocalRegionY()); return String.format("[ID: %d, X: %d, Y: %d]", getId(), getLocalRegionX(), getLocalRegionY());
} }
} }
@@ -27,11 +27,12 @@ public class TilePath {
*/ */
public final Tile getNextTile() { public final Tile getNextTile() {
Tile next = null; Tile next = null;
for (int x = 0; x < tiles.length; x++) { for (Tile tile : tiles) {
if (tiles[x].isOnMinimap()) { if (tile.isOnMinimap()) {
next = tiles[x]; next = tile;
} }
} }
return next; return next;
} }
@@ -61,6 +62,7 @@ public class TilePath {
if (next == null) { if (next == null) {
return; return;
} }
next.walkTo(); next.walkTo();
} }
@@ -71,10 +73,10 @@ public class TilePath {
*/ */
public final TilePath reverse() { public final TilePath reverse() {
Tile[] newTiles = new Tile[tiles.length]; Tile[] newTiles = new Tile[tiles.length];
for (int i = 0; i < tiles.length; i++) for (int i = 0; i < tiles.length; i++) {
newTiles[i] = tiles[tiles.length - i - 1]; newTiles[i] = tiles[tiles.length - i - 1];
}
return new TilePath(newTiles); return new TilePath(newTiles);
} }
} }
@@ -8,9 +8,7 @@ import org.rev317.min.debug.DActions;
import org.rev317.min.script.ScriptEngine; import org.rev317.min.script.ScriptEngine;
/** /**
* @author Everel * @author Everel, JKetelaar, Matt123337
* @author JKetelaar
* @author Matt123337
*/ */
public class MenuAction { public class MenuAction {
@@ -10,5 +10,4 @@ public class MessageCallback {
final MessageEvent messageEvent = new MessageEvent(type, name, message); final MessageEvent messageEvent = new MessageEvent(type, name, message);
ScriptEngine.getInstance().dispatch(messageEvent); ScriptEngine.getInstance().dispatch(messageEvent);
} }
} }
@@ -24,5 +24,4 @@ public class DActions extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -23,5 +23,4 @@ public class DAnimation extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -23,6 +23,7 @@ public class DBank extends AbstractDebugger {
if (!Bank.isOpen()) { if (!Bank.isOpen()) {
return; return;
} }
Item[] items; Item[] items;
if ((items = Bank.getBankItems()) != null) { if ((items = Bank.getBankItems()) != null) {
for (int i = items.length - 1; i >= 0; i--) { for (int i = items.length - 1; i >= 0; i--) {
@@ -32,5 +33,4 @@ public class DBank extends AbstractDebugger {
} }
} }
} }
} }
@@ -35,5 +35,4 @@ public class DCollisionFlags extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -28,5 +28,4 @@ public class DGroundItems extends AbstractDebugger {
System.out.println("ID: " + item.getId() + " Location: " + item.getLocation()); System.out.println("ID: " + item.getId() + " Location: " + item.getLocation());
} }
} }
} }
@@ -26,5 +26,4 @@ public class DInterfaces extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -41,12 +41,13 @@ public class DInventory extends AbstractDebugger {
} }
} }
public int getSlotItemID(int slot){ public int getSlotItemID(int slot) {
for (Item item : Inventory.getItems()){ for (Item item : Inventory.getItems()) {
if (item.getSlot() == slot){ if (item.getSlot() == slot) {
return item.getId(); return item.getId();
} }
} }
return 0; return 0;
} }
} }
@@ -27,5 +27,4 @@ public class DMap extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -22,9 +22,9 @@ public class DMessages extends AbstractDebugger implements MessageListener {
@Override @Override
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
if (enabled){ if (enabled) {
ScriptEngine.getInstance().addMessageListener(this); ScriptEngine.getInstance().addMessageListener(this);
}else{ } else {
ScriptEngine.getInstance().removeMessageListener(this); ScriptEngine.getInstance().removeMessageListener(this);
} }
} }
@@ -24,5 +24,4 @@ public class DMouse extends AbstractDebugger {
public void toggle() { public void toggle() {
enabled = !enabled; enabled = !enabled;
} }
} }
@@ -23,7 +23,5 @@ public class DNpcs extends AbstractDebugger {
for (Npc n : Npcs.getNearest()) { for (Npc n : Npcs.getNearest()) {
System.out.println("ID: " + n.getDef().getId() + " Distance: " + n.distanceTo() + " Location: " + n.getLocation().toString()); System.out.println("ID: " + n.getDef().getId() + " Distance: " + n.distanceTo() + " Location: " + n.getLocation().toString());
} }
} }
} }
@@ -12,7 +12,7 @@ import java.awt.*;
public class DPlayers extends AbstractDebugger { public class DPlayers extends AbstractDebugger {
@Override @Override
public void toggle() { public void toggle() {
for (Player player : Players.getNearest()){ for (Player player : Players.getNearest()) {
System.out.println("Username: " + player.getName() + " Index: " + player.getIndex() + " Distance: " + player.distanceTo() + " Location: " + player.getLocation().toString()); System.out.println("Username: " + player.getName() + " Index: " + player.getIndex() + " Distance: " + player.distanceTo() + " Location: " + player.getLocation().toString());
} }
} }
@@ -24,6 +24,5 @@ public class DPlayers extends AbstractDebugger {
@Override @Override
public void paint(Graphics graphics) { public void paint(Graphics graphics) {
} }
} }
@@ -31,5 +31,4 @@ public class DSceneObjects extends AbstractDebugger {
" Distance: " + objects[i].distanceTo()); " Distance: " + objects[i].distanceTo());
} }
} }
} }
@@ -20,7 +20,7 @@ import java.util.HashMap;
* @author matt123337 * @author matt123337
*/ */
public class ScriptEngine { public class ScriptEngine {
private static HashMap<Context, ScriptEngine> instances = new HashMap<Context, ScriptEngine>(); private static HashMap<Context, ScriptEngine> instances = new HashMap<>();
private ArrayList<MouseListener> mouseListeners; private ArrayList<MouseListener> mouseListeners;
private ArrayList<MouseMotionListener> mouseMotionListeners; private ArrayList<MouseMotionListener> mouseMotionListeners;
private ArrayList<MessageListener> messageListeners; private ArrayList<MessageListener> messageListeners;
@@ -29,10 +29,10 @@ public class ScriptEngine {
private Script script = null; private Script script = null;
private ScriptEngine() { private ScriptEngine() {
this.mouseListeners = new ArrayList<MouseListener>(); this.mouseListeners = new ArrayList<>();
this.mouseMotionListeners = new ArrayList<MouseMotionListener>(); this.mouseMotionListeners = new ArrayList<>();
this.messageListeners = new ArrayList<MessageListener>(); this.messageListeners = new ArrayList<>();
this.actionListeners = new ArrayList<GameActionListener>(); this.actionListeners = new ArrayList<>();
instances.put(Context.getInstance(), this); instances.put(Context.getInstance(), this);
} }
@@ -103,6 +103,7 @@ public class ScriptEngine {
if (script instanceof Paintable) { if (script instanceof Paintable) {
Context.getInstance().removePaintable((Paintable) script); Context.getInstance().removePaintable((Paintable) script);
} }
this.script = null; this.script = null;
} }
@@ -134,6 +135,7 @@ public class ScriptEngine {
if (!(event instanceof MouseEvent)) { if (!(event instanceof MouseEvent)) {
return; return;
} }
final MouseEvent e = (MouseEvent) event; final MouseEvent e = (MouseEvent) event;
for (final MouseListener m : mouseListeners) { for (final MouseListener m : mouseListeners) {
switch (e.getID()) { switch (e.getID()) {
@@ -176,6 +178,4 @@ public class ScriptEngine {
a.onGameAction(event); a.onGameAction(event);
} }
} }
} }
+2 -2
View File
@@ -67,7 +67,7 @@ public class BotMenu implements ActionListener {
actions.addSeparator(); actions.addSeparator();
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
for (int i = 0; i < MenuAction.getOutputs().length; i++){ for (int i = 0; i < MenuAction.getOutputs().length; i++) {
final int index = i; final int index = i;
JMenuItem debugOutput = new JRadioButtonMenuItem("Output: " + index); JMenuItem debugOutput = new JRadioButtonMenuItem("Output: " + index);
debugOutput.addActionListener(new ActionListener() { debugOutput.addActionListener(new ActionListener() {
@@ -87,6 +87,7 @@ public class BotMenu implements ActionListener {
private JMenuItem newItem(String name) { private JMenuItem newItem(String name) {
JMenuItem item = new JCheckBoxMenuItem(name); JMenuItem item = new JCheckBoxMenuItem(name);
item.addActionListener(this); item.addActionListener(this);
return item; return item;
} }
@@ -94,5 +95,4 @@ public class BotMenu implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Context.getInstance().getPaintDebugger().toggle(e.getActionCommand()); Context.getInstance().getPaintDebugger().toggle(e.getActionCommand());
} }
} }