[+] Maimai item unlock

This commit is contained in:
Azalea
2024-03-18 05:31:55 -04:00
parent af83cf552e
commit b3955731c2
6 changed files with 84 additions and 32 deletions

View File

@@ -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
}

View File

@@ -1,13 +1,15 @@
package icu.samnyan.aqua.sega.maimai2.model.userdata;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import jakarta.persistence.*;
@@ -40,15 +42,26 @@ public class UserItem implements Serializable {
this.user = user;
}
public static final int KIND_NAMEPLATE = 1;
public static final int KIND_TITLE = 2;
public static final int KIND_ICON = 3;
public static final int KIND_MUSIC_UNLOCK = 5;
public static final int KIND_MUSIC_MASTER_UNLOCK = 6;
public static final int KIND_MUSIC_REMASTER_UNLOCK = 7;
public static final int KIND_MUSIC_STRONG_UNLOCK = 8;
public static final int KIND_CHARACTER = 9;
public static final int KIND_PARTNER = 10;
public static final int KIND_FRAME = 11;
public static final int KIND_TICKETS = 12;
public enum Mai2ItemKind {
plate(1),
title(2),
icon(3),
musicUnlock(5),
musicMasterUnlock(6),
musicRemasterUnlock(7),
musicStrongUnlock(8),
chara(9),
partner(10),
frame(11),
ticket(12);
public final int value;
Mai2ItemKind(int value) {
this.value = value;
}
public static final Map<Integer, Mai2ItemKind> ALL = Arrays.stream(Mai2ItemKind.class.getEnumConstants())
.map(k -> Map.entry(k.value, k)).collect(HashMap::new, (m, v) -> m.put(v.getKey(), v.getValue()), Map::putAll);
}
}