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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test {
}

group = 'randomeventhelper'
version = '2.6.1'
version = '2.6.2'

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public void onNpcDespawned(NpcDespawned npcDespawned)
@Subscribe
public void onVarbitChanged(VarbitChanged varbitChanged)
{
// For some reason, when the player is within the maze random event, the varbits for the drill demon event fire/are modified
if (this.isInMazeLocalInstance())
{
return;
}

switch (varbitChanged.getVarbitId())
{
case VarbitID.MACRO_DRILLDEMON_POST_1:
Expand Down Expand Up @@ -206,4 +212,9 @@ private boolean isInDrillDemonLocalInstance()
{
return RandomEventHelperPlugin.getRegionIDFromCurrentLocalPointInstanced(client) == 12619;
}

private boolean isInMazeLocalInstance()
{
return RandomEventHelperPlugin.getRegionIDFromCurrentLocalPointInstanced(client) == 11591;
}
}
63 changes: 57 additions & 6 deletions src/main/java/randomeventhelper/randomevents/maze/MazeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.Tile;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.GameObjectDespawned;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameTick;
import net.runelite.api.gameval.ObjectID;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.PluginMessage;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginManager;
import randomeventhelper.RandomEventHelperPlugin;

@Slf4j
@Singleton
Expand All @@ -41,7 +45,8 @@ public class MazeHelper
private static final String PLUGIN_MESSAGE_SHORTEST_PATH_PATH_KEY = "path";
private static final String PLUGIN_MESSAGE_SHORTEST_PATH_CLEAR_KEY = "clear";

private boolean isInsideMaze;
private boolean isFirstRun;
private GameObject mazeExitObject; // Only purpose this serves is to avoid unnecessary onGameTick

public void startUp()
{
Expand Down Expand Up @@ -72,7 +77,8 @@ public void startUp()
return;
}
this.eventBus.register(this);
this.isInsideMaze = false;
this.isFirstRun = true;
this.mazeExitObject = null;
}

public void shutDown()
Expand All @@ -83,13 +89,14 @@ public void shutDown()
{
if (!pluginManager.isPluginEnabled(shortestPathPlugin.get()))
{
if (this.isInsideMaze)
if (this.isFirstRun)
{
this.sendShortestPathClear();
}
}
}
this.isInsideMaze = false;
this.isFirstRun = true;
this.mazeExitObject = null;
}

@Subscribe
Expand All @@ -102,7 +109,8 @@ public void onGameObjectSpawned(GameObjectSpawned gameObjectSpawned)
LocalPoint shrineLocalPoint = gameObjectSpawned.getGameObject().getLocalLocation();
WorldPoint instancedShrineWorldPoint = WorldPoint.fromLocalInstance(this.client, shrineLocalPoint);
log.debug("Detected maze exit object spawn, setting shortest path to it");
this.isInsideMaze = true;
this.isFirstRun = false;
this.mazeExitObject = gameObjectSpawned.getGameObject();
this.sendShortestPathDestination(instancedShrineWorldPoint);
}
}
Expand All @@ -114,11 +122,49 @@ public void onGameObjectDespawned(GameObjectDespawned gameObjectDespawned)
if (gameObjectDespawned.getGameObject().getId() == ObjectID.MACRO_MAZE_COMPLETE)
{
log.debug("Detected maze exit object despawn, clearing shortest path");
this.isInsideMaze = true;
this.isFirstRun = false;
this.mazeExitObject = null;
this.sendShortestPathClear();
}
}

@Subscribe
public void onGameTick(GameTick gameTick)
{
if (this.isFirstRun && this.isInMazeLocalInstance() && this.mazeExitObject == null)
{
log.debug("Cold start detected in maze instance, searching for maze exit object");
this.isFirstRun = false;

Tile[][][] sceneTiles = this.client.getTopLevelWorldView().getScene().getTiles(); // [Plane][x][y]
Tile[][] tilesInZ = sceneTiles[this.client.getTopLevelWorldView().getPlane()]; // Tiles at [z]
for (Tile[] tilesInZX : tilesInZ) // Tiles at [z][x]
{
for (Tile tile : tilesInZX) // Tiles at [z][x][y]
{
if (tile != null && tile.getGameObjects() != null)
{
for (GameObject gameObject : tile.getGameObjects())
{
// There seemed to be some case where the game object was null
if (gameObject == null)
{
continue;
}
GameObjectSpawned gameObjectSpawnedEvent = new GameObjectSpawned();
gameObjectSpawnedEvent.setGameObject(gameObject);
this.onGameObjectSpawned(gameObjectSpawnedEvent);
if (this.mazeExitObject != null)
{
return;
}
}
}
}
}
}
}

private boolean sendShortestPathDestination(WorldPoint destinationWorldPoint)
{
if (destinationWorldPoint == null)
Expand Down Expand Up @@ -162,4 +208,9 @@ private void sendShortestPathClear()
{
this.eventBus.post(new PluginMessage(PLUGIN_MESSAGE_SHORTEST_PATH_NAMESPACE, PLUGIN_MESSAGE_SHORTEST_PATH_CLEAR_KEY));
}

private boolean isInMazeLocalInstance()
{
return RandomEventHelperPlugin.getRegionIDFromCurrentLocalPointInstanced(client) == 11591;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.Text;
import randomeventhelper.RandomEventHelperPlugin;

@Slf4j
@Singleton
Expand Down Expand Up @@ -69,6 +70,12 @@ public void shutDown()
@Subscribe
public void onVarbitChanged(VarbitChanged varbitChanged)
{
// For some reason, when the player is within the maze random event, the varbits for the pirate chest event fire/are modified
if (this.isInMazeLocalInstance())
{
return;
}

switch (varbitChanged.getVarbitId())
{
case VarbitID.PIRATE_COMBILOCK_LEFT:
Expand Down Expand Up @@ -204,4 +211,9 @@ private void populateWidgetsMap()
this.widgetMap.put(ChestLockSlot.RIGHT.getSubtractWidgetID(), rightSubtractWidget);
}
}

private boolean isInMazeLocalInstance()
{
return RandomEventHelperPlugin.getRegionIDFromCurrentLocalPointInstanced(client) == 11591;
}
}