From dca0bb27493a725ba8bee64e69ff0be949d167d0 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Wed, 27 Dec 2023 19:17:12 +0100 Subject: [PATCH 01/11] Added Dragon Features --- .../java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 + .../config/features/combat/CombatConfig.java | 6 + .../config/features/combat/DragonConfig.java | 31 +++ .../features/combat/DragonFeatures.kt | 209 ++++++++++++++++++ 4 files changed, 248 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java create mode 100644 src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 50592b896fe6..d85f4d42be23 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -71,6 +71,7 @@ import at.hannibal2.skyhanni.features.chat.WatchdogHider import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatFilter import at.hannibal2.skyhanni.features.chat.playerchat.PlayerChatModifier import at.hannibal2.skyhanni.features.combat.BestiaryData +import at.hannibal2.skyhanni.features.combat.DragonFeatures import at.hannibal2.skyhanni.features.combat.HideDamageSplash import at.hannibal2.skyhanni.features.combat.damageindicator.DamageIndicatorManager import at.hannibal2.skyhanni.features.combat.endernodetracker.EnderNodeTracker @@ -567,6 +568,7 @@ class SkyHanniMod { loadModule(AnitaExtraFarmingFortune()) loadModule(ComposterDisplay()) loadModule(GardenComposterInventoryFeatures()) + loadModule(DragonFeatures()) loadModule(MinionCollectLogic()) loadModule(BetterSignEditing()) loadModule(PatcherSendCoordinates()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java index 94780f9dda15..95656f2f0ce9 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java @@ -39,6 +39,12 @@ public class CombatConfig { @Accordion public EnderNodeConfig enderNodeTracker = new EnderNodeConfig(); + @Expose + @ConfigOption(name = "Dragon Features", desc = "") + @Accordion + public DragonConfig dragon = new DragonConfig(); + + @Expose @ConfigOption(name = "Hide Damage Splash", desc = "Hide all damage splashes anywhere in SkyBlock.") @ConfigEditorBoolean diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java new file mode 100644 index 000000000000..ae2b51769343 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java @@ -0,0 +1,31 @@ +package at.hannibal2.skyhanni.config.features.combat; + +import at.hannibal2.skyhanni.config.FeatureToggle; +import at.hannibal2.skyhanni.config.core.config.Position; +import com.google.gson.annotations.Expose; +import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; +import io.github.moulberry.moulconfig.annotations.ConfigOption; + +public class DragonConfig { + + @Expose + @ConfigOption(name = "Superior Notification", desc = "Notifies you with an Title that an superior dragon spawned") + @ConfigEditorBoolean + @FeatureToggle + public boolean superiorNotify = true; + + @Expose + @ConfigOption(name = "Weight HUD", desc = "Shows your current dragon weight on the HUD and if hovered shows the breakdown") + @ConfigEditorBoolean + @FeatureToggle + public boolean display = false; + + @Expose + public Position displayPosition = new Position(120, 40, false, true); + + @Expose + @ConfigOption(name = "Weight Message", desc = "Shows your dragon weight in chat after the dragon died") + @ConfigEditorBoolean + @FeatureToggle + public boolean chat = true; +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt new file mode 100644 index 000000000000..a5bc4519426d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -0,0 +1,209 @@ +package at.hannibal2.skyhanni.features.combat + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.TitleManager +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.IslandChangeEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.ScoreboardChangeEvent +import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.formatDouble +import at.hannibal2.skyhanni.utils.LorenzUtils.formatPercentage +import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches +import at.hannibal2.skyhanni.utils.renderables.Renderable +import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class DragonFeatures { + + val config get() = SkyHanniMod.configManager.features.combat.dragon + + val dragonNames = listOf("Protector", "Old", "Wise", "Unstable", "Young", "Strong", "Superior") + + val dragonNamesAsRegex = dragonNames.joinToString("|") + val dragonNamesUpperCaseAsRegex = dragonNames.joinToString("|") { it.uppercase() } + + val repoGroup = RepoPattern.group("combat.dragon") + val chatGroup = repoGroup.group("chat") + val scoreBoardGroup = repoGroup.group("scoreboard") + val tabListGroup = repoGroup.group("tablist") + + val eyePlaced by chatGroup.pattern("eye.placed.you", "§5☬ §r§dYou placed a Summoning Eye! §r§7\\(§r§e\\d§r§7\\/§r§a8§r§7\\)|§5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7\\(§r§a8§r§7\\/§r§a8§r§7\\)") + val eyeRemoved by chatGroup.pattern("eye.removed.you", "§5You recovered a Summoning Eye!") + + val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") + val endStartLine by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") + val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d)\\)") + //§f §r§eYour Damage: §r§a93,362 §r§7(Position #6) + + // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") + val endPlace by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") + val dragonSpawn by chatGroup.pattern("spawn", "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!") + val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") + val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") + val fightInfo by tabListGroup.pattern("fight.info", "§b§lDragon Fight: §r§f\\(\\w+\\)") + val tabDamage by tabListGroup.pattern("fight.player", ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤") + + + var yourEyes = 0 + + var dragonSpawned = false + set(value) { + field = value + if (dragonSpawned) { + egg = false + } + } + + var endText = false + var endTopDamage = 0.0 + + var currentDamage = 0.0 + var currentTopDamage = 0.0 + var currentPlace: Int? = null + var egg = true + + + fun reset() { + endText = false + endTopDamage = 0.0 + dragonSpawned = false + currentTopDamage = 0.0 + currentDamage = 0.0 + currentPlace = null + yourEyes = 0 + } + + fun enable() = LorenzUtils.inSkyBlock && IslandType.THE_END.isInIsland() + + fun enableDisplay() = enable() && config.display + + fun weightMap(place: Int) = when (place) { + -1 -> 10 + 1 -> 300 + 2 -> 250 + 3 -> 200 + 4 -> 125 + 5 -> 110 + 6, 7, 8 -> 100 + 9, 10 -> 90 + 11, 12 -> 80 + else -> 70 + } + + fun calculateWeight(eyes: Int, place: Int, firstDamage: Double, yourDamage: Double) = + weightMap(if (yourDamage == 0.0) -1 else place) + 100 * (eyes + yourDamage / (firstDamage.takeIf { it != 0.0 } + ?: 1.0)) + + + @SubscribeEvent + fun onChat(event: LorenzChatEvent) { + if (!enable()) return + val message = event.message + if (!config.chat && !config.display && !config.superiorNotify) return + dragonSpawn.matchMatcher(message) { + dragonSpawned = true + if (config.superiorNotify && this.group("Dragon") == "Superior") { + TitleManager.sendTitle("§6Superior Dragon Spawned!", 1.5.seconds) + } + return + } + if (!config.chat && !config.display) return + when { + eyePlaced.matches(message) -> { + yourEyes++ + } + + eyeRemoved.matches(message) -> { + yourEyes-- + } + + eggSpawned.matches(message) -> { + egg = true + } + + endStartLine.matches(message) -> { + endText = true + } + + else -> { + endPlace.matchMatcher(message) { + if (!endText) return@matchMatcher + if (this.group("Position") != "1") return@matchMatcher + endTopDamage = this.group("Damage").replace(",", "").toDouble() + return + } + endPosition.matchMatcher(message) { + if (!endText) return@matchMatcher + val weight = calculateWeight( + yourEyes, this.group("Position")?.toInt() + ?: -1, endTopDamage, this.group("Damage").replace(",", "").toDouble() + ) + if (config.chat) { + LorenzUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") + } + reset() + return + } + } + } + + } + + @SubscribeEvent + fun onScoreBoard(event: ScoreboardChangeEvent) { + if (!(enableDisplay())) return + val index = event.newList.indexOfFirst { + scoreDamage.matchMatcher(it) { + currentDamage = this.group("Damage").replace(",", "").toDouble() + true + } ?: false + } + if (dragonSpawned || index == -1) return + if (egg && scoreDragon.matches(event.newList[index - 1])) { + dragonSpawned = true + } + } + + @SubscribeEvent + fun onTabList(event: TabListUpdateEvent) { + if (!(enableDisplay() && dragonSpawned)) return + val infoIndex = event.tabList.indexOfFirst { fightInfo.matches(it) } + if (infoIndex == -1) return + for (i in 1..3) { + tabDamage.matchMatcher(event.tabList[infoIndex + i]) { + if (i == 1) { + currentTopDamage = this.group("Damage").toDouble() * this.group("Unit").let { + when (it) { + "k" -> 1_000 + "M" -> 1_000_000 + else -> 1 + } + } + } + if (this.group("Name") == LorenzUtils.getPlayerName()) { + currentPlace = i + } + } + } + } + + + @SubscribeEvent + fun onRender(event: GuiRenderEvent) { + if (!(enableDisplay() && dragonSpawned)) return + config.displayPosition.renderRenderables(listOf(Renderable.hoverTips("§6Current Weight: §f${formatDouble(calculateWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage))}", listOf("Eyes: $yourEyes", "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), posLabel = "Dragon Weight") + } + + @SubscribeEvent + fun on(event: IslandChangeEvent) { + reset() + egg = true + } +} From 5e7b355a80d71b48de5524c64ea073ae2e185e3f Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Wed, 27 Dec 2023 21:42:54 +0100 Subject: [PATCH 02/11] Trying to break stuff --- .github/workflows/generate-constants.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/generate-constants.yaml b/.github/workflows/generate-constants.yaml index fccadc7fb579..3f33b6d8519f 100644 --- a/.github/workflows/generate-constants.yaml +++ b/.github/workflows/generate-constants.yaml @@ -38,7 +38,6 @@ jobs: needs: regexes name: "Publish regexes" # 511310721 is the Repository ID for SkyHanni - if: ${{ 'push' == github.event_name && 'beta' == github.ref_name && '511310721' == github.repository_id }} steps: - uses: actions/checkout@v3 with: From f8c738ee951f9afb72b804f60436387caa0dcdb9 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Wed, 27 Dec 2023 21:46:47 +0100 Subject: [PATCH 03/11] Didn't break stuff (good) --- .github/workflows/generate-constants.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/generate-constants.yaml b/.github/workflows/generate-constants.yaml index 3f33b6d8519f..fccadc7fb579 100644 --- a/.github/workflows/generate-constants.yaml +++ b/.github/workflows/generate-constants.yaml @@ -38,6 +38,7 @@ jobs: needs: regexes name: "Publish regexes" # 511310721 is the Repository ID for SkyHanni + if: ${{ 'push' == github.event_name && 'beta' == github.ref_name && '511310721' == github.repository_id }} steps: - uses: actions/checkout@v3 with: From ba3a2e7288c7efface56b9911a3392adf0d135c2 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 28 Dec 2023 10:17:00 +0100 Subject: [PATCH 04/11] Cleanup --- .../java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index a5bc4519426d..988db7cfbfcc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -40,7 +40,6 @@ class DragonFeatures { val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") val endStartLine by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d)\\)") - //§f §r§eYour Damage: §r§a93,362 §r§7(Position #6) // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") val endPlace by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") From cbbe39da9e63520c216d43a5efbd3de386f2ff67 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 28 Dec 2023 10:34:14 +0100 Subject: [PATCH 05/11] Bugfix --- .../at/hannibal2/skyhanni/features/combat/DragonFeatures.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index 988db7cfbfcc..f48e08e7c348 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -39,7 +39,7 @@ class DragonFeatures { val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") val endStartLine by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") - val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d)\\)") + val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)") // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") val endPlace by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") From 6ea9203cc0ac9bb2dbb697fd2e9b41129f09cd05 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 28 Dec 2023 11:07:25 +0100 Subject: [PATCH 06/11] Added Protector Weight --- .../config/features/combat/CombatConfig.java | 6 + .../features/combat/DragonFeatures.kt | 111 ++++++++++++++---- 2 files changed, 93 insertions(+), 24 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java index 95656f2f0ce9..2ad4e18b575d 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/combat/CombatConfig.java @@ -44,6 +44,12 @@ public class CombatConfig { @Accordion public DragonConfig dragon = new DragonConfig(); + @Expose + @ConfigOption(name = "Weight Endstone Protector", desc = "Shows your Endstone Protector weight in chat after the it died") + @ConfigEditorBoolean + @FeatureToggle + public boolean endstoneProtectorChat = true; + @Expose @ConfigOption(name = "Hide Damage Splash", desc = "Hide all damage splashes anywhere in SkyBlock.") diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index f48e08e7c348..92bdcffcf515 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -23,13 +23,14 @@ import kotlin.time.Duration.Companion.seconds class DragonFeatures { val config get() = SkyHanniMod.configManager.features.combat.dragon + val configProtector get() = SkyHanniMod.configManager.features.combat.endstoneProtectorChat val dragonNames = listOf("Protector", "Old", "Wise", "Unstable", "Young", "Strong", "Superior") val dragonNamesAsRegex = dragonNames.joinToString("|") val dragonNamesUpperCaseAsRegex = dragonNames.joinToString("|") { it.uppercase() } - val repoGroup = RepoPattern.group("combat.dragon") + val repoGroup = RepoPattern.group("combat.boss.dragon") val chatGroup = repoGroup.group("chat") val scoreBoardGroup = repoGroup.group("scoreboard") val tabListGroup = repoGroup.group("tablist") @@ -38,11 +39,13 @@ class DragonFeatures { val eyeRemoved by chatGroup.pattern("eye.removed.you", "§5You recovered a Summoning Eye!") val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") - val endStartLine by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") + val endStartLineDragon by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") + val endStartLineProtector by RepoPattern.pattern("combat.boss.protector.chat.end.boss", "§f +§r§6§l ENDSTONE PROTECTOR DOWN!") val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)") // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") - val endPlace by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") + val endLeaderboard by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") + val endZealots by RepoPattern.pattern("combat.boss.protector.chat.end.zealot", "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100") val dragonSpawn by chatGroup.pattern("spawn", "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!") val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") @@ -60,8 +63,14 @@ class DragonFeatures { } } - var endText = false + private enum class Type { + golem, dragon + } + + private var endType: Type? = null var endTopDamage = 0.0 + var endDamage = 0.0 + var endPlace = 0 var currentDamage = 0.0 var currentTopDamage = 0.0 @@ -69,9 +78,15 @@ class DragonFeatures { var egg = true - fun reset() { - endText = false + fun resetEnd() { + endType = null endTopDamage = 0.0 + endDamage = 0.0 + endPlace = 0 + } + + fun reset() { + resetEnd() dragonSpawned = false currentTopDamage = 0.0 currentDamage = 0.0 @@ -83,7 +98,7 @@ class DragonFeatures { fun enableDisplay() = enable() && config.display - fun weightMap(place: Int) = when (place) { + fun dragonWeightMap(place: Int) = when (place) { -1 -> 10 1 -> 300 2 -> 250 @@ -96,16 +111,33 @@ class DragonFeatures { else -> 70 } - fun calculateWeight(eyes: Int, place: Int, firstDamage: Double, yourDamage: Double) = - weightMap(if (yourDamage == 0.0) -1 else place) + 100 * (eyes + yourDamage / (firstDamage.takeIf { it != 0.0 } + fun protectorWeightMap(place: Int) = when (place) { + -1 -> 10 + 1 -> 200 + 2 -> 175 + 3 -> 150 + 4 -> 125 + 5 -> 110 + 6, 7, 8 -> 100 + 9, 10 -> 90 + 11, 12 -> 80 + else -> 70 + } + + fun calculateDragonWeight(eyes: Int, place: Int, firstDamage: Double, yourDamage: Double) = + dragonWeightMap(if (yourDamage == 0.0) -1 else place) + 100 * (eyes + yourDamage / (firstDamage.takeIf { it != 0.0 } ?: 1.0)) + fun calculateProtectorWeight(zealots: Int, place: Int, firstDamage: Double, yourDamage: Double) = + protectorWeightMap(if (yourDamage == 0.0) -1 else place) + 50 * (yourDamage / (firstDamage.takeIf { it != 0.0 } + ?: 1.0)) + if (zealots > 100) 100 else zealots + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!enable()) return val message = event.message - if (!config.chat && !config.display && !config.superiorNotify) return + if (!config.chat && !config.display && !config.superiorNotify && !configProtector) return dragonSpawn.matchMatcher(message) { dragonSpawned = true if (config.superiorNotify && this.group("Dragon") == "Superior") { @@ -113,7 +145,7 @@ class DragonFeatures { } return } - if (!config.chat && !config.display) return + if (!config.chat && !config.display && !configProtector) return when { eyePlaced.matches(message) -> { yourEyes++ @@ -127,34 +159,65 @@ class DragonFeatures { egg = true } - endStartLine.matches(message) -> { - endText = true + endStartLineDragon.matches(message) -> { + if (!config.chat) { + reset() + return + } + endType = Type.dragon + } + + endStartLineProtector.matches(message) -> { + if (!configProtector) return + endType = Type.golem } else -> { - endPlace.matchMatcher(message) { - if (!endText) return@matchMatcher + endLeaderboard.matchMatcher(message) { + if (endType == null) return@matchMatcher if (this.group("Position") != "1") return@matchMatcher endTopDamage = this.group("Damage").replace(",", "").toDouble() return } endPosition.matchMatcher(message) { - if (!endText) return@matchMatcher - val weight = calculateWeight( - yourEyes, this.group("Position")?.toInt() - ?: -1, endTopDamage, this.group("Damage").replace(",", "").toDouble() - ) - if (config.chat) { - LorenzUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") + if (endType == null) return@matchMatcher + endPlace = this.group("Position")?.toInt() ?: -1 + endDamage = this.group("Damage").replace(",", "").toDouble() + when (endType) { + Type.dragon -> { + val weight = calculateDragonWeight( + yourEyes, endPlace, endTopDamage, endDamage + ) + + printWeight(weight) + reset() + } + + Type.golem -> { + + // NO reset because of Zealot Line + } + + null -> return@matchMatcher } - reset() return } + endZealots.matchMatcher(message) { + if (endType != Type.golem) return@matchMatcher + val zealots = this.group("Amount").toInt() + val weight = calculateProtectorWeight(zealots, endPlace, endTopDamage, endDamage) + printWeight(weight) + resetEnd() + } } } } + private fun printWeight(weight: Double) { + LorenzUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") + } + @SubscribeEvent fun onScoreBoard(event: ScoreboardChangeEvent) { if (!(enableDisplay())) return @@ -197,7 +260,7 @@ class DragonFeatures { @SubscribeEvent fun onRender(event: GuiRenderEvent) { if (!(enableDisplay() && dragonSpawned)) return - config.displayPosition.renderRenderables(listOf(Renderable.hoverTips("§6Current Weight: §f${formatDouble(calculateWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage))}", listOf("Eyes: $yourEyes", "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), posLabel = "Dragon Weight") + config.displayPosition.renderRenderables(listOf(Renderable.hoverTips("§6Current Weight: §f${formatDouble(calculateDragonWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage))}", listOf("Eyes: $yourEyes", "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), posLabel = "Dragon Weight") } @SubscribeEvent From dd7cdbee02ff19dc044ffa287d1efeca94f5b0b8 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 28 Dec 2023 11:15:16 +0100 Subject: [PATCH 07/11] Fixed Bug --- .../skyhanni/features/combat/DragonFeatures.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index 92bdcffcf515..bc1a4ae85305 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -221,16 +221,15 @@ class DragonFeatures { @SubscribeEvent fun onScoreBoard(event: ScoreboardChangeEvent) { if (!(enableDisplay())) return - val index = event.newList.indexOfFirst { - scoreDamage.matchMatcher(it) { - currentDamage = this.group("Damage").replace(",", "").toDouble() - true - } ?: false - } - if (dragonSpawned || index == -1) return - if (egg && scoreDragon.matches(event.newList[index - 1])) { + val index = event.newList.indexOfFirst { scoreDragon.matches(it) } + if (index == -1) return + if (egg) { dragonSpawned = true } + scoreDamage.matchMatcher(event.newList[index + 1]) { + currentDamage = this.group("Damage").replace(",", "").toDouble() + } + } @SubscribeEvent From 1ea05561260b2a7a6f41335bbdcd31fb9e92cc98 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 28 Dec 2023 11:18:51 +0100 Subject: [PATCH 08/11] Cleanup of RepoPatterns --- .../hannibal2/skyhanni/features/combat/DragonFeatures.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index bc1a4ae85305..8f6f41eb7d25 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -30,6 +30,7 @@ class DragonFeatures { val dragonNamesAsRegex = dragonNames.joinToString("|") val dragonNamesUpperCaseAsRegex = dragonNames.joinToString("|") { it.uppercase() } + val protectorRepoGroup = RepoPattern.group("combat.boss.protector") val repoGroup = RepoPattern.group("combat.boss.dragon") val chatGroup = repoGroup.group("chat") val scoreBoardGroup = repoGroup.group("scoreboard") @@ -40,15 +41,17 @@ class DragonFeatures { val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") val endStartLineDragon by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") - val endStartLineProtector by RepoPattern.pattern("combat.boss.protector.chat.end.boss", "§f +§r§6§l ENDSTONE PROTECTOR DOWN!") + val endStartLineProtector by protectorRepoGroup.pattern("chat.end.boss", "§f +§r§6§l ENDSTONE PROTECTOR DOWN!") val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)") // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") val endLeaderboard by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") - val endZealots by RepoPattern.pattern("combat.boss.protector.chat.end.zealot", "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100") + val endZealots by protectorRepoGroup.pattern("chat.end.zealot", "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100") val dragonSpawn by chatGroup.pattern("spawn", "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!") val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") + + // val scoreProtector by protectorRepoGroup.pattern("scoreboard.protector", "Protector HP: .*") val fightInfo by tabListGroup.pattern("fight.info", "§b§lDragon Fight: §r§f\\(\\w+\\)") val tabDamage by tabListGroup.pattern("fight.player", ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤") From dad2fd4e5f81eaeb6cca3e5d675c051a69a77a39 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:51:43 +0100 Subject: [PATCH 09/11] updated code --- .../features/combat/DragonFeatures.kt | 149 +++++++++++------- 1 file changed, 91 insertions(+), 58 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index 8f6f41eb7d25..135dfc0ae275 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -2,16 +2,18 @@ package at.hannibal2.skyhanni.features.combat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.data.TitleManager import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.ScoreboardChangeEvent import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.formatDouble import at.hannibal2.skyhanni.utils.LorenzUtils.formatPercentage import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches @@ -22,43 +24,66 @@ import kotlin.time.Duration.Companion.seconds class DragonFeatures { - val config get() = SkyHanniMod.configManager.features.combat.dragon - val configProtector get() = SkyHanniMod.configManager.features.combat.endstoneProtectorChat - - val dragonNames = listOf("Protector", "Old", "Wise", "Unstable", "Young", "Strong", "Superior") - - val dragonNamesAsRegex = dragonNames.joinToString("|") - val dragonNamesUpperCaseAsRegex = dragonNames.joinToString("|") { it.uppercase() } - - val protectorRepoGroup = RepoPattern.group("combat.boss.protector") - val repoGroup = RepoPattern.group("combat.boss.dragon") - val chatGroup = repoGroup.group("chat") - val scoreBoardGroup = repoGroup.group("scoreboard") - val tabListGroup = repoGroup.group("tablist") - - val eyePlaced by chatGroup.pattern("eye.placed.you", "§5☬ §r§dYou placed a Summoning Eye! §r§7\\(§r§e\\d§r§7\\/§r§a8§r§7\\)|§5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7\\(§r§a8§r§7\\/§r§a8§r§7\\)") - val eyeRemoved by chatGroup.pattern("eye.removed.you", "§5You recovered a Summoning Eye!") - - val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") - val endStartLineDragon by chatGroup.pattern("end.boss", "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!") - val endStartLineProtector by protectorRepoGroup.pattern("chat.end.boss", "§f +§r§6§l ENDSTONE PROTECTOR DOWN!") - val endPosition by chatGroup.pattern("end.position", "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)") + private val config get() = SkyHanniMod.configManager.features.combat.dragon + private val configProtector get() = SkyHanniMod.configManager.features.combat.endstoneProtectorChat + + private val dragonNames = listOf("Protector", "Old", "Wise", "Unstable", "Young", "Strong", "Superior") + + private val dragonNamesAsRegex = dragonNames.joinToString("|") + private val dragonNamesUpperCaseAsRegex = dragonNames.joinToString("|") { it.uppercase() } + + private val protectorRepoGroup = RepoPattern.group("combat.boss.protector") + private val repoGroup = RepoPattern.group("combat.boss.dragon") + private val chatGroup = repoGroup.group("chat") + private val scoreBoardGroup = repoGroup.group("scoreboard") + private val tabListGroup = repoGroup.group("tablist") + + private val eyePlaced by chatGroup.pattern( + "eye.placed.you", + "§5☬ §r§dYou placed a Summoning Eye! §r§7\\(§r§e\\d§r§7\\/§r§a8§r§7\\)|§5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7\\(§r§a8§r§7\\/§r§a8§r§7\\)" + ) + private val eyeRemoved by chatGroup.pattern("eye.removed.you", "§5You recovered a Summoning Eye!") + + private val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") + private val endStartLineDragon by chatGroup.pattern( + "end.boss", + "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!" + ) + private val endStartLineProtector by protectorRepoGroup.pattern( + "chat.end.boss", + "§f +§r§6§l ENDSTONE PROTECTOR DOWN!" + ) + private val endPosition by chatGroup.pattern( + "end.position", + "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)" + ) // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") - val endLeaderboard by chatGroup.pattern("end.place", "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)") - val endZealots by protectorRepoGroup.pattern("chat.end.zealot", "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100") - val dragonSpawn by chatGroup.pattern("spawn", "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!") - val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") - val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") - - // val scoreProtector by protectorRepoGroup.pattern("scoreboard.protector", "Protector HP: .*") - val fightInfo by tabListGroup.pattern("fight.info", "§b§lDragon Fight: §r§f\\(\\w+\\)") - val tabDamage by tabListGroup.pattern("fight.player", ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤") - - - var yourEyes = 0 - - var dragonSpawned = false + private val endLeaderboard by chatGroup.pattern( + "end.place", + "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)" + ) + private val endZealots by protectorRepoGroup.pattern( + "chat.end.zealot", + "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100" + ) + private val dragonSpawn by chatGroup.pattern( + "spawn", + "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!" + ) + private val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") + private val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") + + // private val scoreProtector by protectorRepoGroup.pattern("scoreboard.protector", "Protector HP: .*") + private val fightInfo by tabListGroup.pattern("fight.info", "§b§lDragon Fight: §r§f\\(\\w+\\)") + private val tabDamage by tabListGroup.pattern( + "fight.player", + ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤" + ) + + private var yourEyes = 0 + + private var dragonSpawned = false set(value) { field = value if (dragonSpawned) { @@ -71,24 +96,23 @@ class DragonFeatures { } private var endType: Type? = null - var endTopDamage = 0.0 - var endDamage = 0.0 - var endPlace = 0 + private var endTopDamage = 0.0 + private var endDamage = 0.0 + private var endPlace = 0 - var currentDamage = 0.0 - var currentTopDamage = 0.0 - var currentPlace: Int? = null - var egg = true + private var currentDamage = 0.0 + private var currentTopDamage = 0.0 + private var currentPlace: Int? = null + private var egg = true - - fun resetEnd() { + private fun resetEnd() { endType = null endTopDamage = 0.0 endDamage = 0.0 endPlace = 0 } - fun reset() { + private fun reset() { resetEnd() dragonSpawned = false currentTopDamage = 0.0 @@ -97,11 +121,11 @@ class DragonFeatures { yourEyes = 0 } - fun enable() = LorenzUtils.inSkyBlock && IslandType.THE_END.isInIsland() + private fun enable() = LorenzUtils.inSkyBlock && IslandType.THE_END.isInIsland() - fun enableDisplay() = enable() && config.display + private fun enableDisplay() = enable() && config.display - fun dragonWeightMap(place: Int) = when (place) { + private fun dragonWeightMap(place: Int) = when (place) { -1 -> 10 1 -> 300 2 -> 250 @@ -114,7 +138,7 @@ class DragonFeatures { else -> 70 } - fun protectorWeightMap(place: Int) = when (place) { + private fun protectorWeightMap(place: Int) = when (place) { -1 -> 10 1 -> 200 2 -> 175 @@ -127,15 +151,14 @@ class DragonFeatures { else -> 70 } - fun calculateDragonWeight(eyes: Int, place: Int, firstDamage: Double, yourDamage: Double) = + private fun calculateDragonWeight(eyes: Int, place: Int, firstDamage: Double, yourDamage: Double) = dragonWeightMap(if (yourDamage == 0.0) -1 else place) + 100 * (eyes + yourDamage / (firstDamage.takeIf { it != 0.0 } ?: 1.0)) - fun calculateProtectorWeight(zealots: Int, place: Int, firstDamage: Double, yourDamage: Double) = + private fun calculateProtectorWeight(zealots: Int, place: Int, firstDamage: Double, yourDamage: Double) = protectorWeightMap(if (yourDamage == 0.0) -1 else place) + 50 * (yourDamage / (firstDamage.takeIf { it != 0.0 } ?: 1.0)) + if (zealots > 100) 100 else zealots - @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!enable()) return @@ -144,7 +167,7 @@ class DragonFeatures { dragonSpawn.matchMatcher(message) { dragonSpawned = true if (config.superiorNotify && this.group("Dragon") == "Superior") { - TitleManager.sendTitle("§6Superior Dragon Spawned!", 1.5.seconds) + LorenzUtils.sendTitle("§6Superior Dragon Spawned!", 1.5.seconds) } return } @@ -218,7 +241,7 @@ class DragonFeatures { } private fun printWeight(weight: Double) { - LorenzUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") + ChatUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") } @SubscribeEvent @@ -258,15 +281,25 @@ class DragonFeatures { } } - @SubscribeEvent fun onRender(event: GuiRenderEvent) { if (!(enableDisplay() && dragonSpawned)) return - config.displayPosition.renderRenderables(listOf(Renderable.hoverTips("§6Current Weight: §f${formatDouble(calculateDragonWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage))}", listOf("Eyes: $yourEyes", "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), posLabel = "Dragon Weight") + config.displayPosition.renderRenderables( + listOf( + Renderable.hoverTips( + "§6Current Weight: §f${ + calculateDragonWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage) + .round(1).addSeparators() + }", + listOf( + "Eyes: $yourEyes", + "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", + "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), + posLabel = "Dragon Weight") } @SubscribeEvent - fun on(event: IslandChangeEvent) { + fun onIslandChange(event: IslandChangeEvent) { reset() egg = true } From e451f198590baac880017adf69ef95c6594f3fbc Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:04:43 +0200 Subject: [PATCH 10/11] updated --- .../config/features/combat/DragonConfig.java | 6 +- .../skyhanni/data/model/TabWidget.kt | 2 +- .../features/combat/DragonFeatures.kt | 119 ++++++++++++------ 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java index ae2b51769343..6d85aef87dbe 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/combat/DragonConfig.java @@ -3,8 +3,9 @@ import at.hannibal2.skyhanni.config.FeatureToggle; import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; -import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; -import io.github.moulberry.moulconfig.annotations.ConfigOption; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; +import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; +import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class DragonConfig { @@ -21,6 +22,7 @@ public class DragonConfig { public boolean display = false; @Expose + @ConfigLink(owner = DragonConfig.class, field = "display") public Position displayPosition = new Position(120, 40, false, true); @Expose diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt b/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt index bf2b424d5e7f..9d922f93d60a 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/model/TabWidget.kt @@ -207,7 +207,7 @@ enum class TabWidget( ), DRAGON( // language=RegExp - "(?:§.)*Dragon: (?:§.)*\\((?[^)])\\)", + "(?:§.)*Dragon: (?:§.)*\\((?[^)]*)\\)", ), VOLCANO( // language=RegExp diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index 135dfc0ae275..ea6d245e1caf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -2,30 +2,32 @@ package at.hannibal2.skyhanni.features.combat import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.data.model.TabWidget import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.ScoreboardChangeEvent -import at.hannibal2.skyhanni.events.TabListUpdateEvent +import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent +import at.hannibal2.skyhanni.events.WidgetUpdateEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzUtils.formatDouble import at.hannibal2.skyhanni.utils.LorenzUtils.formatPercentage import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.LorenzUtils.round import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher +import at.hannibal2.skyhanni.utils.RegexUtils.matches import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.seconds -class DragonFeatures { +@SkyHanniModule +object DragonFeatures { - private val config get() = SkyHanniMod.configManager.features.combat.dragon - private val configProtector get() = SkyHanniMod.configManager.features.combat.endstoneProtectorChat + private val config get() = SkyHanniMod.feature.combat.dragon + private val configProtector get() = SkyHanniMod.feature.combat.endstoneProtectorChat private val dragonNames = listOf("Protector", "Old", "Wise", "Unstable", "Young", "Strong", "Superior") @@ -38,47 +40,73 @@ class DragonFeatures { private val scoreBoardGroup = repoGroup.group("scoreboard") private val tabListGroup = repoGroup.group("tablist") + /** REGEX-TEST: §5☬ §r§dYou placed a Summoning Eye! §r§7(§r§e2§r§7/§r§a8§r§7) + * REGEX-TEST: §5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7(§r§a8§r§7/§r§a8§r§7) + */ private val eyePlaced by chatGroup.pattern( "eye.placed.you", - "§5☬ §r§dYou placed a Summoning Eye! §r§7\\(§r§e\\d§r§7\\/§r§a8§r§7\\)|§5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7\\(§r§a8§r§7\\/§r§a8§r§7\\)" + "§5☬ §r§dYou placed a Summoning Eye! §r§7\\(§r§e\\d§r§7\\/§r§a8§r§7\\)|§5☬ §r§dYou placed a Summoning Eye! Brace yourselves! §r§7\\(§r§a8§r§7\\/§r§a8§r§7\\)", ) + + /** REGEX-TEST: §5You recovered a Summoning Eye! + */ private val eyeRemoved by chatGroup.pattern("eye.removed.you", "§5You recovered a Summoning Eye!") + /** REGEX-TEST: §5☬ §r§dThe Dragon Egg has spawned! + */ private val eggSpawned by chatGroup.pattern("egg.spawn", "§5☬ §r§dThe Dragon Egg has spawned!") + + /** REGEX-TEST: §f §r§6§lPROTECTOR DRAGON DOWN! + */ private val endStartLineDragon by chatGroup.pattern( "end.boss", - "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!" + "§f +§r§6§l(?${dragonNamesUpperCaseAsRegex}) DRAGON DOWN!", ) + + /** REGEX-TEST: §f §r§6§lENDSTONE PROTECTOR DOWN! + */ private val endStartLineProtector by protectorRepoGroup.pattern( "chat.end.boss", - "§f +§r§6§l ENDSTONE PROTECTOR DOWN!" + "§f +§r§6§l ENDSTONE PROTECTOR DOWN!", ) + + /** REGEX-TEST: §f §r§eYour Damage: §r§a88,966 §r§7(Position #5) + */ private val endPosition by chatGroup.pattern( "end.position", - "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)" + "§f +§r§eYour Damage: §r§a(?[\\d.,]+) (?:§r§d§l\\(NEW RECORD!\\) )?§r§7\\(Position #(?\\d+)\\)", ) // val endFinalHit by chatGroup.pattern("end.final", "§f §r§b[^ ]+ (?.*)§r§f §r§7dealt the final blow.") + /** REGEX-TEST: §f §r§e§l1st Damager §r§7- §r§a[VIP] Jarre07§r§f §r§7- §r§e9,659,033 + * REGEX-TEST: §f §r§6§l2nd Damager §r§7- §r§b[MVP§r§9+§r§b] FlamingZoom§r§f §r§7- §r§e1,459,691 + * REGEX-TEST: §f §r§c§l3rd Damager §r§7- §r§b[MVP§r§f+§r§b] Dustbringer§r§f §r§7- §r§e1,091,163 + */ private val endLeaderboard by chatGroup.pattern( "end.place", - "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)" + "§f +§r§.§l(?\\d+).. Damager §r§7- §r§.(?:\\[[^ ]+\\] )?(?.*)§r§. §r§7- §r§e(?[\\d.,]+)", ) + + /** REGEX-TEST: §f §r§eZealots Contributed: §r§a27§r§e/100 + */ private val endZealots by protectorRepoGroup.pattern( "chat.end.zealot", - "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100" + "§f +§r§eZealots Contributed: §r§a(?\\d+)§r§e/100", ) + + /** REGEX-TEST: §5☬ §r§d§lThe §r§5§c§lProtector Dragon§r§d§l has spawned! + */ private val dragonSpawn by chatGroup.pattern( "spawn", - "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!" + "§5☬ §r§d§lThe §r§5§c§l(?${dragonNamesAsRegex}) Dragon§r§d§l has spawned!", ) private val scoreDamage by scoreBoardGroup.pattern("damage", "Your Damage: §c(?[\\w,.]+)") private val scoreDragon by scoreBoardGroup.pattern("dragon", "Dragon HP: .*") // private val scoreProtector by protectorRepoGroup.pattern("scoreboard.protector", "Protector HP: .*") - private val fightInfo by tabListGroup.pattern("fight.info", "§b§lDragon Fight: §r§f\\(\\w+\\)") private val tabDamage by tabListGroup.pattern( "fight.player", - ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤" + ".*§r§f(?.+): §r§c(?[\\d.]+)(?[kM])?❤", ) private var yourEyes = 0 @@ -92,7 +120,8 @@ class DragonFeatures { } private enum class Type { - golem, dragon + golem, + dragon } private var endType: Type? = null @@ -103,6 +132,7 @@ class DragonFeatures { private var currentDamage = 0.0 private var currentTopDamage = 0.0 private var currentPlace: Int? = null + private var widgetActive = false private var egg = true private fun resetEnd() { @@ -118,6 +148,7 @@ class DragonFeatures { currentTopDamage = 0.0 currentDamage = 0.0 currentPlace = null + widgetActive = false yourEyes = 0 } @@ -212,11 +243,11 @@ class DragonFeatures { when (endType) { Type.dragon -> { val weight = calculateDragonWeight( - yourEyes, endPlace, endTopDamage, endDamage + yourEyes, endPlace, endTopDamage, endDamage, ) printWeight(weight) - reset() + DragonFeatures.reset() // love name collisions } Type.golem -> { @@ -241,30 +272,30 @@ class DragonFeatures { } private fun printWeight(weight: Double) { - ChatUtils.chat("§f §r§eYour Weight: §r§a${formatDouble(weight)}") + ChatUtils.chat("§f §r§eYour Weight: §r§a${weight.round(0).addSeparators()}") } @SubscribeEvent - fun onScoreBoard(event: ScoreboardChangeEvent) { + fun onScoreBoard(event: ScoreboardUpdateEvent) { if (!(enableDisplay())) return - val index = event.newList.indexOfFirst { scoreDragon.matches(it) } + val index = event.scoreboard.indexOfFirst { scoreDragon.matches(it) } if (index == -1) return if (egg) { dragonSpawned = true } - scoreDamage.matchMatcher(event.newList[index + 1]) { + scoreDamage.matchMatcher(event.scoreboard[index + 1]) { currentDamage = this.group("Damage").replace(",", "").toDouble() } } @SubscribeEvent - fun onTabList(event: TabListUpdateEvent) { + fun onTabList(event: WidgetUpdateEvent) { + if (!event.isWidget(TabWidget.DRAGON)) return if (!(enableDisplay() && dragonSpawned)) return - val infoIndex = event.tabList.indexOfFirst { fightInfo.matches(it) } - if (infoIndex == -1) return - for (i in 1..3) { - tabDamage.matchMatcher(event.tabList[infoIndex + i]) { + widgetActive = true + for (i in 1 until event.lines.size) { + tabDamage.matchMatcher(event.lines[i]) { if (i == 1) { currentTopDamage = this.group("Damage").toDouble() * this.group("Unit").let { when (it) { @@ -281,23 +312,31 @@ class DragonFeatures { } } + private val widgetErrorGUI = listOf(Renderable.string("§cDragon Widget is disabled!")) + @SubscribeEvent fun onRender(event: GuiRenderEvent) { if (!(enableDisplay() && dragonSpawned)) return config.displayPosition.renderRenderables( - listOf( - Renderable.hoverTips( - "§6Current Weight: §f${ - calculateDragonWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage) - .round(1).addSeparators() - }", - listOf( - "Eyes: $yourEyes", - "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", - "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%"))), - posLabel = "Dragon Weight") + if (!widgetActive) widgetErrorGUI else display(), + posLabel = "Dragon Weight", + ) } + private fun display() = listOf( + Renderable.hoverTips( + "§6Current Weight: §f${ + calculateDragonWeight(yourEyes, currentPlace ?: 6, currentTopDamage, currentDamage) + .round(1).addSeparators() + }", + listOf( + "Eyes: $yourEyes", + "Place: ${currentPlace ?: if (currentDamage != 0.0) "unknown, assuming 6th" else "not damaged yet"}", + "Damage Ratio: ${formatPercentage(currentDamage / (currentTopDamage.takeIf { it != 0.0 } ?: 1.0))}%", + ), + ), + ) + @SubscribeEvent fun onIslandChange(event: IslandChangeEvent) { reset() From ce40d96ae56b861f44df4441435d98171271e6de Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Wed, 3 Jul 2024 12:07:59 +0200 Subject: [PATCH 11/11] ktlint --- .../skyhanni/features/combat/DragonFeatures.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt index ea6d245e1caf..83d766783687 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/combat/DragonFeatures.kt @@ -120,8 +120,8 @@ object DragonFeatures { } private enum class Type { - golem, - dragon + GOLEM, + DRAGON } private var endType: Type? = null @@ -221,12 +221,12 @@ object DragonFeatures { reset() return } - endType = Type.dragon + endType = Type.DRAGON } endStartLineProtector.matches(message) -> { if (!configProtector) return - endType = Type.golem + endType = Type.GOLEM } else -> { @@ -241,7 +241,7 @@ object DragonFeatures { endPlace = this.group("Position")?.toInt() ?: -1 endDamage = this.group("Damage").replace(",", "").toDouble() when (endType) { - Type.dragon -> { + Type.DRAGON -> { val weight = calculateDragonWeight( yourEyes, endPlace, endTopDamage, endDamage, ) @@ -250,7 +250,7 @@ object DragonFeatures { DragonFeatures.reset() // love name collisions } - Type.golem -> { + Type.GOLEM -> { // NO reset because of Zealot Line } @@ -260,7 +260,7 @@ object DragonFeatures { return } endZealots.matchMatcher(message) { - if (endType != Type.golem) return@matchMatcher + if (endType != Type.GOLEM) return@matchMatcher val zealots = this.group("Amount").toInt() val weight = calculateProtectorWeight(zealots, endPlace, endTopDamage, endDamage) printWeight(weight)