Skip to content

Commit

Permalink
fix: account for instanced regions for safe check (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Apr 25, 2023
1 parent 3c6039c commit 67c1391
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- Bugfix: Ignore deaths and player kills in instanced regions that are safe. (#221)
- Dev: Improve test suite reliability for uploading screenshots. (#219)

## 1.4.0
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dinkplugin/notifiers/DeathNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private static boolean isDangerous(Client client) {
return true; // normally dangerous

// inferno and fight cave are technically safe, but we want death notification regardless
int regionId = client.getLocalPlayer().getWorldLocation().getRegionID();
int regionId = WorldUtils.getLocation(client).getRegionID();
return WorldUtils.isInferno(regionId) || WorldUtils.isTzHaarFightCave(regionId);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dinkplugin/notifiers/PlayerKillNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void handleKill(Player target, int myLastDamage) {
target.getCombatLevel(),
equipment,
sendLocation ? client.getWorld() : null,
sendLocation ? target.getWorldLocation() : null,
sendLocation ? WorldUtils.getLocation(client, target) : null,
client.getBoostedSkillLevel(Skill.HITPOINTS),
myLastDamage
);
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/dinkplugin/util/WorldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.google.common.collect.ImmutableSet;
import lombok.experimental.UtilityClass;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.vars.AccountType;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
Expand Down Expand Up @@ -31,6 +33,17 @@ public class WorldUtils {
private final int TZHAAR_CAVE = 9551;
public final @VisibleForTesting int TZHAAR_PIT = 9552;

public static WorldPoint getLocation(Client client) {
return getLocation(client, client.getLocalPlayer());
}

public static WorldPoint getLocation(Client client, Actor actor) {
if (client.isInInstancedRegion())
return WorldPoint.fromLocalInstance(client, actor.getLocalLocation());

return actor.getWorldLocation();
}

public boolean isIgnoredWorld(Set<WorldType> worldType) {
return !Collections.disjoint(IGNORED_WORLDS, worldType);
}
Expand Down Expand Up @@ -69,7 +82,7 @@ public boolean isInferno(int regionId) {
}

public boolean isLastManStanding(Client client) {
if (LMS_REGIONS.contains(client.getLocalPlayer().getWorldLocation().getRegionID()))
if (LMS_REGIONS.contains(getLocation(client).getRegionID()))
return true;

Widget widget = client.getWidget(WidgetInfo.LMS_KDA);
Expand All @@ -90,7 +103,7 @@ public boolean isPlayerOwnedHouse(int regionId) {
}

public boolean isSafeArea(Client client) {
int regionId = client.getLocalPlayer().getWorldLocation().getRegionID();
int regionId = getLocation(client).getRegionID();

if (isBarbarianAssault(regionId) || isChambersOfXeric(regionId) || isInferno(regionId) ||
isNightmareZone(regionId) || isTzHaarFightCave(regionId) || isPestControl(client)) {
Expand Down

0 comments on commit 67c1391

Please sign in to comment.