Skip to content

Commit

Permalink
Merge branch 'master' into feature/loot-npc-id-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
iProdigy authored Sep 28, 2024
2 parents 58f407d + 6af9bd1 commit 31c759f
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
## Unreleased

- Minor: Include NPC ID in loot notification metadata. (#550)
- Minor: Allow customization of rich embed highlight color. (#534)
- Minor: Include Moxi pet name in pet notifications. (#557)
- Bugfix: Treat elite diary resurrections as safe deaths. (#555)

## 1.10.10

- Dev: Update death notifier for new skull icon API. (#552)

## 1.10.9

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dependencies {
}

group = "dinkplugin"
version = "1.10.9"
version = "1.10.10"

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/dinkplugin/DinkPluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dinkplugin.domain.LeagueTaskDifficulty;
import dinkplugin.domain.PlayerLookupService;
import dinkplugin.notifiers.ChatNotifier;
import dinkplugin.util.Utils;
import net.runelite.api.Experience;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
Expand All @@ -17,6 +18,7 @@
import net.runelite.client.config.Range;
import net.runelite.client.config.Units;

import java.awt.Color;
import java.util.EnumSet;
import java.util.Set;

Expand Down Expand Up @@ -439,6 +441,17 @@ default boolean includeClientFrame() {
return false;
}

@ConfigItem(
keyName = "embedColor",
name = "Embed Color",
description = "The highlight color for rich embeds.",
position = 1019,
section = advancedSection
)
default Color embedColor() {
return Utils.PINK;
}

@ConfigItem(
keyName = "discordWebhook", // do not rename; would break old configs
name = "Primary Webhook URLs",
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dinkplugin/domain/ExceptionalDeath.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@RequiredArgsConstructor
public enum ExceptionalDeath {
COX("Chambers of Xeric"),
DIARY_RESURRECTION("Diary Resurrection"),
FIGHT_CAVE("Fight Caves"),
INFERNO("Inferno"),
JAD_CHALLENGES("Jad challenges"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private static List<Embed> computeEmbeds(@NotNull NotificationBody<?> body, bool
embeds.add(0,
Embed.builder()
.author(author)
.color(Utils.PINK)
.color(config.embedColor())
.title(body.isSeasonalWorld() ? "[Seasonal] " + type.getTitle() : type.getTitle())
.description(Utils.truncate(body.getText().evaluate(config.discordRichEmbeds()), Embed.MAX_DESCRIPTION_LENGTH))
.image(screenshot ? new Embed.UrlEmbed("attachment://" + type.getScreenshot()) : null)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dinkplugin/notifiers/CollectionNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class CollectionNotifier extends BaseNotifier {
*/
public static final @Varp int COMPLETED_VARP = 2943, TOTAL_VARP = 2944;

static final @VisibleForTesting int TOTAL_ENTRIES = 1_535; // fallback if TOTAL_VARP is not populated
static final @VisibleForTesting int TOTAL_ENTRIES = 1_560; // fallback if TOTAL_VARP is not populated

private static final Duration RECENT_DROP = Duration.ofSeconds(30L);

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/dinkplugin/notifiers/DeathNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import dinkplugin.util.Region;
import dinkplugin.util.Utils;
import dinkplugin.util.WorldUtils;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Actor;
import net.runelite.api.Item;
Expand All @@ -25,10 +24,12 @@
import net.runelite.api.ParamID;
import net.runelite.api.Player;
import net.runelite.api.Prayer;
import net.runelite.api.SkullIcon;
import net.runelite.api.Varbits;
import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.InteractingChanged;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.NPCManager;
import org.apache.commons.lang3.ArrayUtils;
Expand Down Expand Up @@ -103,6 +104,9 @@ public class DeathNotifier extends BaseNotifier {
@Inject
private NPCManager npcManager;

@Inject
private ClientThread clientThread;

/**
* Tracks the last {@link Actor} our local player interacted with,
* for the purposes of attributing deaths to particular {@link Player}'s.
Expand All @@ -126,16 +130,16 @@ protected String getWebhookUrl() {
}

public void init() {
setIgnoredRegions(config.deathIgnoredRegions());
clientThread.invoke(() -> setIgnoredRegions(config.deathIgnoredRegions()));
}

public void reset() {
setIgnoredRegions(null);
clientThread.invoke(() -> setIgnoredRegions(null));
}

public void onConfigChanged(String key, String value) {
if ("deathIgnoredRegions".equals(key)) {
setIgnoredRegions(value);
clientThread.invoke(() -> setIgnoredRegions(value));
}
}

Expand Down Expand Up @@ -298,7 +302,6 @@ private boolean shouldNotifyExceptionalDangerousDeath(ExceptionalDeath death) {
return isEnabled();
}

@Synchronized
private void setIgnoredRegions(@Nullable String configValue) {
ignoredRegions.clear();
ConfigUtil.readDelimited(configValue).forEach(str -> {
Expand All @@ -319,11 +322,8 @@ private int getKeepCount() {
if (Utils.getAccountType(client) == AccountType.ULTIMATE_IRONMAN)
return 0;

int keepCount;
if (client.getLocalPlayer().getSkullIcon() == null)
keepCount = 3;
else
keepCount = 0;
var skull = client.getLocalPlayer().getSkullIcon();
int keepCount = skull == SkullIcon.NONE ? 3 : 0;
if (client.isPrayerActive(Prayer.PROTECT_ITEM))
keepCount++;
return keepCount;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dinkplugin/notifiers/PetNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ public double[] getRates(Client client) {
entry("Lil' zik", new KcSource(" Theatre of Blood", 1.0 / 650)), // assume normal mode
entry("Lil'viathan", new KcSource("The Leviathan", 1.0 / 2_500)),
entry("Little nightmare", new KcSource("Nightmare", 1.0 / 3_200)), // assume team size 4
entry("Moxi", new KcSource("Amoxliatl", null)), // unknown drop rate
entry("Muphin", new KcSource("Phantom Muspah", 1.0 / 2_500)),
entry("Nexling", new KcSource("Nex", 1.0 / 500)),
entry("Nid", new KcSource("Araxxor", 1.0 / 3000)),
Expand Down
26 changes: 25 additions & 1 deletion src/main/java/dinkplugin/util/WorldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.experimental.UtilityClass;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.api.WorldType;
import net.runelite.api.annotations.Varbit;
import net.runelite.api.annotations.Varp;
Expand Down Expand Up @@ -35,13 +36,17 @@ public class WorldUtils {
private final Set<Integer> SOUL_REGIONS = ImmutableSet.of(8493, 8748, 8749, 9005);
private final Set<Integer> TOA_REGIONS = ImmutableSet.of(14160, 14162, 14164, 14674, 14676, 15184, 15186, 15188, 15696, 15698, 15700);
private final Set<Integer> TOB_REGIONS = ImmutableSet.of(12611, 12612, 12613, 12867, 12869, 13122, 13123, 13125, 13379);
private final Set<Integer> ZULRAH_REGIONS = Set.of(9007, 9008);
private final int INFERNO_REGION = 9043;
private final int CREATURE_GRAVEYARD_REGION = 13462;
private final int NMZ_REGION = 9033;
private final int TZHAAR_CAVE = 9551;
public final @VisibleForTesting int TZHAAR_PIT = 9552;
public final int FORTIS_REGION = 7216;

private final @Varbit int KARAMJA_RESURRECTION_USED = 4557;
private final @Varbit int WESTERN_RESURRECTION_USED = 4565;

/**
* @see <a href="https://oldschool.runescape.wiki/w/RuneScape:Varbit/6104">Wiki</a>
*/
Expand Down Expand Up @@ -166,6 +171,10 @@ public boolean isTzHaarFightPit(int regionId) {
return regionId == TZHAAR_PIT;
}

public boolean isZulrah(int regionId) {
return ZULRAH_REGIONS.contains(regionId);
}

public Danger getDangerLevel(Client client, int regionId, Set<ExceptionalDeath> exceptions) {
if (isGauntlet(regionId)) {
// Players can't take items in or out of (Corrupted) Gauntlet, so these deaths are effectively safe
Expand Down Expand Up @@ -200,7 +209,22 @@ public Danger getDangerLevel(Client client, int regionId, Set<ExceptionalDeath>
}

if (isTzHaarFightCave(regionId)) {
return checkException(Utils.getAccountType(client) == AccountType.HARDCORE_GROUP_IRONMAN, exceptions, ExceptionalDeath.FIGHT_CAVE);
if (Utils.getAccountType(client) == AccountType.HARDCORE_GROUP_IRONMAN) {
return Danger.DANGEROUS;
}
if (exceptions.contains(ExceptionalDeath.FIGHT_CAVE)) {
return Danger.EXCEPTIONAL;
}
if (client.getVarbitValue(KARAMJA_RESURRECTION_USED) == 0 && exceptions.contains(ExceptionalDeath.DIARY_RESURRECTION) && client.getVarbitValue(Varbits.DIARY_KARAMJA_ELITE) > 0) {
// Karamja Elite diary completion allows 1 free daily resurrection: https://github.com/pajlads/DinkPlugin/issues/548
return Danger.EXCEPTIONAL;
}
return Danger.SAFE;
}

if (isZulrah(regionId) && client.getVarbitValue(WESTERN_RESURRECTION_USED) == 0 && client.getVarbitValue(Varbits.DIARY_WESTERN_ELITE) > 0) {
// Western Provinces Elite diary completion allows 1 free daily resurrection: https://github.com/pajlads/DinkPlugin/issues/548
return exceptions.contains(ExceptionalDeath.DIARY_RESURRECTION) ? Danger.EXCEPTIONAL : Danger.SAFE;
}

if (isBarbarianAssault(regionId) || isNightmareZone(regionId) || isMageTrainingArena(regionId)
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/dinkplugin/notifiers/DeathNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.runelite.api.ParamID;
import net.runelite.api.Player;
import net.runelite.api.Prayer;
import net.runelite.api.SkullIcon;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
Expand Down Expand Up @@ -80,6 +81,7 @@ protected void setUp() {
WorldPoint location = new WorldPoint(0, 0, 0);
when(localPlayer.getWorldLocation()).thenReturn(location);
when(localPlayer.getLocalLocation()).thenReturn(new LocalPoint(0, 0));
when(localPlayer.getSkullIcon()).thenReturn(SkullIcon.NONE);

// init item mocks
mockItem(ItemID.RUBY, RUBY_PRICE, "Ruby");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/dinkplugin/notifiers/MockedNotifierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import dinkplugin.util.BlockingClientThread;
import dinkplugin.util.BlockingExecutor;
import dinkplugin.util.TestImageUtil;
import dinkplugin.util.Utils;
import lombok.SneakyThrows;
import net.runelite.api.Client;
import net.runelite.api.GameState;
Expand Down Expand Up @@ -141,6 +142,7 @@ protected void setUp() {
when(config.playerLookupService()).thenReturn(PlayerLookupService.OSRS_HISCORE);
when(config.threadNameTemplate()).thenReturn("[%TYPE%] %MESSAGE%");
when(config.nameFilterMode()).thenReturn(FilterMode.DENY);
when(config.embedColor()).thenReturn(Utils.PINK);
}

protected void mockItem(int id, int price, String name) {
Expand Down

0 comments on commit 31c759f

Please sign in to comment.