Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
)
@Slf4j
public class GotrPlugin extends Plugin {
public static final String version = "1.5.10";
public static final String version = "1.5.11";

@Inject
private GotrConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public boolean run(GotrConfig config) {
try {
if (!Microbot.isLoggedIn()) return;
if (!super.run()) return;
if (!isPlayerLocationKnown()) return;
long startTime = System.currentTimeMillis();

if (!initCheck) {
Expand Down Expand Up @@ -662,20 +663,26 @@ public void shutdown() {

public static boolean isOutsideBarrier() {
int outsideBarrierY = 9482;
return Rs2Player.getWorldLocation().getY() <= outsideBarrierY
&& Rs2Player.getWorldLocation().getRegionID() == 14484;
WorldPoint location = Rs2Player.getWorldLocation();
return location != null
&& location.getY() <= outsideBarrierY
&& location.getRegionID() == 14484;
}

public static boolean isInLargeMine() {
int largeMineX = 3637;
return Rs2Player.getWorldLocation().getRegionID() == 14484
&& Microbot.getClientThread().invoke(() -> Microbot.getClient().getLocalPlayer().getWorldLocation().getX()) >= largeMineX;
WorldPoint location = Rs2Player.getWorldLocation();
return location != null
&& location.getRegionID() == 14484
&& location.getX() >= largeMineX;
}

public boolean isInHugeMine() {
int hugeMineX = 3594;
return Rs2Player.getWorldLocation().getRegionID() == 14484
&& Microbot.getClientThread().invoke(() -> Microbot.getClient().getLocalPlayer().getWorldLocation().getX()) <= hugeMineX;
WorldPoint location = Rs2Player.getWorldLocation();
return location != null
&& location.getRegionID() == 14484
&& location.getX() <= hugeMineX;
}

static boolean isActiveAltarRenderable(Renderable renderable) {
Expand All @@ -700,8 +707,13 @@ public boolean isInMiniGame() {
return elementalRuneWidget != null;
}

static boolean isPlayerLocationKnown() {
return Rs2Player.getWorldLocation() != null;
}

public static boolean isInMainRegion() {
return Rs2Player.getWorldLocation().getRegionID() == 14484;
WorldPoint location = Rs2Player.getWorldLocation();
return location != null && location.getRegionID() == 14484;
}

public static int getStartTimer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package net.runelite.client.plugins.microbot.gotr;

import net.runelite.api.coords.WorldPoint;
import net.runelite.client.plugins.microbot.util.player.Rs2Player;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mockStatic;

class GotrRegionCheckTest
{
private final GotrScript script = new GotrScript();

@Test
void unknownLocationIsInNoArea()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(null);

assertFalse(script.isInHugeMine());
assertFalse(GotrScript.isInLargeMine());
assertFalse(GotrScript.isOutsideBarrier());
assertFalse(GotrScript.isInMainRegion());
assertFalse(GotrScript.isPlayerLocationKnown());
}
}

@Test
void knownLocationLetsLoopDecide()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(new WorldPoint(3222, 3218, 0));

assertTrue(GotrScript.isPlayerLocationKnown());
}
}

@Test
void hugeMineIsDetected()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(new WorldPoint(3590, 9500, 0));

assertTrue(script.isInHugeMine());
assertFalse(GotrScript.isInLargeMine());
assertTrue(GotrScript.isInMainRegion());
}
}

@Test
void largeMineIsDetected()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(new WorldPoint(3640, 9500, 0));

assertTrue(GotrScript.isInLargeMine());
assertFalse(script.isInHugeMine());
}
}

@Test
void outsideBarrierIsDetected()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(new WorldPoint(3615, 9480, 0));

assertTrue(GotrScript.isOutsideBarrier());
assertTrue(GotrScript.isInMainRegion());
}
}

@Test
void otherRegionIsInNoArea()
{
try (MockedStatic<Rs2Player> player = mockStatic(Rs2Player.class))
{
player.when(Rs2Player::getWorldLocation).thenReturn(new WorldPoint(3222, 3218, 0));

assertFalse(script.isInHugeMine());
assertFalse(GotrScript.isInLargeMine());
assertFalse(GotrScript.isOutsideBarrier());
assertFalse(GotrScript.isInMainRegion());
}
}
}
Loading