forked from Cookies_Public/AquaDX
[F] Fix maimai music unlock
This commit is contained in:
parent
e0c7998448
commit
f4cc9c7734
@ -1,15 +1,14 @@
|
|||||||
package icu.samnyan.aqua.sega.maimai2.handler.impl
|
package icu.samnyan.aqua.sega.maimai2.handler.impl
|
||||||
|
|
||||||
import ext.JSON
|
|
||||||
import icu.samnyan.aqua.net.games.Maimai2
|
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.handler.BaseHandler
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
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.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.springframework.data.domain.PageRequest
|
import org.springframework.data.domain.PageRequest
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
@ -17,37 +16,40 @@ import org.springframework.stereotype.Component
|
|||||||
@Component("Maimai2GetUserItemHandler")
|
@Component("Maimai2GetUserItemHandler")
|
||||||
class GetUserItemHandler(
|
class GetUserItemHandler(
|
||||||
val repos: Mai2Repos,
|
val repos: Mai2Repos,
|
||||||
val maimai2: Maimai2
|
val maimai2: Maimai2,
|
||||||
|
val cardRepo: CardRepository,
|
||||||
) : BaseHandler {
|
) : BaseHandler {
|
||||||
val musicUnlock = (5..8).associateWith { kind ->
|
val musicUnlock = (5..8).associateWith { kind ->
|
||||||
JSON.encodeToString(maimai2.musicMapping.mapKeys { UserItem().apply {
|
maimai2.musicMapping.map { mapOf(
|
||||||
itemKind = kind
|
"itemKind" to kind,
|
||||||
itemId = it.key
|
"itemId" to it.key,
|
||||||
stock = 1
|
"stock" to 1,
|
||||||
} }) }
|
"isValid" to true,
|
||||||
|
).toMap() } }
|
||||||
|
|
||||||
override fun handle(request: Map<String, Any>): Any {
|
override fun handle(request: Map<String, Any>): Any {
|
||||||
val userId = request["userId"] as Long
|
val userId = (request["userId"] as Number).toLong()
|
||||||
val nextIndexVal = request["nextIndex"] as Long
|
val nextIndexVal = (request["nextIndex"] as Number).toLong()
|
||||||
val maxCount = request["maxCount"] as Int
|
val maxCount = (request["maxCount"] as Number).toInt()
|
||||||
|
|
||||||
val kind = (nextIndexVal / MULT).toInt()
|
val kind = (nextIndexVal / MULT).toInt()
|
||||||
val nextIndex = (nextIndexVal % MULT).toInt()
|
val nextIndex = (nextIndexVal % MULT).toInt()
|
||||||
val pageNum = nextIndex / maxCount
|
val pageNum = nextIndex / maxCount
|
||||||
|
|
||||||
// All Music unlock TODO: Check user settings
|
// Aqua Net game unlock feature
|
||||||
if (kind in 5..8) {
|
cardRepo.findByExtId(userId).getOrNull()?.aquaUser?.gameOptions?.let { opt ->
|
||||||
logger.info("Response: ${maimai2.musicMapping.size} items - Music unlock")
|
// All Music unlock
|
||||||
return mapOf(
|
if (kind in 5..8 && opt.unlockMusic) {
|
||||||
"userId" to userId,
|
logger.info("Response: ${maimai2.musicMapping.size} items - Music unlock")
|
||||||
"nextIndex" to 0,
|
return mapOf(
|
||||||
"itemKind" to kind,
|
"userId" to userId,
|
||||||
"userItemList" to musicUnlock.getValue(kind)
|
"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 dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount))
|
||||||
|
|
||||||
val currentIndex = kind * MULT + maxCount * pageNum + dbPage.numberOfElements
|
val currentIndex = kind * MULT + maxCount * pageNum + dbPage.numberOfElements
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user