diff options
author | Jordan <77755681+Jordyrat@users.noreply.github.com> | 2024-09-08 08:21:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-08 09:21:14 +0200 |
commit | 9352ace3e97c92645b176f88b6cef6e638121b95 (patch) | |
tree | 803cbb085fc1b9e4877a8e16c6db697d10e6d90b /src/main/java/at/hannibal2/skyhanni/data/HotmData.kt | |
parent | 5ac091a11d558717eb42106bcad35d23653dab5d (diff) | |
download | skyhanni-9352ace3e97c92645b176f88b6cef6e638121b95.tar.gz skyhanni-9352ace3e97c92645b176f88b6cef6e638121b95.tar.bz2 skyhanni-9352ace3e97c92645b176f88b6cef6e638121b95.zip |
Improvement: Powder Tracker revamped (#2394)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/data/HotmData.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/HotmData.kt | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt b/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt index e82ddd4ae..0392eab25 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HotmData.kt @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.api.HotmAPI.MayhemPerk import at.hannibal2.skyhanni.api.HotmAPI.SkymallPerk import at.hannibal2.skyhanni.config.storage.ProfileSpecificStorage import at.hannibal2.skyhanni.data.jsonobjects.local.HotmTree +import at.hannibal2.skyhanni.data.model.TabWidget import at.hannibal2.skyhanni.events.DebugDataCollectEvent import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent @@ -12,6 +13,7 @@ import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.events.ScoreboardUpdateEvent +import at.hannibal2.skyhanni.events.WidgetUpdateEvent import at.hannibal2.skyhanni.features.gui.customscoreboard.ScoreboardPattern import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager @@ -23,7 +25,6 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatLong import at.hannibal2.skyhanni.utils.RegexUtils.indexOfFirstMatch import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst @@ -475,6 +476,15 @@ enum class HotmData( "§b§lMAYHEM! §r§7(?<perk>.*)", ) + /** + * REGEX-TEST: Mithril: §r§299,918 + * REGEX-TEST: Gemstone: §r§d37,670 + */ + private val powderPattern by patternGroup.pattern( + "widget.powder", + "\\s*(?<type>\\w+): (?:§.)+(?<amount>[\\d,.]+)" + ) + var inInventory = false var tokens: Int @@ -493,7 +503,7 @@ enum class HotmData( init { entries.forEach { it.guiNamePattern } - HotmAPI.Powder.entries.forEach { + HotmAPI.PowderType.entries.forEach { it.heartPattern it.resetPattern } @@ -527,7 +537,7 @@ enum class HotmData( it.rawLevel = 0 it.enabled = false it.isUnlocked = false - HotmAPI.Powder.entries.forEach { it.setCurrent(it.getTotal()) } + HotmAPI.PowderType.entries.forEach { it.setCurrent(it.getTotal()) } availableTokens = tokens } @@ -585,7 +595,7 @@ enum class HotmData( if (isHeartItem) { // Reset on the heart Item to remove duplication tokens = 0 availableTokens = 0 - HotmAPI.Powder.entries.forEach { it.reset() } + HotmAPI.PowderType.entries.forEach { it.reset() } heartItem = this } @@ -595,7 +605,7 @@ enum class HotmData( lore@ for (line in lore) { - HotmAPI.Powder.entries.forEach { + HotmAPI.PowderType.entries.forEach { it.pattern(isHeartItem).matchMatcher(line) { val powder = group("powder").replace(",", "").toLong() if (isHeartItem) { @@ -654,13 +664,12 @@ enum class HotmData( if (!LorenzUtils.inSkyBlock) return event.scoreboard.matchFirst(ScoreboardPattern.powderPattern) { - val type = HotmAPI.Powder.entries.firstOrNull { it.displayName == group("type") } ?: return + val type = HotmAPI.PowderType.entries.firstOrNull { it.displayName == group("type") } ?: return val amount = group("amount").formatLong() val difference = amount - type.getCurrent() if (difference > 0) { type.gain(difference) - ChatUtils.debug("Gained §a${difference.addSeparators()} §e${type.displayName} Powder") } } } @@ -687,6 +696,22 @@ enum class HotmData( } @SubscribeEvent + fun onWidgetUpdate(event: WidgetUpdateEvent) { + if (!event.isWidget(TabWidget.POWDER)) return + event.lines.forEach { + powderPattern.matchMatcher(it) { + val type = HotmAPI.PowderType.entries.firstOrNull { it.displayName == group("type") } ?: return + val amount = group("amount").replace(",", "").toLong() + val difference = amount - type.getCurrent() + + if (difference > 0) { + type.gain(difference) + } + } + } + } + + @SubscribeEvent fun onChat(event: LorenzChatEvent) { if (!LorenzUtils.inSkyBlock) return if (resetChatPattern.matches(event.message)) { @@ -733,7 +758,7 @@ enum class HotmData( @SubscribeEvent fun onProfileSwitch(event: ProfileJoinEvent) { - HotmAPI.Powder.entries.forEach { + HotmAPI.PowderType.entries.forEach { if (it.getStorage() == null) { ProfileStorageData.profileSpecific?.mining?.powder?.put( it, @@ -748,7 +773,7 @@ enum class HotmData( event.title("HotM") event.addIrrelevant { add("Tokens : $availableTokens/$tokens") - HotmAPI.Powder.entries.forEach { + HotmAPI.PowderType.entries.forEach { add("${it.displayName} Powder: ${it.getCurrent()}/${it.getTotal()}") } add("Ability: ${HotmAPI.activeMiningAbility?.printName}") |