aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorHiZe_ <superhize@hotmail.com>2023-07-24 15:06:27 +0200
committerGitHub <noreply@github.com>2023-07-24 15:06:27 +0200
commit48449acc17694d99c84db001ecb9215a901666a5 (patch)
tree2d2dd917e0852cc882ac4c3e493e85bd2d321161 /src/main
parent402e10596224a123dba780ab6ccaca36d80beb91 (diff)
downloadskyhanni-48449acc17694d99c84db001ecb9215a901666a5.tar.gz
skyhanni-48449acc17694d99c84db001ecb9215a901666a5.tar.bz2
skyhanni-48449acc17694d99c84db001ecb9215a901666a5.zip
Slayer boss warning (#320)
Co-authored-by: superhize <superhize@gmail.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/SlayerConfig.java23
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/SlayerProgressChangeEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/slayer/SlayerBossSpawnSoon.kt41
5 files changed, 70 insertions, 0 deletions
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
@@ -403,6 +403,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. " +
"Kill a mob with melee-hits to fix this hypixel bug. §cOnly works while doing slayers!"
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 = " \\(?(?<progress>[0-9.,k]+)\\/(?<total>[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