aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-06-23 00:50:09 +0200
committerGitHub <noreply@github.com>2023-06-23 00:50:09 +0200
commit1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c (patch)
tree778ae39b4c35133f5117cbe9a9a4c2223a4eeeba /src/main/java/at/hannibal2/skyhanni/features
parentc7463ccbbe3f6a7ff91ed38f0bcafe82dd1a843c (diff)
parenta1efe2d469bfe9e152ffcae4cd42dd9e98818c0f (diff)
downloadskyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.tar.gz
skyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.tar.bz2
skyhanni-1cf1600d0eec7f027c4d10d1b6eb2b2cb249309c.zip
Merge pull request #242
Frozen Treasure Tracker
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt165
2 files changed, 184 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt
new file mode 100644
index 000000000..e2c70cedc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasure.kt
@@ -0,0 +1,19 @@
+package at.hannibal2.skyhanni.features.misc
+
+enum class FrozenTreasure(
+ val internalName: String,
+ val displayName: String,
+ val defaultAmount: Int,
+ val iceMultiplier: Int = 0,
+) {
+ WHITE_GIFT("WHITE_GIFT", "§fWhite Gift", 1),
+ GREEN_GIFT("GREEN_GIFT", "§aGreen Gift", 1),
+ RED_GIFT("RED_GIFT", "§9§cRed Gift", 1),
+ PACKED_ICE("PACKED_ICE", "§fPacked Ice", 32, 9),
+ ENCHANTED_ICE("ENCHANTED_ICE", "§aEnchanted Ice", 9, 160), // wiki says 1-16 so assuming 9
+ ENCHANTED_PACKED_ICE("ENCHANTED_PACKED_ICE", "§9Enchanted Packed Ice", 1, 25600),
+ ICE_BAIT("ICE_BAIT", "§aIce Bait", 16),
+ GLOWY_CHUM_BAIT("GLOWY_CHUM_BAIT", "§aGlowy Chum Bait", 16),
+ GLACIAL_FRAGMENT("GLACIAL_FRAGMENT", "§5Glacial Fragment", 1),
+ GLACIAL_TALISMAN("GLACIAL_TALISMAN", "§fGlacial Talisman", 1)
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt
new file mode 100644
index 000000000..10c2f0bd6
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FrozenTreasureTracker.kt
@@ -0,0 +1,165 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.data.ScoreboardData
+import at.hannibal2.skyhanni.events.ConfigLoadEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+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
+import at.hannibal2.skyhanni.utils.NumberUtil
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+import net.minecraftforge.event.world.WorldEvent
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.concurrent.fixedRateTimer
+
+class FrozenTreasureTracker {
+ private val config get() = SkyHanniMod.feature.misc.frozenTreasureTracker
+ private var display = listOf<List<Any>>()
+ private var treasuresMined = 0
+ private var compactProcs = 0
+ private var estimatedIce = 0L
+ private var lastEstimatedIce = 0L
+ private val icePerMin = mutableListOf<Long>()
+ private var icePerHour = 0
+ 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 = 15_000) {
+ if (!onJerryWorkshop()) return@fixedRateTimer
+ calculateIcePerHour()
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldLoad(event: WorldEvent.Load) {
+ icePerHour = 0
+ stoppedChecks = 0
+ icePerMin.clear()
+ saveAndUpdate()
+ }
+
+ private fun calculateIcePerHour() {
+ val difference = estimatedIce - lastEstimatedIce
+ lastEstimatedIce = estimatedIce
+ if (difference == 0L) {
+ stoppedChecks += 1
+ if (stoppedChecks == 12) {
+ stoppedChecks = 0
+ icePerMin.clear()
+ icePerHour = 0
+ }
+ return
+ }
+ stoppedChecks = 0
+ icePerMin.add(difference)
+ if (difference != estimatedIce) icePerHour = icePerMin.average().toInt() * 240
+ }
+
+ private fun formatDisplay(map: List<List<Any>>): List<List<Any>> {
+ val newList = mutableListOf<List<Any>>()
+ for (index in config.textFormat) {
+ newList.add(map[index])
+ }
+ return newList
+ }
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!ProfileStorageData.loaded) return
+ if (!onJerryWorkshop()) return
+
+ val message = event.message.removeColor().trim()
+
+ compactPattern.matchMatcher(message) {
+ compactProcs += 1
+ saveAndUpdate()
+ if (config.hideMessages) event.blockedReason = "frozen treasure tracker"
+ }
+
+ for (treasure in FrozenTreasure.values()) {
+ 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 }
+ saveAndUpdate()
+ if (config.hideMessages) event.blockedReason = "frozen treasure tracker"
+ }
+ }
+ }
+
+ @SubscribeEvent
+ fun onPreProfileSwitch(event: PreProfileSwitchEvent) {
+ 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>> {
+ addAsSingletonList("§1§lFrozen Treasure Tracker")
+ addAsSingletonList("§6${formatNumber(treasuresMined)} Treasures Mined")
+ addAsSingletonList("§3${formatNumber(estimatedIce)} Total Ice")
+ addAsSingletonList("§3${formatNumber(icePerHour)} Ice/hr")
+ addAsSingletonList("§8${formatNumber(compactProcs)} Compact Procs")
+ addAsSingletonList("")
+
+ for (treasure in FrozenTreasure.values()) {
+ val count = (treasureCount[treasure] ?: 0) * if (config.showAsDrops) treasure.defaultAmount else 1
+ addAsSingletonList("§b${formatNumber(count)} ${treasure.displayName}")
+ }
+ addAsSingletonList("")
+ }
+
+ fun formatNumber(amount: Number): String {
+ if (amount is Int) return amount.addSeparators()
+ if (amount is Long) return NumberUtil.format(amount)
+ return "$amount"
+ }
+
+ private fun saveAndUpdate() {
+ val hidden = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return
+ hidden.treasuresMined = treasuresMined
+ hidden.compactProcs = compactProcs
+ hidden.treasureCount = treasureCount
+ calculateIce()
+ display = formatDisplay(drawTreasureDisplay())
+ }
+
+ private fun calculateIce() {
+ estimatedIce = 0
+ estimatedIce += compactProcs * 160
+ for (treasure in FrozenTreasure.values()) {
+ val amount = treasureCount[treasure] ?: 0
+ estimatedIce += amount * treasure.defaultAmount * treasure.iceMultiplier
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
+ if (!config.enabled) return
+ if (!onJerryWorkshop()) return
+ if (config.onlyInCave && !inGlacialCave()) return
+ config.position.renderStringsAndItems(display, posLabel = "Visitor Stats")
+ }
+
+ private fun onJerryWorkshop() = LorenzUtils.inIsland(IslandType.WINTER)
+
+ private fun inGlacialCave() = onJerryWorkshop() && ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §3Glacial Cave")
+} \ No newline at end of file