Skip to content

Commit 7a7c0b7

Browse files
authored
Merge pull request #1707 from chsami/development
fix(player): handle null local player in cheerer creation
2 parents bbc103f + 0f1cec0 commit 7a7c0b7

29 files changed

Lines changed: 1106 additions & 249 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ project.build.group=net.runelite
3131
project.build.version=1.12.22
3232

3333
glslang.path=
34-
microbot.version=2.1.29
34+
microbot.version=2.1.30
3535
microbot.commit.sha=nogit
3636
microbot.repo.url=http://138.201.81.246:8081/repository/microbot-snapshot/
3737
microbot.repo.username=

runelite-client/build.gradle.kts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,32 @@ tasks.register<Test>("runTests") {
108108
}
109109
}
110110

111+
tasks.register<Test>("runIntegrationTest") {
112+
group = "verification"
113+
description = "Run Rs2ActorModel integration test with live client"
114+
enabled = true
115+
116+
testClassesDirs = sourceSets.test.get().output.classesDirs
117+
classpath = sourceSets.test.get().runtimeClasspath
118+
119+
jvmArgs(
120+
"-Dfile.encoding=UTF-8",
121+
"-Duser.timezone=Europe/Brussels",
122+
"-ea"
123+
)
124+
125+
include("**/Rs2ActorModelIntegrationTest.class")
126+
include("**/Rs2WalkerIntegrationTest.class")
127+
128+
useJUnit()
129+
130+
testLogging {
131+
events("passed", "skipped", "failed")
132+
showStandardStreams = true
133+
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
134+
}
135+
}
136+
111137
lombok.version = libs.versions.lombok.get()
112138

113139
java {
@@ -303,7 +329,9 @@ tasks.checkstyleMain {
303329
}
304330

305331
tasks.withType<Test> {
306-
enabled = false
332+
if (name != "runIntegrationTest" && name != "runTests" && name != "runDebugTests") {
333+
enabled = false
334+
}
307335
systemProperty("glslang.path", providers.gradleProperty("glslangPath").getOrElse(""))
308336
}
309337

runelite-client/src/main/java/net/runelite/client/plugins/microbot/api/actor/Rs2ActorModel.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ public int getHealthScale()
7171
@Override
7272
public WorldPoint getWorldLocation()
7373
{
74-
if (getWorldView() != null && getWorldView().getId() != -1) {
75-
return Microbot.getClientThread().invoke(this::projectActorLocationToMainWorld);
76-
}
77-
78-
return actor.getWorldLocation();
74+
return Microbot.getClientThread().invoke(() -> {
75+
WorldView worldView = actor.getWorldView();
76+
if (worldView != null && !worldView.isTopLevel()) {
77+
return projectActorLocationToMainWorld();
78+
}
79+
return actor.getWorldLocation();
80+
});
7981
}
8082

8183
@Override
@@ -450,17 +452,15 @@ public long getHash()
450452

451453
public WorldPoint projectActorLocationToMainWorld() {
452454
WorldPoint actorLocation = actor.getWorldLocation();
453-
LocalPoint localPoint = LocalPoint.fromWorld(
454-
getWorldView(),
455-
actorLocation
456-
);
455+
WorldView wv = actor.getWorldView();
456+
LocalPoint localPoint = LocalPoint.fromWorld(wv, actorLocation);
457457

458458
if (localPoint == null)
459459
{
460460
return actorLocation;
461461
}
462462

463-
var mainWorldProjection = getWorldView().getMainWorldProjection();
463+
var mainWorldProjection = wv.getMainWorldProjection();
464464

465465
if (mainWorldProjection == null)
466466
{

runelite-client/src/main/java/net/runelite/client/plugins/microbot/example/ExampleScript.java

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import net.runelite.client.plugins.microbot.api.player.Rs2PlayerCache;
1919
import net.runelite.client.plugins.microbot.util.player.Rs2PlayerModel;
2020
import net.runelite.client.plugins.microbot.util.reachable.Rs2Reachable;
21+
import net.runelite.client.plugins.microbot.util.walker.Rs2Walker;
2122

2223
import javax.inject.Inject;
2324
import java.util.ArrayList;
@@ -56,59 +57,26 @@ public boolean run() {
5657
try {
5758
if (!Microbot.isLoggedIn()) return;
5859

59-
/*
60-
if (Microbot.getClient().getTopLevelWorldView().getScene().isInstance()) {
61-
LocalPoint l = LocalPoint.fromWorld(Microbot.getClient().getTopLevelWorldView(), Microbot.getClient().getLocalPlayer().getWorldLocation());
62-
System.out.println("was here");
63-
WorldPoint.fromLocalInstance(Microbot.getClient(), l);
64-
} else {
65-
System.out.println("was here lol");
66-
// this needs to ran on client threaad if we are on the sea
67-
var a = Microbot.getClient().getLocalPlayer().getWorldLocation();
68-
System.out.println(a);
69-
}*/
70-
71-
var shipwreck = rs2TileObjectCache.query()
72-
.where(x -> x.getName() != null && x.getName().toLowerCase().contains("shipwreck"))
73-
.within(5)
74-
.nearestOnClientThread();
75-
var player = new Rs2PlayerModel();
76-
77-
var isInvFull = Rs2Inventory.count() >= Rs2Random.between(24, 28);
78-
if (isInvFull && Rs2Inventory.count("salvage") > 0 && player.getAnimation() == -1) {
79-
// Rs2Inventory.dropAll("large salvage");
80-
rs2TileObjectCache.query()
81-
.fromWorldView()
82-
.where(x -> x.getName() != null && x.getName().equalsIgnoreCase("salvaging station"))
83-
.where(x -> x.getWorldView().getId() == new Rs2PlayerModel().getWorldView().getId())
84-
.nearestOnClientThread()
85-
.click();
86-
sleepUntil(() -> Rs2Inventory.count("salvage") == 0, 60000);
87-
} else if (isInvFull) {
88-
dropJunk();
89-
} else {
90-
if (player.getAnimation() != -1) {
91-
log.info("Currently salvaging, waiting...");
92-
sleep(5000, 10000);
93-
return;
94-
}
60+
if (Rs2Inventory.isFull()) {
61+
Rs2Inventory.dropAll("Logs");
62+
return;
63+
}
9564

96-
if (shipwreck == null) {
97-
log.info("No shipwreck found nearby");
98-
sleep(5000);
99-
dropJunk();
100-
return;
101-
}
65+
if (Rs2Player.isAnimating()) return;
10266

103-
rs2TileObjectCache.query().fromWorldView().where(x -> x.getName() != null && x.getName().toLowerCase().contains("salvaging hook")).nearestOnClientThread().click("Deploy");
104-
sleepUntil(() -> player.getAnimation() != -1, 5000);
67+
var tree = Microbot.getRs2TileObjectCache().query()
68+
.withName("Tree")
69+
.nearest();
10570

71+
if (tree != null) {
72+
tree.click("Chop down");
73+
sleepUntil(Rs2Player::isAnimating, 3000);
10674
}
10775

10876
} catch (Exception ex) {
109-
log.error("Error in performance test loop", ex);
77+
log.error("Error in example script", ex);
11078
}
111-
}, 0, 1000, TimeUnit.MILLISECONDS);
79+
}, 0, 600, TimeUnit.MILLISECONDS);
11280

11381
return true;
11482
}

runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/QuestScript.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private boolean attemptToAcquireRequirementItem(DetailedQuestStep questStep, Ite
319319

320320
if (worldPoint != null) {
321321
if ((Rs2Walker.canReach(worldPoint) && worldPoint.distanceTo(Rs2Player.getWorldLocation()) < 2)
322-
|| worldPoint.toWorldArea().hasLineOfSightTo(Microbot.getClient().getTopLevelWorldView(), Microbot.getClient().getLocalPlayer().getWorldLocation().toWorldArea())
322+
|| worldPoint.toWorldArea().hasLineOfSightTo(Microbot.getClient().getTopLevelWorldView(), Rs2Player.getWorldLocation().toWorldArea())
323323
&& Rs2Camera.isTileOnScreen(LocalPoint.fromWorld(Microbot.getClient().getTopLevelWorldView(), worldPoint))) {
324324
lootGroundItem(targetItemId, 10);
325325
} else {
@@ -464,7 +464,7 @@ public boolean applyNpcStep(NpcStep step) {
464464
} else if (npc != null && (!npc.hasLineOfSight() || !Rs2Walker.canReach(npc.getWorldLocation()))) {
465465
Rs2Walker.walkTo(npc.getWorldLocation(), 2);
466466
} else {
467-
if (step.getDefinedPoint().getWorldPoint().distanceTo(Microbot.getClient().getLocalPlayer().getWorldLocation()) > 3) {
467+
if (step.getDefinedPoint().getWorldPoint().distanceTo(Rs2Player.getWorldLocation()) > 3) {
468468
Rs2Walker.walkTo(step.getDefinedPoint().getWorldPoint(), 2);
469469
return false;
470470
}
@@ -517,7 +517,7 @@ public boolean applyObjectStep(ObjectStep step) {
517517
return false;
518518
}
519519

520-
if (step.getDefinedPoint().getWorldPoint() != null && Microbot.getClient().getLocalPlayer().getWorldLocation().distanceTo2D(step.getDefinedPoint().getWorldPoint()) > 1
520+
if (step.getDefinedPoint().getWorldPoint() != null && Rs2Player.getWorldLocation().distanceTo2D(step.getDefinedPoint().getWorldPoint()) > 1
521521
&& (object == null || !Rs2Walker.canReach(object.getWorldLocation()))) {
522522
WorldPoint targetTile = null;
523523
WorldPoint stepLocation = object == null ? step.getDefinedPoint().getWorldPoint() : object.getWorldLocation();
@@ -641,7 +641,7 @@ private boolean hasLineOfSightToObject(Rs2TileObjectModel object) {
641641
}
642642

643643
WorldArea objectArea = object.getWorldLocation().toWorldArea();
644-
WorldArea playerArea = Microbot.getClient().getLocalPlayer().getWorldLocation().toWorldArea();
644+
WorldArea playerArea = Rs2Player.getWorldLocation().toWorldArea();
645645

646646
return Microbot.getClient().getTopLevelWorldView() != null
647647
&& playerArea.hasLineOfSightTo(Microbot.getClient().getTopLevelWorldView(), objectArea);

runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/runeliteobjects/Cheerer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class Cheerer
4545
public static void createCheerers(RuneliteObjectManager runeliteObjectManager, Client client, ConfigManager configManager)
4646
{
4747
cheerers.clear();
48+
if (client.getLocalPlayer() == null)
49+
{
50+
return;
51+
}
4852
createWOM(runeliteObjectManager, client);
4953
createZoinkwiz(runeliteObjectManager, client);
5054
}

runelite-client/src/main/java/net/runelite/client/plugins/microbot/questhelper/runeliteobjects/extendedruneliteobjects/RuneliteObjectManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,10 @@ public void onClientTick(ClientTick event)
822822
{
823823
redClickAnimationFrame++;
824824
}
825+
if (client.getLocalPlayer() == null)
826+
{
827+
return;
828+
}
825829
WorldPoint playerPosition = WorldPoint.fromLocalInstance(client, client.getLocalPlayer().getLocalLocation());
826830
runeliteObjectGroups.forEach((groupID, extendedRuneliteObjectGroup) -> {
827831
for (ExtendedRuneliteObject extendedRuneliteObject : extendedRuneliteObjectGroup.extendedRuneliteObjects)

runelite-client/src/main/java/net/runelite/client/plugins/microbot/shortestpath/pathfinder/CollisionMap.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ private static int packedPointFromOrdinal(int startPacked, OrdinalDirection dire
9999
new WorldPoint(3672, 3862, 0)
100100
);
101101

102+
private volatile int cachedRegionId = -1;
103+
private volatile long cachedRegionIdTime = 0;
104+
private static final long REGION_CACHE_MS = 5000;
105+
private static final int TOA_PUZZLE_REGION = 14162;
106+
107+
private int getCachedRegionId() {
108+
long now = System.currentTimeMillis();
109+
if (now - cachedRegionIdTime > REGION_CACHE_MS) {
110+
try {
111+
WorldPoint loc = Rs2Player.getWorldLocation();
112+
cachedRegionId = loc != null ? loc.getRegionID() : -1;
113+
} catch (Exception e) {
114+
cachedRegionId = -1;
115+
}
116+
cachedRegionIdTime = now;
117+
}
118+
return cachedRegionId;
119+
}
120+
102121
public List<Node> getNeighbors(Node node, VisitedTiles visited, PathfinderConfig config, Set<Integer> targets) {
103122
final int x = WorldPointUtil.unpackWorldX(node.packedPosition);
104123
final int y = WorldPointUtil.unpackWorldY(node.packedPosition);
@@ -167,7 +186,7 @@ public List<Node> getNeighbors(Node node, VisitedTiles visited, PathfinderConfig
167186
* This piece of code is designed to allow web walker to be used in toa puzzle room
168187
* it will dodge specific tiles in the sequence room
169188
*/
170-
if (Rs2Player.getWorldLocation().getRegionID() == 14162) { //toa puzzle room
189+
if (getCachedRegionId() == TOA_PUZZLE_REGION) {
171190
if (!targets.contains(neighborPacked)) {
172191
WorldPoint globalWorldPoint = Rs2WorldPoint.convertInstancedWorldPoint(WorldPointUtil.unpackWorldPoint(neighborPacked));
173192
if (globalWorldPoint != null) {

0 commit comments

Comments
 (0)