aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/lorenz/mod/dungeon
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-12 00:36:02 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-12 00:36:02 +0200
commit08a857ae8d599fcc9206420cc14c164289ce1297 (patch)
treec58fc76144f149b788e36805fc24de8f435f6d91 /src/main/java/at/lorenz/mod/dungeon
parentf620d3490173ae815b46ee79398e5cbc36114c2b (diff)
downloadskyhanni-08a857ae8d599fcc9206420cc14c164289ce1297.tar.gz
skyhanni-08a857ae8d599fcc9206420cc14c164289ce1297.tar.bz2
skyhanni-08a857ae8d599fcc9206420cc14c164289ce1297.zip
add dungeon milestone display
Diffstat (limited to 'src/main/java/at/lorenz/mod/dungeon')
-rw-r--r--src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt2
-rw-r--r--src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt97
2 files changed, 97 insertions, 2 deletions
diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt
index 9452e5f60..bdf0addb4 100644
--- a/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt
+++ b/src/main/java/at/lorenz/mod/dungeon/DungeonChatFilter.kt
@@ -40,8 +40,6 @@ class DungeonChatFilter {
isPuzzle(message) -> "puzzle"
isBoss(message) -> "boss"
isEnd(message) -> "end"
- //TODO add
-// DungeonMilestoneDisplay.isMilestoneMessage(message) -> "milestone"
else -> ""
}
diff --git a/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt b/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt
new file mode 100644
index 000000000..cad3ff56f
--- /dev/null
+++ b/src/main/java/at/lorenz/mod/dungeon/DungeonMilestoneDisplay.kt
@@ -0,0 +1,97 @@
+package at.lorenz.mod.dungeon
+
+import at.lorenz.mod.LorenzMod
+import at.lorenz.mod.events.DungeonEnterEvent
+import at.lorenz.mod.events.LorenzChatEvent
+import at.lorenz.mod.misc.CurrentPetDisplay
+import at.lorenz.mod.utils.GuiRender.renderString
+import at.lorenz.mod.utils.LorenzUtils
+import at.lorenz.mod.utils.LorenzUtils.matchRegex
+import net.minecraftforge.client.event.RenderGameOverlayEvent
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.concurrent.fixedRateTimer
+
+class DungeonMilestoneDisplay {
+
+
+ companion object {
+ private var textToRender = ""
+ var color = ""
+ var currentMilestone = 0
+ var timeReached = 0L
+
+ fun isMilestoneMessage(message: String): Boolean = when {
+ message.matchRegex("§e§l(.*) Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)") -> true
+ message.matchRegex("§e§lArcher Milestone §r§e.§r§7: You have dealt §r§c(.*)§r§7 Ranged Damage so far! §r§a(.*)") -> true
+ message.matchRegex("§e§lHealer Milestone §r§e.§r§7: You have healed §r§a(.*)§r§7 Damage so far! §r§a(.*)") -> true
+ message.matchRegex("§e§lTank Milestone §r§e.§r§7: You have tanked and dealt §r§c(.*)§r§7 Total Damage so far! §r§a(.*)s") -> true
+
+ else -> false
+ }
+ }
+
+ init {
+ fixedRateTimer(name = "dungeon-milestone-display", period = 200) {
+ if (!isEnabled()) return@fixedRateTimer
+ checkVisibility()
+ }
+ }
+
+ private fun checkVisibility() {
+ if (currentMilestone >= 3) {
+ if (System.currentTimeMillis() > timeReached + 3_000)
+ if (textToRender != "") {
+ textToRender = textToRender.substring(1)
+ }
+ }
+ }
+
+ @SubscribeEvent(receiveCanceled = true)
+ fun onChatPacket(event: LorenzChatEvent) {
+ if (!isEnabled()) return
+
+ if (isMilestoneMessage(event.message)) {
+ event.blockedReason = "dungeon_milestone"
+ currentMilestone++
+ update()
+ }
+ }
+
+ private fun update() {
+ if (currentMilestone > 3) return
+ if (currentMilestone == 3) {
+ timeReached = System.currentTimeMillis()
+ }
+
+ color = when (currentMilestone) {
+ 0, 1 -> "§c"
+ 2 -> "§e"
+ else -> "§a"
+ }
+ textToRender = "Current Milestone: $currentMilestone"
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: WorldEvent.Load) {
+ textToRender = ""
+ currentMilestone = 0
+ }
+
+ @SubscribeEvent
+ fun onDungeonStart(event: DungeonEnterEvent) {
+ currentMilestone = 0
+ update()
+ }
+
+ @SubscribeEvent
+ fun renderOverlay(event: RenderGameOverlayEvent.Post) {
+ if (!isEnabled()) return
+
+ LorenzMod.feature.dungeon.milestoneDisplayPos.renderString(color + textToRender)
+ }
+
+ private fun isEnabled(): Boolean {
+ return LorenzUtils.inDungeons && LorenzMod.feature.dungeon.showMilestoneDisplay
+ }
+} \ No newline at end of file