-
-
Notifications
You must be signed in to change notification settings - Fork 208
/
HoppityEggsCompactChat.kt
173 lines (152 loc) · 7.82 KB
/
HoppityEggsCompactChat.kt
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package at.hannibal2.skyhanni.features.event.hoppity
import at.hannibal2.skyhanni.config.features.event.hoppity.HoppityChatConfig
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.event.hoppity.HoppityAPI.HoppityStateDataSet
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEggType.Companion.resettingEntries
import at.hannibal2.skyhanni.features.event.hoppity.HoppityEventSummary.getRabbitsFormat
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryAPI
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryTimeTowerManager
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.takeIfNotEmpty
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.fromNow
import at.hannibal2.skyhanni.utils.TimeUtils.format
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
typealias RarityType = HoppityChatConfig.CompactRarityTypes
@SkyHanniModule
object HoppityEggsCompactChat {
private var hoppityDataSet = HoppityStateDataSet()
private val config get() = ChocolateFactoryAPI.config
private val eventConfig get() = HoppityEggsManager.config
private val chatConfig get() = HoppityEggsManager.config.chat
private val hitmanCompactDataSets: MutableList<HoppityStateDataSet> = mutableListOf()
fun compactChat(event: LorenzChatEvent?, dataSet: HoppityStateDataSet) {
if (!chatConfig.compact) return
hoppityDataSet = dataSet.copy()
event?.let { it.blockedReason = "compact_hoppity" }
if (hoppityDataSet.hoppityMessages.size == 3) sendCompact()
}
private fun sendCompact() {
if (hoppityDataSet.lastMeal?.let { it == HoppityEggType.HITMAN } == true) handleCompactHitman()
else sendNonHitman()
}
private fun sendNonHitman() {
if (HoppityEggType.resettingEntries.contains(hoppityDataSet.lastMeal) && eventConfig.sharedWaypoints) {
DelayedRun.runDelayed(5.milliseconds) {
createWaypointShareCompactMessage(HoppityEggsManager.getAndDisposeWaypointOnclick())
hoppityDataSet.reset()
}
} else {
ChatUtils.hoverableChat(createCompactMessage(), hover = hoppityDataSet.hoppityMessages, prefix = false)
hoppityDataSet.reset()
}
}
private fun handleCompactHitman() {
if (!chatConfig.compactHitman) {
sendNonHitman()
return
}
hoppityDataSet.let {
hitmanCompactDataSets.add(it.copy())
it.reset()
}
val sizeNow = hitmanCompactDataSets.size
DelayedRun.runDelayed(750.milliseconds) {
if (hitmanCompactDataSets.size != sizeNow) return@runDelayed
if (hitmanCompactDataSets.size == 1) {
hoppityDataSet = hitmanCompactDataSets.first() // Pop back out the stored data
sendNonHitman()
}
else sendHitmanSummary()
}
}
private fun sendHitmanSummary() {
if (hitmanCompactDataSets.isEmpty()) return
val summaryMessage = buildString {
appendLine("§c§lHitman Summary")
appendLine()
// Create a Map of LorenzRarity -> Int so we can use the existing EventSummary logic
val rarityMap: Map<LorenzRarity, Int> = hitmanCompactDataSets
.mapNotNull { it.lastRarity }
.groupingBy { it }
.eachCount()
getRabbitsFormat(rarityMap, "Total Hitman").forEach { appendLine(it) }
hitmanCompactDataSets.filter { !it.duplicate }.takeIfNotEmpty()?.let { sets ->
appendLine()
appendLine("§d§lNEW Rabbits")
sets.forEach { set ->
appendLine(
"${set.getRarityFormat()}${set.getNameFormat()} §7(${hoppityDataSet.lastProfit}§7)"
)
}
}
hitmanCompactDataSets.filter { it.duplicate }.takeIfNotEmpty()?.let { sets ->
appendLine()
// Create a Map of LorenzRarity -> Int so we can use the existing EventSummary logic
val dupeRarityMap: Map<LorenzRarity, Int> = sets
.mapNotNull { it.lastRarity }
.groupingBy { it }
.eachCount()
getRabbitsFormat(dupeRarityMap, "Duplicate").forEach { appendLine(it) }
val dupeChocolateAmount = sets.sumOf { it.lastDuplicateAmount ?: 0 }
val timeFormat = dupeChocolateAmount.getChocExtraTimeString()
appendLine(" §6+${dupeChocolateAmount.addSeparators()} §6Chocolate§7$timeFormat")
}
}
ChatUtils.chat(summaryMessage, prefix = false)
hitmanCompactDataSets.clear()
}
private fun Long?.getChocExtraTimeString(): String {
if (this == null) return "?"
val extraTime = ChocolateFactoryAPI.timeUntilNeed(this)
return if (config.showDuplicateTime) ", §a+§b${extraTime.format(maxUnits = 2)}§7" else ""
}
private fun HoppityStateDataSet.getNameFormat(): String =
lastName.takeIf { it.isNotEmpty() } ?: "§C§L???"
private fun HoppityStateDataSet.getRarityString(): String =
lastRarity?.let { "${it.chatColorCode}§l${it.rawName}" } ?: "§C§L???"
private fun HoppityStateDataSet.getRarityFormat(): String = when {
hoppityDataSet.duplicate && chatConfig.rarityInCompact in listOf(RarityType.BOTH, RarityType.DUPE) -> "${getRarityString()} "
!hoppityDataSet.duplicate && chatConfig.rarityInCompact in listOf(RarityType.BOTH, RarityType.NEW) -> "${getRarityString()} "
else -> ""
}
private fun createCompactMessage(withMeal: Boolean = true): String {
val mealNameFormat = if (withMeal) when (hoppityDataSet.lastMeal) {
in resettingEntries -> "${hoppityDataSet.lastMeal?.coloredName.orEmpty()} Egg"
else -> "${hoppityDataSet.lastMeal?.coloredName.orEmpty()} Rabbit"
} else ""
val nameFormat = hoppityDataSet.getNameFormat()
val rarityFormat = hoppityDataSet.getRarityFormat()
return if (hoppityDataSet.duplicate) {
val dupeChocAmount = hoppityDataSet.lastDuplicateAmount?.shortFormat() ?: "?"
val dupeNumberFormat = if (chatConfig.showDuplicateNumber) {
(HoppityCollectionStats.getRabbitCount(hoppityDataSet.lastName)).takeIf { it > 0 }?.let {
" §7(§b#$it§7)"
}.orEmpty()
} else ""
val timeStr = hoppityDataSet.lastDuplicateAmount.getChocExtraTimeString()
val dupeChocColor = if (chatConfig.recolorTTChocolate && ChocolateFactoryTimeTowerManager.timeTowerActive()) "§d" else "§6"
val dupeChocFormat = " §7(§6+$dupeChocColor$dupeChocAmount §6Chocolate§7$timeStr)"
"$mealNameFormat! §7Duplicate $rarityFormat$nameFormat$dupeNumberFormat$dupeChocFormat"
} else {
"$mealNameFormat! §d§lNEW $rarityFormat$nameFormat §7(${hoppityDataSet.lastProfit}§7)"
}
}
private fun createWaypointShareCompactMessage(onClick: () -> Unit) {
val hover = hoppityDataSet.hoppityMessages.joinToString("\n") +
" \n§eClick here to share the location of this chocolate egg with the server!"
ChatUtils.clickableChat(
createCompactMessage(),
hover = hover,
onClick = onClick,
expireAt = 30.seconds.fromNow(),
oneTimeClick = true,
prefix = false,
)
}
}