From 48449acc17694d99c84db001ecb9215a901666a5 Mon Sep 17 00:00:00 2001 From: HiZe_ Date: Mon, 24 Jul 2023 15:06:27 +0200 Subject: Slayer boss warning (#320) Co-authored-by: superhize Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 1 + .../skyhanni/config/features/SlayerConfig.java | 23 ++++++++++++ .../java/at/hannibal2/skyhanni/data/SlayerAPI.kt | 2 ++ .../skyhanni/events/SlayerProgressChangeEvent.kt | 3 ++ .../features/slayer/SlayerBossSpawnSoon.kt | 41 ++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/events/SlayerProgressChangeEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerBossSpawnSoon.kt (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 3985c00a1..7e30efd80 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -354,6 +354,7 @@ class SkyHanniMod { loadModule(LivingCaveDefenseBlocks()) loadModule(LivingCaveLivingMetalHelper()) loadModule(RiftMotesOrb()) + loadModule(SlayerBossSpawnSoon()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java index 4efa9feb4..d2b4cc61d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java @@ -402,6 +402,29 @@ public class SlayerConfig { } + @Expose + @ConfigOption(name = "Boss spawn warning", desc = "") + @Accordion + public SlayerBossWarning slayerBossWarning = new SlayerBossWarning(); + + public static class SlayerBossWarning { + + @Expose + @ConfigOption(name = "Enabled", desc = "Send a title when your boss is about to spawn.") + @ConfigEditorBoolean + public boolean enabled = false; + + @Expose + @ConfigOption(name = "Percent", desc = "The percent at which the title and sound should be sent.") + @ConfigEditorSlider(minStep = 1, minValue = 50, maxValue = 90) + public int percent = 80; + + @Expose + @ConfigOption(name = "Repeat", desc = "Resend the title and sound on every kill after reaching the configured percent value.") + @ConfigEditorBoolean + public boolean repeat = false; + } + @Expose @ConfigOption(name = "Broken Wither Impact", desc = "Warns when right-clicking with a Wither Impact weapon (e.g. Hyperion) no longer gains combat exp. " + diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt index 7e44bd5cf..aa41560eb 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.SlayerChangeEvent +import at.hannibal2.skyhanni.events.SlayerProgressChangeEvent import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi import at.hannibal2.skyhanni.features.slayer.SlayerType @@ -118,6 +119,7 @@ object SlayerAPI { val slayerProgress = ScoreboardData.sidebarLinesFormatted.nextAfter("Slayer Quest", 2) ?: "" if (latestSlayerProgress != slayerProgress) { + SlayerProgressChangeEvent(latestSlayerProgress, slayerProgress).postAndCatch() latestSlayerProgress = slayerProgress latestProgressChangeTime = System.currentTimeMillis() } diff --git a/src/main/java/at/hannibal2/skyhanni/events/SlayerProgressChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/SlayerProgressChangeEvent.kt new file mode 100644 index 000000000..909df1d6a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/SlayerProgressChangeEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class SlayerProgressChangeEvent(val oldProgress: String, val newProgress: String): LorenzEvent() \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerBossSpawnSoon.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerBossSpawnSoon.kt new file mode 100644 index 000000000..0ab6eb997 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerBossSpawnSoon.kt @@ -0,0 +1,41 @@ +package at.hannibal2.skyhanni.features.slayer + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.SlayerAPI +import at.hannibal2.skyhanni.data.TitleUtils +import at.hannibal2.skyhanni.events.SlayerProgressChangeEvent +import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class SlayerBossSpawnSoon { + + private val config get() = SkyHanniMod.feature.slayer.slayerBossWarning + private val pattern = " \\(?(?[0-9.,k]+)\\/(?[0-9.,k]+)\\)?.*".toPattern() + private var lastCompletion = 0f + private var warned = false + + @SubscribeEvent + fun onSlayerProgressChange(event: SlayerProgressChangeEvent) { + if (!isEnabled()) return + + val completion = pattern.matchMatcher(event.newProgress.removeColor()) { + group("progress").formatNumber().toFloat() / group("total").formatNumber().toFloat() + } ?: return + + if (completion > config.percent / 100.0) { + if (!warned || (config.repeat && completion != lastCompletion)) { + SoundUtils.playBeepSound() + TitleUtils.sendTitle("§cSlayer boss soon!", 2_000) + warned = true + } + } else { + warned = false + } + lastCompletion = completion + } + + fun isEnabled() = config.enabled && SlayerAPI.hasActiveSlayerQuest() +} \ No newline at end of file -- cgit