diff --git a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java index 12fd1b2c14..c2592382b7 100644 --- a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java +++ b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaPlugin.java @@ -29,7 +29,7 @@ @Slf4j public class SulphurNaguaPlugin extends Plugin { - public static final String version = "2.0.3"; + public static final String version = "2.0.4"; @Inject SulphurNaguaScript sulphurNaguaScript; diff --git a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java index be83b19046..f31b80050f 100644 --- a/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java +++ b/src/main/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaScript.java @@ -205,8 +205,11 @@ private int getEffectiveTargetPotions(SulphurNaguaConfig config) { private boolean isInCombatArea() { WorldArea combatArea = getNaguaCombatArea(); - WorldPoint playerLoc = Rs2Player.getWorldLocation(); - return combatArea != null && playerLoc != null && combatArea.contains(playerLoc); + return isInArea(combatArea, Rs2Player.getWorldLocation()); + } + + static boolean isInArea(WorldArea area, WorldPoint point) { + return area != null && point != null && area.contains(point); } private void determineState(SulphurNaguaConfig config) { @@ -486,7 +489,12 @@ private void handleGettingRunecraftingXp(SulphurNaguaConfig config) { return; } - if (Rs2Player.getWorldLocation().distanceTo(EYTALLALI_LOCATION) > 5) { + WorldPoint playerLoc = Rs2Player.getWorldLocation(); + if (playerLoc == null) { + return; + } + + if (playerLoc.distanceTo(EYTALLALI_LOCATION) > 5) { Rs2Walker.walkTo(EYTALLALI_LOCATION); sleep(400, 800); return; @@ -533,9 +541,14 @@ private void handleFighting(SulphurNaguaConfig config) { boolean needsNewTarget = !Rs2Player.isInCombat() || Rs2Player.getInteracting() == null; if (needsNewTarget) { + WorldPoint playerLoc = Rs2Player.getWorldLocation(); + if (playerLoc == null) { + return; + } + WorldArea combatArea = getNaguaCombatArea(); - if (combatArea != null && combatArea.contains(Rs2Player.getWorldLocation())) { + if (isInArea(combatArea, playerLoc)) { var attackingNagua = Microbot.getRs2NpcCache().query() .withName("Sulphur Nagua") diff --git a/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java b/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java new file mode 100644 index 0000000000..d3d1fa8e07 --- /dev/null +++ b/src/test/java/net/runelite/client/plugins/microbot/sulphurnaguafigther/SulphurNaguaCombatAreaTest.java @@ -0,0 +1,35 @@ +package net.runelite.client.plugins.microbot.sulphurnaguafigther; + +import net.runelite.api.coords.WorldArea; +import net.runelite.api.coords.WorldPoint; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SulphurNaguaCombatAreaTest { + + private final WorldArea area = new WorldArea(1350, 9570, 10, 10, 0); + + @Test + void missingPlayerLocationIsNotInArea() { + assertDoesNotThrow(() -> SulphurNaguaScript.isInArea(area, null)); + assertFalse(SulphurNaguaScript.isInArea(area, null)); + } + + @Test + void missingAreaIsNotInArea() { + assertFalse(SulphurNaguaScript.isInArea(null, new WorldPoint(1355, 9575, 0))); + } + + @Test + void pointInsideAreaIsInArea() { + assertTrue(SulphurNaguaScript.isInArea(area, new WorldPoint(1355, 9575, 0))); + } + + @Test + void pointOutsideAreaIsNotInArea() { + assertFalse(SulphurNaguaScript.isInArea(area, new WorldPoint(1400, 9575, 0))); + } +}