diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt index 8350a637e..eb99d1674 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt @@ -1,10 +1,14 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.ProfileStorageData import at.hannibal2.skyhanni.data.ScoreboardData -import at.hannibal2.skyhanni.events.* +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.PreProfileSwitchEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.LorenzUtils.editCopy @@ -19,8 +23,6 @@ import kotlin.concurrent.fixedRateTimer class FrozenTreasureTracker { private val config get() = SkyHanniMod.feature.misc.frozenTreasureTracker private var display = emptyList<List<Any>>() - private var treasuresMined = 0 - private var compactProcs = 0 private var estimatedIce = 0L private var lastEstimatedIce = 0L private val icePerMin = mutableListOf<Long>() @@ -28,8 +30,6 @@ class FrozenTreasureTracker { private var stoppedChecks = 0 private var compactPattern = "COMPACT! You found an Enchanted Ice!".toPattern() - private var treasureCount = mapOf<FrozenTreasure, Int>() - init { fixedRateTimer(name = "skyhanni-dungeon-milestone-display", period = 1000) { if (!onJerryWorkshop()) return@fixedRateTimer @@ -82,18 +82,19 @@ class FrozenTreasureTracker { if (!onJerryWorkshop()) return val message = event.message.removeColor().trim() + val storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return compactPattern.matchMatcher(message) { - compactProcs += 1 + storage.compactProcs += 1 saveAndUpdate() if (config.hideMessages) event.blockedReason = "frozen treasure tracker" } for (treasure in FrozenTreasure.entries) { if ("FROZEN TREASURE! You found ${treasure.displayName.removeColor()}!".toRegex().matches(message)) { - treasuresMined += 1 - val old = treasureCount[treasure] ?: 0 - treasureCount = treasureCount.editCopy { this[treasure] = old + 1 } + storage.treasuresMined += 1 + val old = storage.treasureCount[treasure] ?: 0 + storage.treasureCount = storage.treasureCount.editCopy { this[treasure] = old + 1 } saveAndUpdate() if (config.hideMessages) event.blockedReason = "frozen treasure tracker" } @@ -105,25 +106,16 @@ class FrozenTreasureTracker { display = emptyList() } - @SubscribeEvent - fun onConfigLoad(event: ConfigLoadEvent) { - val hidden = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return - treasuresMined = hidden.treasuresMined - compactProcs = hidden.compactProcs - treasureCount = hidden.treasureCount - saveAndUpdate() - } - - private fun drawTreasureDisplay() = buildList<List<Any>> { + private fun drawTreasureDisplay(storage: Storage.ProfileSpecific.FrozenTreasureTracker) = buildList<List<Any>> { addAsSingletonList("§1§lFrozen Treasure Tracker") - addAsSingletonList("§6${formatNumber(treasuresMined)} Treasures Mined") + addAsSingletonList("§6${formatNumber(storage.treasuresMined)} Treasures Mined") addAsSingletonList("§3${formatNumber(estimatedIce)} Total Ice") addAsSingletonList("§3${formatNumber(icePerHour)} Ice/hr") - addAsSingletonList("§8${formatNumber(compactProcs)} Compact Procs") + addAsSingletonList("§8${formatNumber(storage.treasuresMined)} Compact Procs") addAsSingletonList("") for (treasure in FrozenTreasure.entries) { - val count = (treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1 + val count = (storage.treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1 addAsSingletonList("§b${formatNumber(count)} ${treasure.displayName}") } addAsSingletonList("") @@ -136,19 +128,16 @@ class FrozenTreasureTracker { } private fun saveAndUpdate() { - val hidden = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return - hidden.treasuresMined = treasuresMined - hidden.compactProcs = compactProcs - hidden.treasureCount = treasureCount - calculateIce() - display = formatDisplay(drawTreasureDisplay()) + val storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return + calculateIce(storage) + display = formatDisplay(drawTreasureDisplay(storage)) } - private fun calculateIce() { + private fun calculateIce(storage: Storage.ProfileSpecific.FrozenTreasureTracker) { estimatedIce = 0 - estimatedIce += compactProcs * 160 + estimatedIce += storage.compactProcs * 160 for (treasure in FrozenTreasure.entries) { - val amount = treasureCount[treasure] ?: 0 + val amount = storage.treasureCount[treasure] ?: 0 estimatedIce += amount * treasure.defaultAmount * treasure.iceMultiplier } } |