From f4cc9c773426629f7ab9ffed6a8fb0806f2071b5 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Mon, 18 Mar 2024 01:32:00 -0400 Subject: [PATCH] [F] Fix maimai music unlock --- .../handler/impl/GetUserItemHandler.kt | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/impl/GetUserItemHandler.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/impl/GetUserItemHandler.kt index a0d18993..20b45bdf 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/impl/GetUserItemHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/handler/impl/GetUserItemHandler.kt @@ -1,15 +1,14 @@ package icu.samnyan.aqua.sega.maimai2.handler.impl -import ext.JSON import icu.samnyan.aqua.net.games.Maimai2 +import icu.samnyan.aqua.sega.general.dao.CardRepository import icu.samnyan.aqua.sega.maimai2.handler.BaseHandler import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos -import icu.samnyan.aqua.sega.maimai2.model.userdata.UserItem -import kotlinx.serialization.encodeToString import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.data.domain.PageRequest import org.springframework.stereotype.Component +import kotlin.jvm.optionals.getOrNull /** * @author samnyan (privateamusement@protonmail.com) @@ -17,37 +16,40 @@ import org.springframework.stereotype.Component @Component("Maimai2GetUserItemHandler") class GetUserItemHandler( val repos: Mai2Repos, - val maimai2: Maimai2 + val maimai2: Maimai2, + val cardRepo: CardRepository, ) : BaseHandler { val musicUnlock = (5..8).associateWith { kind -> - JSON.encodeToString(maimai2.musicMapping.mapKeys { UserItem().apply { - itemKind = kind - itemId = it.key - stock = 1 - } }) } + maimai2.musicMapping.map { mapOf( + "itemKind" to kind, + "itemId" to it.key, + "stock" to 1, + "isValid" to true, + ).toMap() } } override fun handle(request: Map): Any { - val userId = request["userId"] as Long - val nextIndexVal = request["nextIndex"] as Long - val maxCount = request["maxCount"] as Int + val userId = (request["userId"] as Number).toLong() + val nextIndexVal = (request["nextIndex"] as Number).toLong() + val maxCount = (request["maxCount"] as Number).toInt() val kind = (nextIndexVal / MULT).toInt() val nextIndex = (nextIndexVal % MULT).toInt() val pageNum = nextIndex / maxCount - // All Music unlock TODO: Check user settings - if (kind in 5..8) { - logger.info("Response: ${maimai2.musicMapping.size} items - Music unlock") - return mapOf( - "userId" to userId, - "nextIndex" to 0, - "itemKind" to kind, - "userItemList" to musicUnlock.getValue(kind) - ) + // Aqua Net game unlock feature + cardRepo.findByExtId(userId).getOrNull()?.aquaUser?.gameOptions?.let { opt -> + // All Music unlock + if (kind in 5..8 && opt.unlockMusic) { + logger.info("Response: ${maimai2.musicMapping.size} items - Music unlock") + return mapOf( + "userId" to userId, + "nextIndex" to 0, + "itemKind" to kind, + "userItemList" to musicUnlock.getValue(kind) + ) + } } - // - val dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount)) val currentIndex = kind * MULT + maxCount * pageNum + dbPage.numberOfElements