blob: eb99d167402c06601a311b4fa274ae49a1e4a296 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
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.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
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.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.fixedRateTimer
class FrozenTreasureTracker {
private val config get() = SkyHanniMod.feature.misc.frozenTreasureTracker
private var display = emptyList<List<Any>>()
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()
init {
fixedRateTimer(name = "skyhanni-dungeon-milestone-display", period = 1000) {
if (!onJerryWorkshop()) return@fixedRateTimer
calculateIcePerHour()
}
}
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
icePerHour = 0
stoppedChecks = 0
icePerMin.clear()
saveAndUpdate()
}
private fun calculateIcePerHour() {
val difference = estimatedIce - lastEstimatedIce
lastEstimatedIce = estimatedIce
if (difference == estimatedIce) {
return
}
icePerHour = icePerMin.average().toInt() * 3600
icePerMin.add(difference)
if (difference == 0L) {
stoppedChecks += 1
if (stoppedChecks == 60) {
stoppedChecks = 0
icePerMin.clear()
icePerHour = 0
}
return
}
stoppedChecks = 0
}
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()
val storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return
compactPattern.matchMatcher(message) {
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)) {
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"
}
}
}
@SubscribeEvent
fun onPreProfileSwitch(event: PreProfileSwitchEvent) {
display = emptyList()
}
private fun drawTreasureDisplay(storage: Storage.ProfileSpecific.FrozenTreasureTracker) = buildList<List<Any>> {
addAsSingletonList("§1§lFrozen Treasure Tracker")
addAsSingletonList("§6${formatNumber(storage.treasuresMined)} Treasures Mined")
addAsSingletonList("§3${formatNumber(estimatedIce)} Total Ice")
addAsSingletonList("§3${formatNumber(icePerHour)} Ice/hr")
addAsSingletonList("§8${formatNumber(storage.treasuresMined)} Compact Procs")
addAsSingletonList("")
for (treasure in FrozenTreasure.entries) {
val count = (storage.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 storage = ProfileStorageData.profileSpecific?.frozenTreasureTracker ?: return
calculateIce(storage)
display = formatDisplay(drawTreasureDisplay(storage))
}
private fun calculateIce(storage: Storage.ProfileSpecific.FrozenTreasureTracker) {
estimatedIce = 0
estimatedIce += storage.compactProcs * 160
for (treasure in FrozenTreasure.entries) {
val amount = storage.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 = "Frozen Treasure Tracker")
}
private fun onJerryWorkshop() = LorenzUtils.inIsland(IslandType.WINTER)
private fun inGlacialCave() = onJerryWorkshop() && ScoreboardData.sidebarLinesFormatted.contains(" §7⏣ §3Glacial Cave")
}
|