Merge pull request #71 from Parabot/cleanup/code-cleanup

[CLEANUP] Code cleanup
This commit is contained in:
Jeroen Ketelaar
2017-02-03 19:49:21 +01:00
committed by GitHub
54 changed files with 143 additions and 123 deletions
+2
View File
@@ -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;
} }
} }
@@ -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();
} }
@@ -11,5 +11,4 @@ public interface Ground {
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;
} }
@@ -139,6 +138,7 @@ public class Bank {
} }
} }
} }
return null; return null;
} }
@@ -153,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);
} }
@@ -165,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() {
@@ -176,6 +176,7 @@ public class Bank {
}, 5000); }, 5000);
return; return;
} }
bank.interact(SceneObjects.Option.USE); bank.interact(SceneObjects.Option.USE);
} }
@@ -187,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"));
} }
@@ -229,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();
} }
@@ -241,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();
} }
@@ -253,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();
@@ -263,6 +268,7 @@ public class Bank {
} }
} }
} }
return items.toArray(new Item[items.size()]); return items.toArray(new Item[items.size()]);
} }
@@ -275,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);
} }
@@ -287,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;
} }
@@ -146,9 +146,10 @@ 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();
} }
@@ -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()]);
} }
@@ -75,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();
@@ -88,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;
} }
@@ -125,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];
} }
@@ -139,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];
} }
@@ -151,6 +156,7 @@ public class GroundItems {
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,7 +177,6 @@ public class GroundItems {
*/ */
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) {
@@ -179,9 +184,9 @@ public class GroundItems {
return true; return true;
} }
} }
return false; return false;
} }
}); });
} }
@@ -199,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;
@@ -40,9 +40,11 @@ public class Items {
return name; return name;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
} }
return null; return null;
} }
@@ -60,8 +62,10 @@ public class Items {
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
return new int[0]; return new int[0];
} }
@@ -85,8 +89,10 @@ public class Items {
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
return new int[0]; return new int[0];
} }
@@ -110,8 +116,10 @@ public class Items {
return ids; return ids;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
return new int[0]; return new int[0];
} }
@@ -130,7 +138,8 @@ public class Items {
return price; return price;
} }
} }
} catch (MalformedURLException | ParseException ignored) { } catch (MalformedURLException | ParseException e) {
e.printStackTrace();
} }
} }
return 0; return 0;
@@ -181,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);
} }
} }
@@ -54,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()]);
} }
@@ -77,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];
} }
@@ -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];
} }
@@ -103,6 +106,7 @@ public class 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;
} }
@@ -124,11 +128,13 @@ public class Npcs {
} }
} }
} }
return false; return false;
} }
}); });
Arrays.sort(npcs, NEAREST_SORTER); Arrays.sort(npcs, NEAREST_SORTER);
return npcs; return npcs;
} }
@@ -168,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;
@@ -43,7 +43,7 @@ public class 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) {
@@ -54,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()]);
} }
@@ -116,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;
@@ -52,6 +52,7 @@ public class Prayer {
prayers.add(curse); prayers.add(curse);
} }
} }
return prayers.toArray(new Book[prayers.size()]); return prayers.toArray(new Book[prayers.size()]);
} }
@@ -225,12 +226,12 @@ public class Prayer {
} }
public interface Book { public interface Book {
public int getSetting(); int getSetting();
public int getAction(); int getAction();
public int getLevel(); int getLevel();
public String getName(); String getName();
} }
} }
@@ -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()]);
} }
@@ -71,6 +72,7 @@ public class 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;
} }
@@ -99,6 +101,7 @@ public class SceneObjects {
return true; return true;
} }
} }
return false; return false;
} }
@@ -107,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) {
@@ -115,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;
} }
@@ -152,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()]);
} }
@@ -169,10 +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) {
@@ -219,9 +224,11 @@ 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")),
@@ -253,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;
@@ -263,6 +270,4 @@ public class SceneObjects {
return actionId; return actionId;
} }
} }
} }
@@ -66,6 +66,7 @@ public enum Skill {
if (level > 99 || level < 1) { if (level > 99 || level < 1) {
return 0; return 0;
} }
return EXPERIENCE[level]; return EXPERIENCE[level];
} }
@@ -81,6 +82,7 @@ public enum Skill {
return i; return i;
} }
} }
return 1; return 1;
} }
@@ -95,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);
} }
@@ -111,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();
@@ -125,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());
} }
/** /**
@@ -148,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());
} }
/** /**
@@ -170,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() + "]";
} }
} }
@@ -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;
} }
} }
@@ -37,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;
} }
@@ -76,6 +78,7 @@ public class Area {
} }
} }
} }
return t.toArray(new Tile[t.size()]); return t.toArray(new Tile[t.size()]);
} }
@@ -107,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() {
@@ -100,5 +100,4 @@ public class GroundItem implements Locatable {
public RefClass getRefClass() { public RefClass getRefClass() {
return new RefClass(this.accessor); return new RefClass(this.accessor);
} }
} }
@@ -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);
} }
} }
@@ -23,12 +23,13 @@ public class NpcDef {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return -1; return -1;
} }
private long getLongId() { private long getLongId() {
if (accessor != null) { if (accessor != null) {
if (accessor.getId() < Integer.MAX_VALUE) { if (accessor.getLongId() < Integer.MAX_VALUE) {
return (long) accessor.getId(); return (long) accessor.getId();
} }
} }
@@ -45,5 +46,4 @@ public class NpcDef {
public RefClass getRefClass() { public RefClass getRefClass() {
return new RefClass(this.accessor); return new RefClass(this.accessor);
} }
} }
@@ -121,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());
} }
} }
@@ -116,6 +116,7 @@ public final class Tile implements TileFlags, Locatable {
hash = 31 * hash + this.x; hash = 31 * hash + this.x;
hash = 31 * hash + this.y; hash = 31 * hash + this.y;
hash = 31 * hash + this.z; hash = 31 * hash + this.z;
return hash; return hash;
} }
@@ -171,5 +172,4 @@ public final class Tile implements TileFlags, Locatable {
public Tile getLocation() { public Tile getLocation() {
return this; return this;
} }
} }
@@ -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;
} }
} }
@@ -47,6 +47,7 @@ public class DInventory extends AbstractDebugger {
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;
} }
} }
@@ -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());
} }
} }
} }
@@ -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);
} }
} }
} }
+1 -1
View File
@@ -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());
} }
} }