From 00da3bce6d78bf845cf598f1645fc7504ebe64ca Mon Sep 17 00:00:00 2001 From: Fryslan Date: Wed, 20 Jul 2016 22:57:30 +0200 Subject: [PATCH 1/3] [METHODS] Added Gained and GainedPerHour calculation methods. --- .../rev317/min/api/methods/Calculations.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/rev317/min/api/methods/Calculations.java b/src/main/java/org/rev317/min/api/methods/Calculations.java index 86e616e..fe17d43 100644 --- a/src/main/java/org/rev317/min/api/methods/Calculations.java +++ b/src/main/java/org/rev317/min/api/methods/Calculations.java @@ -1,5 +1,6 @@ package org.rev317.min.api.methods; +import org.parabot.environment.api.utils.Timer; import org.rev317.min.api.wrappers.Tile; /** @@ -231,7 +232,40 @@ public class Calculations { * @return True if Coordinate data from first and second tiles match. */ public static boolean isSameTile(Tile first, Tile second) { - return first.getX() == second.getX() && first.getY() == second.getY() && first.getPlane() == second.getPlane(); + return distanceBetween(first, second) == 0 && first.getPlane() == second.getPlane(); + } + + /** + * Checks if player is at the destination tile. + * + * @param destination destination tile. + * @return true if players location equals destination tile. + */ + public static boolean atTile(Tile destination) { + return isSameTile(Players.getMyPlayer().getLocation(), destination); + } + + /** + * Get's the difference between start and current. + * + * @param start Starting value. + * @param current Current value. + * @return difference between start and current. + */ + public static int gained(int start, int current) { + return start - current; + } + + /** + * Get's the hourly difference between start and current. + * + * @param runtime Timer used for calculating hourly difference. + * @param start Starting value. + * @param current Current value. + * @return Hourly difference between start and current. + */ + public static int gainedPerHour(Timer runtime, int start, int current) { + return runtime.getPerHour(gained(start, current)); } } From 1d286bd5409b8cb23932160a9541fc9283a79b4b Mon Sep 17 00:00:00 2001 From: Fryslan Date: Wed, 20 Jul 2016 23:02:43 +0200 Subject: [PATCH 2/3] [METHODS] Added Gained and GainedPerHour calculation methods. --- src/main/java/org/rev317/min/api/methods/Calculations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/rev317/min/api/methods/Calculations.java b/src/main/java/org/rev317/min/api/methods/Calculations.java index fe17d43..9f5730c 100644 --- a/src/main/java/org/rev317/min/api/methods/Calculations.java +++ b/src/main/java/org/rev317/min/api/methods/Calculations.java @@ -268,4 +268,4 @@ public class Calculations { return runtime.getPerHour(gained(start, current)); } -} +} \ No newline at end of file From b457abc9f483cba28e28394a33e9d58f907bfbe4 Mon Sep 17 00:00:00 2001 From: Fryslan Date: Fri, 30 Sep 2016 22:25:20 +0200 Subject: [PATCH 3/3] [FIX] Added null check in Npcs.getNearest --- src/main/java/org/rev317/min/api/methods/Npcs.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/rev317/min/api/methods/Npcs.java b/src/main/java/org/rev317/min/api/methods/Npcs.java index b84ae79..13b69aa 100644 --- a/src/main/java/org/rev317/min/api/methods/Npcs.java +++ b/src/main/java/org/rev317/min/api/methods/Npcs.java @@ -119,9 +119,11 @@ public class Npcs { @Override public boolean accept(Npc npc) { - for (final int id : ids) { - if (id == npc.getDef().getId()) { - return true; + if (npc.getDef() != null){ + for (final int id : ids) { + if (id == npc.getDef().getId()) { + return true; + } } } return false;