From c5879ae5a7cc053fe7aef4c8c9132006427b987d Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:08:48 -0400 Subject: [PATCH] [+] Wacca user/sugoroku/update --- .../samnyan/aqua/sega/wacca/WaccaServer.kt | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt index 97581ca5..9993d17d 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt @@ -187,4 +187,42 @@ fun WaccaServer.init() { ) } } -} \ No newline at end of file + fun addItems(recv: List>, u: WaccaUser, items: Map>) { + if (recv.isEmpty()) return + val newItems = mutableListOf() + recv.forEach { (id, type, param) -> + val ex = items[type]?.get(id) + when (type) { + WP() -> u.wp += param + XP() -> u.xp += param + MUSIC_DIFFICULTY_UNLOCK(), + MUSIC_UNLOCK() -> newItems += (ex ?: WcUserItem(type, id)) + .apply { user = u; p1 = min(max(param.long(), p1), WaccaDifficulty.HARD.value.long()) } + TROPHY() -> newItems += (ex ?: TROPHY(u, id)).apply { p1 = season.long(); p2 = param.long() } + else -> newItems += (ex ?: WcUserItem(type, id)).apply { user = u } + } + } + rp.user.save(u) + rp.item.saveAll(newItems) + } + + "user/sugoroku/update" api@ { _, (uid, gid, page, progress, loops, boostsUsed, itemsRecv, totalPts, missionFlag) -> + val u = user(uid) ?: (400 - "User not found") + val g = rp.gate.findByUserAndGateId(u, gid.int()) ?: WcUserGate().apply { user = u; gateId = gid.int() } + val items = itmGrp(u) + + // Update gate + rp.gate.save(g.also { + it.page = page.int() + it.progress = progress.int() + it.loops = loops.int() + it.missionFlag = missionFlag.int() + it.totalPoints = totalPts.int() + }) + + operator fun MutableList.plusAssign(item: T) { add(item) } + + // Update items + addItems(itemsRecv as List>, u, items) + empty + }