mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-07 02:37:26 +08:00
[RF] Re-organize game options
This commit is contained in:
@@ -35,8 +35,10 @@ import java.util.concurrent.locks.Lock
|
||||
import kotlin.reflect.KCallable
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KMutableProperty1
|
||||
import kotlin.reflect.full.declaredMemberProperties
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.jvm.javaField
|
||||
import kotlin.reflect.jvm.jvmErasure
|
||||
|
||||
typealias RP = RequestParam
|
||||
@@ -81,7 +83,7 @@ annotation class SettingField(
|
||||
|
||||
// Reflection
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun <T : Any> KClass<T>.vars() = memberProperties.mapNotNull { it as? Var<T, Any> }
|
||||
fun <T : Any> KClass<T>.vars() = declaredMemberProperties.sortedBy { it.javaField?.declaringClass?.declaredFields?.indexOf(it.javaField) ?: Int.MAX_VALUE }.mapNotNull { it as? Var<T, Any> }
|
||||
fun <T : Any> KClass<T>.varsMap() = vars().associateBy { it.name }
|
||||
fun <T : Any> KClass<T>.getters() = java.methods.filter { it.name.startsWith("get") }
|
||||
fun <T : Any> KClass<T>.gettersMap() = getters().associateBy { it.name.removePrefix("get").firstCharLower() }
|
||||
|
||||
@@ -2,10 +2,7 @@ package icu.samnyan.aqua.net.db
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import ext.SettingField
|
||||
import jakarta.persistence.Entity
|
||||
import jakarta.persistence.GeneratedValue
|
||||
import jakarta.persistence.GenerationType
|
||||
import jakarta.persistence.Id
|
||||
import jakarta.persistence.*
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
@Entity
|
||||
@@ -14,21 +11,29 @@ class AquaGameOptions(
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
var id: Long = 0,
|
||||
|
||||
@SettingField("general")
|
||||
var unlockMusic: Boolean = false,
|
||||
|
||||
@SettingField("general")
|
||||
var unlockChara: Boolean = false,
|
||||
|
||||
@SettingField("general")
|
||||
var unlockCollectables: Boolean = false,
|
||||
|
||||
@SettingField("general")
|
||||
var unlockTickets: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_music")
|
||||
var mai2UnlockMusic: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_chara")
|
||||
var mai2UnlockChara: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_chara_max_level")
|
||||
var mai2UnlockCharaMaxLevel: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_partners")
|
||||
var mai2UnlockPartners: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_collectables")
|
||||
var mai2UnlockCollectables: Boolean = false,
|
||||
@SettingField("mai2") @Column(name = "mai2_unlock_tickets")
|
||||
var mai2UnlockTickets: Boolean = false,
|
||||
|
||||
@SettingField("wacca")
|
||||
var waccaUnlockMusic: Boolean = false,
|
||||
@SettingField("wacca")
|
||||
var waccaUnlockPlates: Boolean = false,
|
||||
@SettingField("wacca")
|
||||
var waccaUnlockCollectables: Boolean = false,
|
||||
@SettingField("wacca")
|
||||
var waccaUnlockTickets: Boolean = false,
|
||||
@SettingField("wacca")
|
||||
var waccaInfiniteWp: Boolean = false,
|
||||
|
||||
@SettingField("wacca")
|
||||
var waccaAlwaysVip: Boolean = false,
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package icu.samnyan.aqua.sega.maimai2.handler
|
||||
|
||||
import ext.int
|
||||
import ext.logger
|
||||
import icu.samnyan.aqua.net.games.mai2.Maimai2
|
||||
import icu.samnyan.aqua.sega.general.BaseHandler
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
|
||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2ItemKind
|
||||
import icu.samnyan.aqua.sega.maimai2.model.userdata.Mai2UserCharacter
|
||||
import org.springframework.stereotype.Component
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
@@ -15,34 +17,25 @@ class GetUserCharacterHandler(
|
||||
val maimai2: Maimai2,
|
||||
val cardRepo: CardRepository,
|
||||
) : BaseHandler {
|
||||
val itemUnlock = maimai2.itemMapping[Mai2ItemKind.chara.name]?.map { mapOf(
|
||||
"characterId" to it.key,
|
||||
"level" to 9999,
|
||||
"awakening" to 1,
|
||||
"useCount" to 0
|
||||
) }
|
||||
val charaIds = maimai2.itemMapping[Mai2ItemKind.chara.name]?.map { it.key.int() } ?: emptyList()
|
||||
|
||||
init {
|
||||
if (itemUnlock.isNullOrEmpty()) logger.warn("Mai2 item info is empty")
|
||||
if (charaIds.isEmpty()) logger.warn("Mai2 item info is empty")
|
||||
}
|
||||
|
||||
override fun handle(request: Map<String, Any>): Any {
|
||||
val userId = (request["userId"] as Number).toLong()
|
||||
|
||||
// Aqua Net game unlock feature
|
||||
cardRepo.findByExtId(userId).getOrNull()?.aquaUser?.gameOptions?.let { opt ->
|
||||
if (!opt.unlockChara or itemUnlock.isNullOrEmpty()) return@let
|
||||
|
||||
logger.info("Response: ${itemUnlock!!.size} Characters - All unlock")
|
||||
return mapOf(
|
||||
"userId" to userId,
|
||||
"userCharacterList" to itemUnlock
|
||||
)
|
||||
}
|
||||
val gameOptions = cardRepo.findByExtId(userId).getOrNull()?.aquaUser?.gameOptions
|
||||
val userCharacterList = repos.userCharacter.findByUser_Card_ExtId(userId)
|
||||
.let { if (gameOptions?.mai2UnlockChara != true) it else (
|
||||
charaIds.associateWith { Mai2UserCharacter().apply { characterId = it; level = 1 } } +
|
||||
it.associateBy { it.characterId }
|
||||
).values }
|
||||
.let { if (gameOptions?.mai2UnlockCharaMaxLevel != true) it else it.map { it.apply { level = 9999 } } }
|
||||
|
||||
return mapOf(
|
||||
"userId" to userId,
|
||||
"userCharacterList" to repos.userCharacter.findByUser_Card_ExtId(userId)
|
||||
"userCharacterList" to userCharacterList
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,10 +50,11 @@ class GetUserItemHandler(
|
||||
// Aqua Net game unlock feature
|
||||
cardRepo.findByExtId(userId).getOrNull()?.aquaUser?.gameOptions?.let { opt ->
|
||||
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]
|
||||
(kind in 5..8) && opt.mai2UnlockMusic -> musicUnlock.getValue(kind)
|
||||
(kind in 1..3 || kind == 11) && opt.mai2UnlockCollectables -> itemUnlock[kind]
|
||||
(kind == 12) && opt.mai2UnlockTickets -> itemUnlock[kind]
|
||||
(kind == 9) && opt.mai2UnlockChara -> itemUnlock[kind]
|
||||
(kind == 10) && opt.mai2UnlockPartners -> itemUnlock[kind]
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -205,19 +205,19 @@ fun WaccaServer.init() {
|
||||
val go = u.card?.aquaUser?.gameOptions ?: AquaGameOptions()
|
||||
|
||||
// All unlock
|
||||
if (go.unlockMusic && wacca.musicMapping.isNotEmpty()) {
|
||||
if (go.waccaUnlockMusic && wacca.musicMapping.isNotEmpty()) {
|
||||
items[MUSIC_UNLOCK()] = wacca.musicMapping.map { (id, v) -> MUSIC_UNLOCK(u, id, p1 = v.notes.size.long() - 1) }
|
||||
}
|
||||
if (go.unlockTickets) {
|
||||
if (go.waccaUnlockTickets) {
|
||||
var i = 0
|
||||
items[TICKET()] = enabledTickets.flatMap { (1..5).map { TICKET(u, it).apply { id = (i++).toLong() } } }
|
||||
}
|
||||
if (go.unlockChara) {
|
||||
if (go.waccaUnlockPlates) {
|
||||
wacca.itemMapping["plates"]?.let { items[USER_PLATE()] = it.map { (k, _) -> USER_PLATE(u, k.int()) } }
|
||||
}
|
||||
if (go.unlockCollectables) {
|
||||
if (go.waccaUnlockCollectables) {
|
||||
// TODO: Add titles
|
||||
mapOf("icon" to ICON, "plates" to USER_PLATE, "trophy" to TROPHY).map { (name, type) ->
|
||||
mapOf("icon" to ICON, "trophy" to TROPHY).map { (name, type) ->
|
||||
wacca.itemMapping[name]?.let { items[type()] = it.map { (k, _) -> type(u, k.int()) } }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user