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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.data.jsonobjects.repo.CarryTrackerJson
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.events.entity.slayer.SlayerDeathEvent
import at.hannibal2.skyhanni.features.slayer.SlayerType
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatDouble
import at.hannibal2.skyhanni.utils.NumberUtil.formatDoubleOrUserError
import at.hannibal2.skyhanni.utils.NumberUtil.formatIntOrUserError
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils.cleanPlayerName
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.seconds
/**
* TODO more carry features
* save on restart
* support for Dungeon, Kuudra, crimson minibosses
* average spawn time per slayer customer
* change customer name color if offline, onlilne, on your island
* show time since last boss died next to slayer customer name
* highlight slayer bosses for slayer customers
* automatically mark customers with /shmarkplaayers
* show a line behind them
*/
@SkyHanniModule
object CarryTracker {
private val config get() = SkyHanniMod.feature.misc
private val customers = mutableListOf<Customer>()
private val carryTypes = mutableMapOf<String, CarryType>()
private var slayerNames = emptyMap<SlayerType, List<String>>()
private var display = listOf<Renderable>()
private val patternGroup = RepoPattern.group("carry")
/**
* REGEX-TEST:
* §6Trade completed with §r§b[MVP§r§c+§r§b] ClachersHD§r§f§r§6!
*/
private val tradeCompletedPattern by patternGroup.pattern(
"trade.completed",
"§6Trade completed with (?<name>.*)§r§6!",
)
/**
* REGEX-TEST:
* §r§a§l+ §r§6500k coins
*/
private val rawNamePattern by patternGroup.pattern(
"trade.coins.gained",
" §r§a§l\\+ §r§6(?<coins>.*) coins",
)
@HandleEvent
fun onSlayerDeath(event: SlayerDeathEvent) {
val slayerType = event.slayerType
val tier = event.tier
val owner = event.owner
for (customer in customers) {
if (!customer.name.equals(owner, ignoreCase = true)) continue
for (carry in customer.carries) {
val type = carry.type as? SlayerCarryType ?: return
if (type.slayerType != slayerType) continue
if (type.tier != tier) continue
carry.done++
if (carry.done == carry.requested) {
ChatUtils.chat("Carry done for ${customer.name}!")
LorenzUtils.sendTitle("§eCarry done!", 3.seconds)
}
update()
}
}
}
// TODO create trade event with player name, coins and items
var lastTradedPlayer = ""
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
tradeCompletedPattern.matchMatcher(event.message) {
lastTradedPlayer = group("name").cleanPlayerName()
}
rawNamePattern.matchMatcher(event.message) {
val coinsGained = group("coins").formatDouble()
getCustomer(lastTradedPlayer).alreadyPaid += coinsGained
update()
}
}
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<CarryTrackerJson>("CarryTracker")
slayerNames = data.slayerNames.mapKeys { SlayerType.valueOf(it.key) }
}
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent) {
if (!LorenzUtils.inSkyBlock) return
config.carryPosition.renderRenderables(display, posLabel = "Carry Tracker")
}
fun onCommand(args: Array<String>) {
if (args.size < 2 || args.size > 3) {
ChatUtils.userError("Usage:\n§c/shcarry <customer name> <type> <amount requested>\n§c/shcarry <type> <price per>")
return
}
if (args.size == 2) {
setPrice(args[0], args[1])
return
}
val customerName = args[0]
val rawType = args[1]
val carryType = getCarryType(rawType) ?: return
val amountRequested = args[2].formatIntOrUserError() ?: return
val newCarry = Carry(carryType, amountRequested)
for (customer in customers) {
if (!customer.name.equals(customerName, ignoreCase = true)) continue
val carries = customer.carries
for (carry in carries.toList()) {
if (!newCarry.type.sameType(carry.type)) continue
val newAmountRequested = carry.requested + amountRequested
if (newAmountRequested < 1) {
ChatUtils.userError("New carry amount requested must be positive!")
return
}
carries.remove(carry)
val updatedCarry = Carry(carryType, newAmountRequested)
updatedCarry.done = carry.done
carries.add(updatedCarry)
update()
ChatUtils.chat("Updated carry: §b$customerName §8x$newAmountRequested ${newCarry.type}")
return
}
}
if (amountRequested < 1) {
ChatUtils.userError("Carry amount requested must be positive!")
return
}
val customer = getCustomer(customerName)
customer.carries.add(newCarry)
update()
ChatUtils.chat("Started carry: §b$customerName §8x$amountRequested ${newCarry.type}")
}
private fun getCarryType(rawType: String): CarryType? = carryTypes.getOrPut(rawType) {
createCarryType(rawType) ?: run {
ChatUtils.userError("Unknown carry type: '$rawType'! Use e.g. rev5, sven4, eman3, blaze2..")
return null
}
}
private fun setPrice(rawType: String, rawPrice: String) {
val carryType = getCarryType(rawType) ?: return
val price = rawPrice.formatDoubleOrUserError() ?: return
carryType.pricePer = price
update()
ChatUtils.chat("Set carry price for $carryType §eto §6${price.shortFormat()} coins.")
}
private fun getCustomer(customerName: String): Customer {
for (customer in customers) {
if (customer.name.equals(customerName, ignoreCase = true)) {
return customer
}
}
val customer = Customer(customerName)
customers.add(customer)
return customer
}
private fun CarryType.sameType(other: CarryType): Boolean = name == other.name && tier == other.tier
private fun update() {
val list = mutableListOf<Renderable>()
if (customers.none { it.carries.isNotEmpty() }) {
display = emptyList()
return
}
list.addString("§c§lCarries")
for (customer in customers) {
if (customer.carries.isEmpty()) continue
addCustomerName(customer, list)
val carries = customer.carries
for (carry in carries) {
val requested = carry.requested
val done = carry.done
val missing = requested - done
val color = if (done > requested) "§c" else if (done == requested) "§a" else "§e"
val cost = formatCost(carry.type.pricePer?.let { it * requested })
val text = "$color$done§8/$color$
|