From 80cfdbefef4c19fe952a2913b7a465efbddfcecf Mon Sep 17 00:00:00 2001 From: martimavocado <39881008+martimavocado@users.noreply.github.com> Date: Sat, 27 Apr 2024 12:19:32 +0100 Subject: Backend: Add blessings to DungeonAPI (#1326) Co-authored-by: Cal --- .../skyhanni/features/dungeon/DungeonAPI.kt | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt index 264f31bf2..c9e17ee04 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonAPI.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.TablistFooterUpdateEvent import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.CollectionUtils.equalsOneOf import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -22,6 +23,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.formatInt import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary import at.hannibal2.skyhanni.utils.StringUtils.matchFirst import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern @@ -62,6 +64,28 @@ object DungeonAPI { "room", "§7\\d+\\/\\d+\\/\\d+ §\\w+ (?[\\w,-]+)" ) + private val blessingPattern by patternGroup.pattern( + "blessings", + "§r§r§fBlessing of (?\\w+) (?\\w+)§r" + ) + private val noBlessingPattern by patternGroup.pattern( + "noblessings", + "§r§r§7No Buffs active. Find them by exploring the Dungeon!§r" + ) + + enum class DungeonBlessings(var power: Int) { + LIFE(0), + POWER(0), + STONE(0), + WISDOM(0), + TIME(0); + + companion object { + fun reset() { + entries.forEach { it.power = 0 } + } + } + } fun inDungeon() = IslandType.CATACOMBS.isInIsland() @@ -151,6 +175,26 @@ object DungeonAPI { } } + @SubscribeEvent + fun onTabUpdate(event: TablistFooterUpdateEvent) { + if (!inDungeon()) return + val tabList = event.footer.split("\n") + tabList.forEach { + if (noBlessingPattern.matches(it)) { + DungeonBlessings.reset() + return + } + val matcher = blessingPattern.matcher(it) + if (matcher.find()) { + val type = matcher.group("type") ?: return@forEach + val amount = matcher.group("amount").romanToDecimalIfNecessary() + if (DungeonBlessings.valueOf(type.uppercase()).power != amount) { + DungeonBlessings.valueOf(type.uppercase()).power = amount + } + } + } + } + @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { dungeonFloor = null @@ -159,6 +203,7 @@ object DungeonAPI { isUniqueClass = false playerClass = null playerClassLevel = -1 + DungeonBlessings.reset() } @SubscribeEvent @@ -266,6 +311,12 @@ object DungeonAPI { add("playerClass: $playerClass") add("isUniqueClass: $isUniqueClass") add("playerClassLevel: $playerClassLevel") + add("") + add("Life: ${DungeonBlessings.LIFE.power}") + add("Stone: ${DungeonBlessings.STONE.power}") + add("Wisdom: ${DungeonBlessings.WISDOM.power}") + add("Power: ${DungeonBlessings.POWER.power}") + add("Time: ${DungeonBlessings.TIME.power}") } } -- cgit