forked from Cookies_Github_mirror/AquaDX
[+] Maimai item unlock
This commit is contained in:
@@ -4,6 +4,7 @@ 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.Mai2ItemKind
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.data.domain.PageRequest
|
||||
@@ -25,7 +26,21 @@ class GetUserItemHandler(
|
||||
"itemId" to it.key,
|
||||
"stock" to 1,
|
||||
"isValid" to true,
|
||||
).toMap() } }
|
||||
) } }
|
||||
|
||||
val itemUnlock = Mai2ItemKind.ALL.filter { it.key in 1..3 || it.key in 9..12 }
|
||||
.mapValues { (kind, kindEnum) -> maimai2.itemMapping[kindEnum.name]?.map { (id, item) ->
|
||||
mapOf(
|
||||
"itemKind" to kind,
|
||||
"itemId" to id,
|
||||
"stock" to 1,
|
||||
"isValid" to true,
|
||||
) } ?: emptyList() }
|
||||
|
||||
init {
|
||||
if (musicUnlock[5].isNullOrEmpty()) logger.warn("Mai2 music info is empty")
|
||||
if (itemUnlock[1].isNullOrEmpty()) logger.warn("Mai2 item info is empty")
|
||||
}
|
||||
|
||||
override fun handle(request: Map<String, Any>): Any {
|
||||
val userId = (request["userId"] as Number).toLong()
|
||||
@@ -35,19 +50,28 @@ class GetUserItemHandler(
|
||||
val kind = (nextIndexVal / MULT).toInt()
|
||||
val nextIndex = (nextIndexVal % MULT).toInt()
|
||||
val pageNum = nextIndex / maxCount
|
||||
val kindType = Mai2ItemKind.ALL[kind]?.name
|
||||
|
||||
// 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 items = when {
|
||||
(kind in 5..8) && opt.unlockMusic -> musicUnlock.getValue(kind)
|
||||
(kind in 1..3 || kind == 11) && opt.unlockCollectables -> itemUnlock[kind]
|
||||
(kind == 12) && opt.unlockTickets -> itemUnlock[kind]
|
||||
(kind in 9..10) && opt.unlockChara -> itemUnlock[kind]
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
// If no items are found, disable the unlock feature
|
||||
if (items.isNullOrEmpty()) return@let
|
||||
|
||||
logger.info("Response: ${items.size} $kindType items - All unlock")
|
||||
return mapOf(
|
||||
"userId" to userId,
|
||||
"nextIndex" to 0,
|
||||
"itemKind" to kind,
|
||||
"userItemList" to items
|
||||
)
|
||||
}
|
||||
|
||||
val dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount))
|
||||
@@ -60,7 +84,7 @@ class GetUserItemHandler(
|
||||
"userItemList" to dbPage.content
|
||||
)
|
||||
|
||||
logger.info("Response: ${dbPage.numberOfElements} items")
|
||||
logger.info("Response: ${dbPage.numberOfElements} $kindType items")
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user