From 3ef47d879a43b26620b082dbaaff321ec291e907 Mon Sep 17 00:00:00 2001 From: Oxyopiia <101736939+Oxyopiia@users.noreply.github.com> Date: Mon, 12 Aug 2024 16:38:44 +0100 Subject: [PATCH] Add Elderpork (#69) --- .../vice/config/features/BossStorage.kt | 3 ++ src/main/java/net/oxyopia/vice/data/World.kt | 1 + .../java/net/oxyopia/vice/events/ChatEvent.kt | 6 ++- .../vice/features/bosses/BossCounter.kt | 3 ++ .../oxyopia/vice/features/bosses/Elderpork.kt | 45 +++++++++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/oxyopia/vice/features/bosses/Elderpork.kt diff --git a/src/main/java/net/oxyopia/vice/config/features/BossStorage.kt b/src/main/java/net/oxyopia/vice/config/features/BossStorage.kt index 4c6eb8d5..2041262c 100644 --- a/src/main/java/net/oxyopia/vice/config/features/BossStorage.kt +++ b/src/main/java/net/oxyopia/vice/config/features/BossStorage.kt @@ -20,6 +20,9 @@ class BossStorage { @Expose val minehut = Boss() + @Expose + val elderpork = Boss() + @Expose val shadowGelato = Boss() diff --git a/src/main/java/net/oxyopia/vice/data/World.kt b/src/main/java/net/oxyopia/vice/data/World.kt index d63a8b44..225d1cd7 100644 --- a/src/main/java/net/oxyopia/vice/data/World.kt +++ b/src/main/java/net/oxyopia/vice/data/World.kt @@ -30,6 +30,7 @@ enum class World(val id: String, val displayName: String, val type: WorldType = AbyssalVice("darkvice", "Abyssal Vice", type = WorldType.BOSS), ShadowGelato("shadowgelato", "Shadow Gelato", type = WorldType.BOSS), Diox("dioxarena", "Diox", type = WorldType.BOSS), + Elderpork("elderpork", "Elderpork", type = WorldType.BOSS), Floor2Arena("f2arenas", "Void Voyage", type = WorldType.ARENA, displayColor = Colors.ChatColor.Green), Floor3Arena("f3arenas", "Cryonic Caverns", type = WorldType.ARENA, displayColor = Colors.ChatColor.Blue), diff --git a/src/main/java/net/oxyopia/vice/events/ChatEvent.kt b/src/main/java/net/oxyopia/vice/events/ChatEvent.kt index 62272e92..75637924 100644 --- a/src/main/java/net/oxyopia/vice/events/ChatEvent.kt +++ b/src/main/java/net/oxyopia/vice/events/ChatEvent.kt @@ -6,7 +6,11 @@ class ChatEvent(content: Text) : ViceEvent.Cancelable() { val string: String = content.string val sender: String by lazy { - string.substringBefore(":").substringAfterLast(" ") + string.substringBefore(":", "@Vice-NO_SENDER@").substringAfterLast(" ") + } + + val hasNoSender by lazy { + sender == "@Vice-NO_SENDER@" } override fun cancel() { diff --git a/src/main/java/net/oxyopia/vice/features/bosses/BossCounter.kt b/src/main/java/net/oxyopia/vice/features/bosses/BossCounter.kt index 63be6d10..309d2270 100644 --- a/src/main/java/net/oxyopia/vice/features/bosses/BossCounter.kt +++ b/src/main/java/net/oxyopia/vice/features/bosses/BossCounter.kt @@ -38,6 +38,7 @@ object BossCounter: HudElement("Boss Counter", Vice.storage.bosses.bossCounterPo list.addBossStat("El Gelato", Colors.ChatColor.Green, bosses.gelato.completions) list.addBossStat("PPP", Colors.ChatColor.Red, bosses.ppp.completions) list.addBossStat("Minehut", Colors.ChatColor.Aqua, bosses.minehut.completions) + list.addBossStat("Elderpork", Colors.Elderpork, bosses.elderpork.completions) list.addBossStat("Shadow Gelato", Colors.ShadowGelato, bosses.shadowGelato.completions) list.addBossStat("Abyssal Vice", Colors.Diox, bosses.abyssalVice.completions) @@ -51,6 +52,7 @@ object BossCounter: HudElement("Boss Counter", Vice.storage.bosses.bossCounterPo @SubscribeEvent fun onChatMessage(event: ChatEvent) { val content = event.string + if (!event.hasNoSender) return when { World.Vice.isInWorld() && content.contains(viceTimeRegex) -> bosses.vice.completions-- @@ -59,6 +61,7 @@ object BossCounter: HudElement("Boss Counter", Vice.storage.bosses.bossCounterPo World.Minehut.isInWorld() && content.contains(minehutTimeRegex) -> bosses.minehut.completions-- World.ShadowGelato.isInWorld() && content.contains(shadowTimeRegex) -> bosses.shadowGelato.completions-- World.AbyssalVice.isInWorld() && content.contains(abyssalCompletionRegex) -> bosses.abyssalVice.completions++ + World.Elderpork.isInWorld() && content.contains("TAPE FINISHED.") -> bosses.elderpork.completions++ else -> return } diff --git a/src/main/java/net/oxyopia/vice/features/bosses/Elderpork.kt b/src/main/java/net/oxyopia/vice/features/bosses/Elderpork.kt new file mode 100644 index 00000000..465d0f14 --- /dev/null +++ b/src/main/java/net/oxyopia/vice/features/bosses/Elderpork.kt @@ -0,0 +1,45 @@ +package net.oxyopia.vice.features.bosses + +import net.minecraft.entity.boss.BossBar +import net.oxyopia.vice.data.Colors +import net.oxyopia.vice.data.World +import net.oxyopia.vice.events.BossBarEvents +import net.oxyopia.vice.events.ChatEvent +import net.oxyopia.vice.events.core.SubscribeEvent +import net.oxyopia.vice.utils.HudUtils.toText +import net.oxyopia.vice.utils.TimeUtils.formatTimer +import net.oxyopia.vice.utils.TimeUtils.timeDelta +import net.oxyopia.vice.utils.TimeUtils.timeDeltaWithin +import kotlin.time.Duration.Companion.seconds + +object Elderpork : Boss( + World.Elderpork, + Regex("Elderpork the Great - (?:(\\d+)/\\d+|YOU/SHOULD/KILL/YOURSELF) ❤ \\[PHASE (\\d+)]"), + phaseTimesSec = listOf(60 * 2, 60 * 10, 60 * 5, 60 * 2) +){ + private val MONITOR_MAX_TIME = 30.seconds + + private var monitorLastStart = -0L + + @SubscribeEvent + fun onChatMessage(event: ChatEvent) { + if (event.string.endsWith("is preparing to fight Elderpork the Great!") && event.hasNoSender) { + monitorLastStart = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onBossbarAfter(event: BossBarEvents.Insert) { + if (monitorLastStart.timeDeltaWithin(MONITOR_MAX_TIME)) { + val elapsedTime = monitorLastStart.timeDelta() + val percentageComplete = elapsedTime / MONITOR_MAX_TIME + + event.add( + "Delivery Start ${elapsedTime.formatTimer(MONITOR_MAX_TIME)}".toText(Colors.Elderpork), + 1f - percentageComplete.toFloat(), + BossBar.Color.PINK, + BossBar.Style.NOTCHED_10 + ) + } + } +} \ No newline at end of file