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 | |
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')
6 files changed, 72 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/HotmAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/HotmAPI.kt index 39305a012..97e041a89 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/HotmAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/HotmAPI.kt @@ -2,12 +2,14 @@ package at.hannibal2.skyhanni.api import at.hannibal2.skyhanni.data.HotmData import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.mining.PowderGainEvent +import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemCategory import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getDrillUpgrades -import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.TimeLimitedCache import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraft.item.ItemStack @@ -30,7 +32,7 @@ object HotmAPI { } } == true - enum class Powder(val displayName: String, val color: String) { + enum class PowderType(val displayName: String, val color: String) { MITHRIL("Mithril", "§2"), GEMSTONE("Gemstone", "§d"), GLACITE("Glacite", "§b"), @@ -71,9 +73,11 @@ object HotmAPI { } /** Use when new powder gets collected*/ - fun gain(value: Long) { - addTotal(value) - addCurrent(value) + fun gain(difference: Long) { + ChatUtils.debug("Gained §a${difference.addSeparators()} §e${displayName} Powder") + addTotal(difference) + addCurrent(difference) + PowderGainEvent(this, difference).post() } fun reset() { diff --git a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java index e7a7565bb..794819cf1 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java +++ b/src/main/java/at/hannibal2/skyhanni/config/storage/ProfileSpecificStorage.java @@ -534,7 +534,7 @@ public class ProfileSpecificStorage { public HotmTree hotmTree = new HotmTree(); @Expose - public Map<HotmAPI.Powder, PowderStorage> powder = new HashMap<>(); + public Map<HotmAPI.PowderType, PowderStorage> powder = new HashMap<>(); public static class PowderStorage { 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}") diff --git a/src/main/java/at/hannibal2/skyhanni/events/mining/PowderGainEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/mining/PowderGainEvent.kt new file mode 100644 index 000000000..15bf3ee58 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/mining/PowderGainEvent.kt @@ -0,0 +1,6 @@ +package at.hannibal2.skyhanni.events.mining + +import at.hannibal2.skyhanni.api.HotmAPI +import at.hannibal2.skyhanni.api.event.SkyHanniEvent + +class PowderGainEvent(val powder: HotmAPI.PowderType, val amount: Long) : SkyHanniEvent() diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt index a58a7efc4..369fca62e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/customscoreboard/ScoreboardElements.kt @@ -731,7 +731,7 @@ private fun getQuiverShowWhen(): Boolean { } private fun getPowderDisplayPair() = buildList { - val powderTypes = HotmAPI.Powder.values() + val powderTypes = HotmAPI.PowderType.values() if (informationFilteringConfig.hideEmptyLines && powderTypes.all { it.getTotal() == 0L }) { return listOf("<hidden>" to HorizontalAlignment.LEFT) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt index 69e93489f..6edcac0a0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/powdertracker/PowderTracker.kt @@ -1,6 +1,8 @@ package at.hannibal2.skyhanni.features.mining.powdertracker import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.HotmAPI +import at.hannibal2.skyhanni.api.event.HandleEvent import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator import at.hannibal2.skyhanni.config.features.mining.PowderTrackerConfig.PowderDisplayEntry import at.hannibal2.skyhanni.data.BossbarData @@ -12,8 +14,10 @@ import at.hannibal2.skyhanni.events.IslandChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.events.SecondPassedEvent +import at.hannibal2.skyhanni.events.mining.PowderGainEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList +import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.ConditionalUtils.afterChange import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland @@ -32,6 +36,7 @@ import com.google.gson.annotations.Expose import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration import kotlin.time.Duration.Companion.minutes +import kotlin.time.Duration.Companion.seconds @SkyHanniModule object PowderTracker { @@ -192,13 +197,11 @@ object PowderTracker { } for (reward in PowderChestReward.entries) { + if (reward == PowderChestReward.MITHRIL_POWDER || reward == PowderChestReward.GEMSTONE_POWDER) return reward.chatPattern.matchMatcher(msg) { tracker.modify { val count = it.rewards[reward] ?: 0 - var amount = groupOrNull("amount")?.formatLong() ?: 1 - if ((reward == PowderChestReward.MITHRIL_POWDER || reward == PowderChestReward.GEMSTONE_POWDER) && doublePowder) { - amount *= 2 - } + val amount = groupOrNull("amount")?.formatLong() ?: 1 it.rewards[reward] = count + amount } } @@ -206,6 +209,20 @@ object PowderTracker { tracker.update() } + @HandleEvent(onlyOnIsland = IslandType.CRYSTAL_HOLLOWS) + fun onPowderGain(event: PowderGainEvent) { + if (lastChestPicked.passedSince() > 5.seconds) return + tracker.modify { + val reward = when (event.powder) { + HotmAPI.PowderType.GEMSTONE -> PowderChestReward.GEMSTONE_POWDER + HotmAPI.PowderType.MITHRIL -> PowderChestReward.MITHRIL_POWDER + else -> return@modify + } + it.rewards.addOrPut(reward, event.amount) + } + tracker.update() + } + @SubscribeEvent fun onConfigLoad(event: ConfigLoadEvent) { config.textFormat.afterChange { |