mirror of https://github.com/hykilpikonna/AquaDX
[+] Maimai music unlock
parent
25f5f6e1f7
commit
a952674df7
|
@ -1,59 +0,0 @@
|
||||||
package icu.samnyan.aqua.sega.maimai2.handler.impl;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserItemRepo;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.handler.BaseHandler;
|
|
||||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.UserItem;
|
|
||||||
import icu.samnyan.aqua.sega.util.jackson.BasicMapper;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author samnyan (privateamusement@protonmail.com)
|
|
||||||
*/
|
|
||||||
@Component("Maimai2GetUserItemHandler")
|
|
||||||
public class GetUserItemHandler implements BaseHandler {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GetUserItemHandler.class);
|
|
||||||
|
|
||||||
private final BasicMapper mapper;
|
|
||||||
|
|
||||||
private final Mai2UserItemRepo userItemRepository;
|
|
||||||
|
|
||||||
public GetUserItemHandler(BasicMapper mapper, Mai2UserItemRepo userItemRepository) {
|
|
||||||
this.mapper = mapper;
|
|
||||||
this.userItemRepository = userItemRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String handle(Map<String, Object> request) throws JsonProcessingException {
|
|
||||||
long userId = ((Number) request.get("userId")).longValue();
|
|
||||||
long nextIndexVal = ((Number) request.get("nextIndex")).longValue();
|
|
||||||
int maxCount = ((Number) request.get("maxCount")).intValue();
|
|
||||||
|
|
||||||
long mul = 10000000000L;
|
|
||||||
|
|
||||||
int kind = (int) (nextIndexVal / mul);
|
|
||||||
int nextIndex = (int) (nextIndexVal % mul);
|
|
||||||
int pageNum = nextIndex / maxCount;
|
|
||||||
|
|
||||||
Page<UserItem> dbPage = userItemRepository.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount));
|
|
||||||
|
|
||||||
long currentIndex = kind * mul + maxCount * pageNum + dbPage.getNumberOfElements();
|
|
||||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
|
||||||
resultMap.put("userId", userId);
|
|
||||||
resultMap.put("nextIndex", dbPage.getNumberOfElements() < maxCount ? 0 : currentIndex);
|
|
||||||
resultMap.put("itemKind", kind);
|
|
||||||
resultMap.put("userItemList", dbPage.getContent());
|
|
||||||
|
|
||||||
String json = mapper.write(resultMap);
|
|
||||||
logger.info("Response: " + json);
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package icu.samnyan.aqua.sega.maimai2.handler.impl
|
||||||
|
|
||||||
|
import ext.JSON
|
||||||
|
import icu.samnyan.aqua.net.games.Maimai2
|
||||||
|
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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author samnyan (privateamusement@protonmail.com)
|
||||||
|
*/
|
||||||
|
@Component("Maimai2GetUserItemHandler")
|
||||||
|
class GetUserItemHandler(
|
||||||
|
val repos: Mai2Repos,
|
||||||
|
val maimai2: Maimai2
|
||||||
|
) : BaseHandler {
|
||||||
|
val musicUnlock = (5..8).associateWith { kind ->
|
||||||
|
JSON.encodeToString(maimai2.musicMapping.mapKeys { UserItem().apply {
|
||||||
|
itemKind = kind
|
||||||
|
itemId = it.key
|
||||||
|
stock = 1
|
||||||
|
} }) }
|
||||||
|
|
||||||
|
override fun handle(request: Map<String, Any>): Any {
|
||||||
|
val userId = request["userId"] as Long
|
||||||
|
val nextIndexVal = request["nextIndex"] as Long
|
||||||
|
val maxCount = request["maxCount"] as Int
|
||||||
|
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
val dbPage = repos.userItem.findByUser_Card_ExtIdAndItemKind(userId, kind, PageRequest.of(pageNum, maxCount))
|
||||||
|
|
||||||
|
val currentIndex = kind * MULT + maxCount * pageNum + dbPage.numberOfElements
|
||||||
|
val result = mapOf(
|
||||||
|
"userId" to userId,
|
||||||
|
"nextIndex" to if (dbPage.numberOfElements < maxCount) 0 else currentIndex,
|
||||||
|
"itemKind" to kind,
|
||||||
|
"userItemList" to dbPage.content
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info("Response: ${dbPage.numberOfElements} items")
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val logger: Logger = LoggerFactory.getLogger(GetUserItemHandler::class.java)
|
||||||
|
const val MULT = 10000000000L
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,4 +39,16 @@ public class UserItem implements Serializable {
|
||||||
public UserItem(UserDetail user) {
|
public UserItem(UserDetail user) {
|
||||||
this.user = user;
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue