[O] Use global db

This commit is contained in:
Azalea 2025-10-25 07:54:20 +08:00
parent c7a5458f11
commit 619caec2ff
20 changed files with 228 additions and 324 deletions

View File

@ -27,6 +27,7 @@ class DivaGameRepos(
@Component
class DivaRepos(
val g: DivaGameRepos,
val s: DivaServices,
val gameSession: GameSessionRepository,
val playLog: PlayLogRepository,
val contest: PlayerContestRepository,

View File

@ -0,0 +1,63 @@
package icu.samnyan.aqua.sega.diva
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerCustomize
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerModule
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import org.apache.commons.lang3.StringUtils
import org.springframework.stereotype.Component
import org.springframework.stereotype.Service
import java.math.BigInteger
import java.util.*
@Component
class DivaServices(
val profile: PlayerProfileService,
val module: PlayerModuleService,
val customize: PlayerCustomizeService
)
@Service
class PlayerModuleService(val repo: PlayerModuleRepository) {
fun buy(profile: PlayerProfile, moduleId: Int) = repo.save(PlayerModule(profile, moduleId))
fun getModuleHaveString(profile: PlayerProfile): String {
val moduleList = repo.findByPdId(profile)
var module_have = BigInteger("0")
for (module in moduleList) {
module_have = module_have.or(BigInteger.valueOf(1).shiftLeft(module.moduleId))
}
println(module_have.toString(2))
return StringUtils.leftPad(module_have.toString(16), 250, "0").uppercase(Locale.getDefault())
}
}
@Service
class PlayerProfileService(val repo: PlayerProfileRepository) {
fun findByPdId(pdId: Long): Optional<PlayerProfile> = repo.findByPdId(pdId)
fun register(request: RegistrationRequest): PlayerProfile {
val profile = PlayerProfile()
profile.pdId = request.aime_id
profile.playerName = request.player_name
return repo.save(profile)
}
fun save(profile: PlayerProfile) = repo.save(profile)
}
@Service
class PlayerCustomizeService(val repo: PlayerCustomizeRepository) {
fun buy(profile: PlayerProfile, customizeId: Int) = repo.save(PlayerCustomize(profile, customizeId))
fun getModuleHaveString(profile: PlayerProfile): String {
val customizeList = repo.findByPdId(profile)
var customize_have = BigInteger("0")
for (customize in customizeList) {
customize_have = customize_have.or(BigInteger.valueOf(1).shiftLeft(customize.customizeId))
}
return StringUtils.leftPad(customize_have.toString(16), 250, "0")
}
}

View File

@ -3,7 +3,7 @@ package icu.samnyan.aqua.sega.diva.handler.card
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest
import icu.samnyan.aqua.sega.diva.model.response.card.RegistrationResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.PlayerProfileService
import org.springframework.stereotype.Component
/**

View File

@ -1,6 +1,6 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.ContestRepository
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.gamedata.Contest
import icu.samnyan.aqua.sega.diva.model.request.BaseRequest
import icu.samnyan.aqua.sega.diva.model.response.databank.ContestInfoResponse
@ -14,9 +14,9 @@ import kotlin.math.max
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ContestInfoHandler(private val contestRepository: ContestRepository) {
class ContestInfoHandler(val db: DivaRepos) {
fun handle(request: BaseRequest): Any {
val contestList = contestRepository.findTop8ByEnable(true)
val contestList = db.g.contest.findTop8ByEnable(true)
var ci_str = "***"
if (!contestList.isEmpty()) {
val sb = StringBuilder()

View File

@ -1,6 +1,7 @@
package icu.samnyan.aqua.sega.diva.handler.databank
import icu.samnyan.aqua.sega.diva.PlayerPvRecordRepository
import ext.csv
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
import icu.samnyan.aqua.sega.diva.model.common.Edition
import icu.samnyan.aqua.sega.diva.model.common.collection.PsRankingCollection
@ -10,13 +11,12 @@ import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.*
import java.util.stream.Collectors
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepository) {
class PsRankingHandler(val db: DivaRepos) {
fun handle(request: PsRankingRequest): Any {
var edition = Edition.ORIGINAL
var difficulty = Difficulty.HARD
@ -33,7 +33,7 @@ class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepos
val list = request.rnk_ps_pv_id_lst
val resultCollections: MutableMap<Int?, PsRankingCollection?> = LinkedHashMap<Int?, PsRankingCollection?>()
for (i in list) {
val records = playerPvRecordRepository.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(
val records = db.pvRecord.findTop3ByPvIdAndEditionAndDifficultyOrderByMaxScoreDesc(
i,
edition,
difficulty
@ -84,16 +84,16 @@ class PsRankingHandler(private val playerPvRecordRepository: PlayerPvRecordRepos
LocalDateTime.now(),
LocalDateTime.now(),
request.rnk_ps_idx,
pvIds.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition1.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition2.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
edition3.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score1.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score2.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
score3.stream().map<String?> { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")),
name1.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(",")),
name2.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(",")),
name3.stream().map<String?> { obj: String? -> obj.toString() }.collect(Collectors.joining(","))
pvIds.csv,
edition1.csv,
edition2.csv,
edition3.csv,
score1.csv,
score2.csv,
score3.csv,
name1.csv,
name2.csv,
name3.csv
)
}
}

View File

@ -1,15 +1,12 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.DivaCustomizeRepository
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyCstmzItmRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyCstmzItmResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.springframework.stereotype.Component
import java.util.function.Supplier
@ -17,20 +14,15 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BuyCstmzItmHandler(
private val divaCustomizeRepository: DivaCustomizeRepository,
private val playerProfileService: PlayerProfileService,
private val playerCustomizeService: PlayerCustomizeService,
private val gameSessionRepository: GameSessionRepository
) {
class BuyCstmzItmHandler(val db: DivaRepos) {
fun handle(request: BuyCstmzItmRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow(Supplier { SessionNotFoundException() })
val customizeOptional = divaCustomizeRepository.findById(request.cstmz_itm_id)
val customizeOptional = db.g.customize.findById(request.cstmz_itm_id)
if (customizeOptional.isEmpty) {
return BuyCstmzItmResponse(
@ -39,29 +31,27 @@ class BuyCstmzItmHandler(
"ok",
Result.FAILED
)
} else {
if (session.vp < customizeOptional.get().price) {
return BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
playerCustomizeService.buy(profile, request.cstmz_itm_id)
session.vp = session.vp - customizeOptional.get().price
gameSessionRepository.save<GameSession?>(session)
return BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.cstmz_itm_id,
playerCustomizeService.getModuleHaveString(profile),
session.vp
)
}
}
if (session.vp < customizeOptional.get().price) {
return BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
}
db.s.customize.buy(profile, request.cstmz_itm_id)
session.vp -= customizeOptional.get().price
db.gameSession.save<GameSession?>(session)
return BuyCstmzItmResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.cstmz_itm_id,
db.s.customize.getModuleHaveString(profile),
session.vp
)
}
}

View File

@ -1,15 +1,12 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.DivaModuleRepository
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.BuyModuleRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.BuyModuleResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.springframework.stereotype.Component
import java.util.function.Supplier
@ -17,22 +14,16 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class BuyModuleHandler(
private val divaModuleRepository: DivaModuleRepository,
private val playerProfileService: PlayerProfileService,
private val playerModuleService: PlayerModuleService,
private val gameSessionRepository: GameSessionRepository
) {
class BuyModuleHandler(val db: DivaRepos) {
fun handle(request: BuyModuleRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
val moduleOptional = divaModuleRepository.findById(request.mdl_id)
val moduleOptional = db.g.module.findById(request.mdl_id)
val response: BuyModuleResponse?
if (moduleOptional.isEmpty) {
return BuyModuleResponse(
request.cmd,
@ -40,29 +31,27 @@ class BuyModuleHandler(
"ok",
Result.FAILED
)
} else {
if (session.vp < moduleOptional.get().price) {
return BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
} else {
playerModuleService.buy(profile, request.mdl_id)
session.vp = session.vp - moduleOptional.get().price
gameSessionRepository.save<GameSession?>(session)
return BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.mdl_id,
playerModuleService.getModuleHaveString(profile),
session.vp
)
}
}
if (session.vp < moduleOptional.get().price) {
return BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.FAILED
)
}
db.s.module.buy(profile, request.mdl_id)
session.vp -= moduleOptional.get().price
db.gameSession.save<GameSession?>(session)
return BuyModuleResponse(
request.cmd,
request.req_id,
"ok",
Result.SUCCESS,
request.mdl_id,
db.s.module.getModuleHaveString(profile),
session.vp
)
}
}

View File

@ -1,14 +1,12 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.PlayerPvCustomizeRepository
import icu.samnyan.aqua.sega.diva.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
import icu.samnyan.aqua.sega.diva.model.common.Edition
import icu.samnyan.aqua.sega.diva.model.request.ingame.GetPvPdRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.GetPvPdResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaDateTimeUtil
import icu.samnyan.aqua.sega.diva.util.URIEncoder.encode
import org.springframework.stereotype.Component
@ -19,13 +17,9 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class GetPvPdHandler(
private val pvRecordRepository: PlayerPvRecordRepository,
private val pvCustomizeRepository: PlayerPvCustomizeRepository,
private val playerProfileService: PlayerProfileService
) {
class GetPvPdHandler(val db: DivaRepos) {
fun handle(request: GetPvPdRequest): Any {
val profileO = playerProfileService.findByPdId(request.pd_id)
val profileO = db.profile.findByPdId(request.pd_id)
val pd = StringBuilder()
for (pvId in request.pd_pv_id_lst) {
@ -40,7 +34,7 @@ class GetPvPdHandler(
val difficulty = Difficulty.fromValue(diff)
// Myself
val edition0 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
val edition0 = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
pvId,
Edition.ORIGINAL,
@ -48,7 +42,7 @@ class GetPvPdHandler(
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
val edition1 = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
val edition1 = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
pvId,
Edition.EXTRA,
@ -60,7 +54,7 @@ class GetPvPdHandler(
val rivalEdition0: PlayerPvRecord?
val rivalEdition1: PlayerPvRecord?
if (profile.rivalPdId != -1L) {
rivalEdition0 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
rivalEdition0 = db.pvRecord.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
profile.rivalPdId,
pvId,
Edition.ORIGINAL,
@ -68,7 +62,7 @@ class GetPvPdHandler(
)
.orElseGet(Supplier { PlayerPvRecord(pvId, Edition.ORIGINAL) })
rivalEdition1 = pvRecordRepository.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
rivalEdition1 = db.pvRecord.findByPdId_PdIdAndPvIdAndEditionAndDifficulty(
profile.rivalPdId,
pvId,
Edition.EXTRA,
@ -80,7 +74,7 @@ class GetPvPdHandler(
rivalEdition1 = PlayerPvRecord(pvId, Edition.EXTRA)
}
val customize = pvCustomizeRepository.findByPdIdAndPvId(profile, pvId)
val customize = db.pvCustomize.findByPdIdAndPvId(profile, pvId)
.orElseGet(Supplier { PlayerPvCustomize(profile, pvId) })
val str = getString(
@ -89,7 +83,6 @@ class GetPvPdHandler(
rivalEdition0,
profile.rivalPdId
) + "," + getString(edition1, customize, rivalEdition1, profile.rivalPdId)
// logger.info(str);
pd.append(encode(str)).append(",")
}
}
@ -132,7 +125,7 @@ class GetPvPdHandler(
rivalRecord.maxScore + "," +
rivalRecord.maxAttain + "," +
"-1,-1," +
pvRecordRepository.rankByPvIdAndPdIdAndEditionAndDifficulty(
db.pvRecord.rankByPvIdAndPdIdAndEditionAndDifficulty(
record.pvId,
record.pdId,
record.edition,

View File

@ -1,13 +1,12 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import ext.csv
import icu.samnyan.aqua.sega.diva.PlayerPvCustomizeRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.Result
import icu.samnyan.aqua.sega.diva.model.request.ingame.ShopExitRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.ShopExitResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvCustomize
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import org.springframework.stereotype.Component
import java.util.function.Supplier
@ -15,14 +14,11 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class ShopExitHandler(
private val playerProfileService: PlayerProfileService,
private val pvCustomizeRepository: PlayerPvCustomizeRepository
) {
class ShopExitHandler(val db: DivaRepos) {
fun handle(request: ShopExitRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val customize = pvCustomizeRepository.findByPdIdAndPvId(profile, request.ply_pv_id)
val customize = db.pvCustomize.findByPdIdAndPvId(profile, request.ply_pv_id)
.orElseGet(Supplier { PlayerPvCustomize(profile, request.ply_pv_id) })
if (request.use_pv_mdl_eqp == 1) {
@ -39,8 +35,8 @@ class ShopExitHandler(
profile.commonCustomizeItems = request.c_itm_eqp_cmn_ary.csv
profile.moduleSelectItemFlag = request.ms_itm_flg_cmn_ary.csv
playerProfileService.save(profile)
pvCustomizeRepository.save<PlayerPvCustomize?>(customize)
db.profile.save(profile)
db.pvCustomize.save(customize)
return ShopExitResponse(
request.cmd,
request.req_id,

View File

@ -1,21 +1,14 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import ext.logger
import icu.samnyan.aqua.sega.diva.ContestRepository
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.PlayLogRepository
import icu.samnyan.aqua.sega.diva.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.PlayerCustomizeRepository
import icu.samnyan.aqua.sega.diva.PlayerInventoryRepository
import icu.samnyan.aqua.sega.diva.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.*
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest
import icu.samnyan.aqua.sega.diva.model.response.ingame.StageResultResponse
import icu.samnyan.aqua.sega.diva.model.userdata.*
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaCalculator
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.apache.commons.lang3.StringUtils
import org.springframework.stereotype.Component
import java.lang.String
@ -33,26 +26,16 @@ import kotlin.math.max
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StageResultHandler(
private val gameSessionRepository: GameSessionRepository,
private val pvRecordRepository: PlayerPvRecordRepository,
private val playerProfileService: PlayerProfileService,
private val playLogRepository: PlayLogRepository,
private val contestRepository: ContestRepository,
private val playerContestRepository: PlayerContestRepository,
private val playerCustomizeRepository: PlayerCustomizeRepository,
private val playerInventoryRepository: PlayerInventoryRepository,
private val divaCalculator: DivaCalculator
) {
class StageResultHandler(val db: DivaRepos, val calc: DivaCalculator) {
private var currentProfile: PlayerProfile? = null
val logger = logger()
fun handle(request: StageResultRequest): Any {
val response: StageResultResponse?
if (request.getPd_id() != -1L) {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
currentProfile = profile
@ -77,7 +60,7 @@ class StageResultHandler(
val log = getLog(request, profile, stageIndex)
logger.debug("Stage Result Object: {}", log.toString())
val record = pvRecordRepository.findByPdIdAndPvIdAndEditionAndDifficulty(
val record = db.pvRecord.findByPdIdAndPvIdAndEditionAndDifficulty(
profile,
log.pvId,
log.edition,
@ -114,7 +97,7 @@ class StageResultHandler(
session.lastPvId = log.pvId
session.lastUpdateTime = LocalDateTime.now()
val levelInfo = divaCalculator.getLevelInfo(profile)
val levelInfo = calc.getLevelInfo(profile)
session.oldLevelNumber = session.levelNumber
session.oldLevelExp = session.levelExp
session.levelNumber = levelInfo.levelNumber
@ -139,10 +122,10 @@ class StageResultHandler(
contestSpecifier = getContestSpecifier(progress)
// Check if the contest info exist
val contestOptional = contestRepository.findById(contestId)
val contestOptional = db.g.contest.findById(contestId)
if (contestOptional.isPresent) {
val contest = contestOptional.get()
val playerContestOptional = playerContestRepository.findByPdIdAndContestId(profile, contestId)
val playerContestOptional = db.contest.findByPdIdAndContestId(profile, contestId)
// Contest Entry Reward
// Check if this is first stage
@ -209,9 +192,9 @@ class StageResultHandler(
}
}
pvRecordRepository.save<PlayerPvRecord?>(record)
playLogRepository.save<PlayLog?>(log)
gameSessionRepository.save<GameSession?>(session)
db.pvRecord.save<PlayerPvRecord?>(record)
db.playLog.save<PlayLog?>(log)
db.gameSession.save<GameSession?>(session)
return StageResultResponse(
@ -368,7 +351,7 @@ class StageResultHandler(
borders: Int,
reward: kotlin.String?
): MutableMap<kotlin.String?, kotlin.String?>? {
if (currentValue > borders && previousValue < borders) {
if (borders in (previousValue + 1)..<currentValue) {
if (StringUtils.isNotBlank(reward)) {
val rewardValue: Array<kotlin.String?> =
reward!!.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
@ -383,7 +366,7 @@ class StageResultHandler(
}
"1" -> {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile!!, "SKIN", rewardValue[1]!!)
if (db.inventory.findByPdIdAndTypeAndValue(currentProfile!!, "SKIN", rewardValue[1]!!)
.isPresent
) {
result["type"] = "-1"
@ -391,7 +374,7 @@ class StageResultHandler(
result["string1"] = "***"
result["string2"] = "***"
} else {
playerInventoryRepository.save<PlayerInventory?>(
db.inventory.save<PlayerInventory?>(
PlayerInventory(
null,
currentProfile,
@ -407,7 +390,7 @@ class StageResultHandler(
}
"2" -> {
if (playerInventoryRepository.findByPdIdAndTypeAndValue(currentProfile!!, "PLATE", rewardValue[1]!!)
if (db.inventory.findByPdIdAndTypeAndValue(currentProfile!!, "PLATE", rewardValue[1]!!)
.isPresent
) {
result.put("type", "-1")
@ -415,7 +398,7 @@ class StageResultHandler(
result.put("string1", "***")
result.put("string2", "***")
} else {
playerInventoryRepository.save<PlayerInventory?>(
db.inventory.save<PlayerInventory?>(
PlayerInventory(
null,
currentProfile,
@ -431,7 +414,7 @@ class StageResultHandler(
}
"3" -> {
if (playerCustomizeRepository.findByPdIdAndCustomizeId(currentProfile!!, rewardValue[1]!!.toInt())
if (db.customize.findByPdIdAndCustomizeId(currentProfile!!, rewardValue[1]!!.toInt())
.isPresent
) {
result.put("type", "-1")
@ -439,7 +422,7 @@ class StageResultHandler(
result.put("string1", "***")
result.put("string2", "***")
} else {
playerCustomizeRepository.save(
db.customize.save(
PlayerCustomize(
currentProfile,
rewardValue[1]!!.toInt()

View File

@ -1,12 +1,11 @@
package icu.samnyan.aqua.sega.diva.handler.ingame
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageStartRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.springframework.stereotype.Component
import java.util.function.Supplier
@ -14,15 +13,12 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StageStartHandler(
private val gameSessionRepository: GameSessionRepository,
private val playerProfileService: PlayerProfileService
) {
class StageStartHandler(val db: DivaRepos) {
fun handle(request: StageStartRequest): Any {
if (request.getPd_id() != -1L) {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
val stageArr = request.getStg_ply_pv_id()
@ -40,7 +36,7 @@ class StageStartHandler(
stageIndex = 3
}
session.stageIndex = stageIndex
gameSessionRepository.save<GameSession?>(session)
db.gameSession.save<GameSession?>(session)
}
return BaseResponse(

View File

@ -2,12 +2,11 @@ package icu.samnyan.aqua.sega.diva.handler.ingame
import ext.csv
import ext.logger
import icu.samnyan.aqua.sega.diva.PlayerScreenShotRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.request.ingame.StoreSsRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerScreenShot
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import org.springframework.stereotype.Component
import org.springframework.web.multipart.MultipartFile
import java.io.IOException
@ -21,13 +20,10 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class StoreSsHandler(
private val playerProfileService: PlayerProfileService,
private val screenShotRepository: PlayerScreenShotRepository
) {
class StoreSsHandler(val db: DivaRepos) {
val logger = logger()
fun handle(request: StoreSsRequest, file: MultipartFile): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
var response: BaseResponse?
@ -43,7 +39,7 @@ class StoreSsHandler(
request.ss_mdl_id.csv,
request.ss_c_itm_id.csv
)
screenShotRepository.save<PlayerScreenShot?>(ss)
db.screenShot.save<PlayerScreenShot?>(ss)
return BaseResponse(
request.cmd,

View File

@ -1,10 +1,6 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.ContestRepository
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.ContestBorder
import icu.samnyan.aqua.sega.diva.model.common.Difficulty
import icu.samnyan.aqua.sega.diva.model.common.Edition
@ -13,8 +9,9 @@ import icu.samnyan.aqua.sega.diva.model.gamedata.Contest
import icu.samnyan.aqua.sega.diva.model.request.ingame.StageResultRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.DivaStringUtils
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.springframework.stereotype.Component
import java.lang.String
import java.time.LocalDateTime
@ -27,16 +24,11 @@ import kotlin.math.max
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class EndHandler(
private val contestRepository: ContestRepository,
private val playerProfileService: PlayerProfileService,
private val playerContestRepository: PlayerContestRepository,
private val gameSessionRepository: GameSessionRepository
) {
class EndHandler(val db: DivaRepos) {
fun handle(request: StageResultRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
@ -53,7 +45,7 @@ class EndHandler(
profile.sortMode = SortMode.fromValue(request.getSort_kind())
if (request.getCr_cid() != -1) {
val contest = contestRepository.findById(request.getCr_cid()).orElseGet(Supplier { Contest() })
val contest = db.g.contest.findById(request.getCr_cid()).orElseGet(Supplier { Contest() })
val currentResultRank = getContestRank(contest, request.getCr_tv())
if (request.getCr_if() == 0) {
// Do contest is playing
@ -64,7 +56,7 @@ class EndHandler(
profile.contestNowPlayingSpecifier = String.join(",", *request.getCr_sp())
} else {
val contestRecord =
playerContestRepository.findByPdIdAndContestId(profile, request.getCr_cid()).orElseGet(
db.contest.findByPdIdAndContestId(profile, request.getCr_cid()).orElseGet(
Supplier { PlayerContest(profile, request.getCr_cid()) })
contestRecord.startCount += 1
contestRecord.bestValue = max(contestRecord.bestValue, request.getCr_tv())
@ -73,7 +65,7 @@ class EndHandler(
) currentResultRank else contestRecord.resultRank
contestRecord.lastUpdateTime = LocalDateTime.now()
playerContestRepository.save<PlayerContest?>(contestRecord)
db.contest.save<PlayerContest?>(contestRecord)
profile.isContestNowPlayingEnable = false
profile.contestNowPlayingId = -1
profile.contestNowPlayingResultRank = ContestBorder.NONE
@ -82,9 +74,8 @@ class EndHandler(
}
}
playerProfileService.save(profile)
gameSessionRepository.delete(session)
db.profile.save(profile)
db.gameSession.delete(session)
return BaseResponse(
request.cmd,

View File

@ -1,29 +1,22 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.request.user.PdUnlockRequest
import icu.samnyan.aqua.sega.diva.model.response.BaseResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
import org.springframework.stereotype.Component
import java.util.function.Supplier
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PdUnlockHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) {
class PdUnlockHandler(val db: DivaRepos) {
fun handle(request: PdUnlockRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow<SessionNotFoundException?>(Supplier { SessionNotFoundException() })
gameSessionRepository.delete(session)
db.gameSession.delete(session)
return BaseResponse(
request.cmd,

View File

@ -1,13 +1,12 @@
package icu.samnyan.aqua.sega.diva.handler.user
import ext.logger
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.model.common.PreStartResult
import icu.samnyan.aqua.sega.diva.model.common.StartMode
import icu.samnyan.aqua.sega.diva.model.request.user.PreStartRequest
import icu.samnyan.aqua.sega.diva.model.response.user.PreStartResponse
import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import org.springframework.stereotype.Component
import java.time.LocalDateTime
import java.util.concurrent.ThreadLocalRandom
@ -16,13 +15,10 @@ import java.util.concurrent.ThreadLocalRandom
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class PreStartHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository
) {
class PreStartHandler(val db: DivaRepos) {
var logger = logger()
fun handle(request: PreStartRequest): Any {
val profileOptional = playerProfileService.findByPdId(request.aime_id)
val profileOptional = db.profile.findByPdId(request.aime_id)
if (profileOptional.isEmpty) {
return PreStartResponse(
request.cmd,
@ -33,7 +29,7 @@ class PreStartHandler(
} else {
val profile = profileOptional.get()
val sessionOptional = gameSessionRepository.findByPdId(profile)
val sessionOptional = db.gameSession.findByPdId(profile)
if (sessionOptional.isPresent) {
val session = sessionOptional.get()
if (!session.lastUpdateTime
@ -46,7 +42,7 @@ class PreStartHandler(
PreStartResult.ALREADY_PLAYING
)
} else {
gameSessionRepository.delete(session)
db.gameSession.delete(session)
}
}
@ -66,7 +62,7 @@ class PreStartHandler(
profile.vocaloidPoints
)
gameSessionRepository.save(session)
db.gameSession.save(session)
return PreStartResponse(
request.cmd,

View File

@ -1,9 +1,10 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.model.request.user.SpendCreditRequest
import icu.samnyan.aqua.sega.diva.model.response.user.SpendCreditResponse
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.PlayerProfileService
import org.springframework.stereotype.Component
import java.util.function.Supplier
@ -11,9 +12,9 @@ import java.util.function.Supplier
* @author samnyan (privateamusement@protonmail.com)
*/
@Component
class SpendCreditHandler(private val playerProfileService: PlayerProfileService) {
class SpendCreditHandler(val db: DivaRepos) {
fun handle(request: SpendCreditRequest): Any {
val profile = playerProfileService.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
val profile = db.profile.findByPdId(request.pd_id).orElseThrow<ProfileNotFoundException?>(
Supplier { ProfileNotFoundException() })
return SpendCreditResponse(

View File

@ -1,10 +1,10 @@
package icu.samnyan.aqua.sega.diva.handler.user
import icu.samnyan.aqua.sega.diva.GameSessionRepository
import icu.samnyan.aqua.sega.diva.PlayerContestRepository
import icu.samnyan.aqua.sega.diva.PlayerPvRecordRepository
import icu.samnyan.aqua.sega.diva.DivaRepos
import icu.samnyan.aqua.sega.diva.PlayerCustomizeService
import icu.samnyan.aqua.sega.diva.PlayerModuleService
import icu.samnyan.aqua.sega.diva.PlayerProfileService
import icu.samnyan.aqua.sega.diva.model.common.*
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearSet
import icu.samnyan.aqua.sega.diva.model.common.collection.ClearTally
import icu.samnyan.aqua.sega.diva.model.request.user.StartRequest
import icu.samnyan.aqua.sega.diva.model.response.user.StartResponse
@ -12,9 +12,6 @@ import icu.samnyan.aqua.sega.diva.model.userdata.GameSession
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerContest
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerPvRecord
import icu.samnyan.aqua.sega.diva.service.PlayerCustomizeService
import icu.samnyan.aqua.sega.diva.service.PlayerModuleService
import icu.samnyan.aqua.sega.diva.service.PlayerProfileService
import icu.samnyan.aqua.sega.diva.util.ProfileNotFoundException
import icu.samnyan.aqua.sega.diva.util.PvRecordDataException
import icu.samnyan.aqua.sega.diva.util.SessionNotFoundException
@ -31,20 +28,18 @@ import java.util.stream.Collectors
@Component
class StartHandler(
private val playerProfileService: PlayerProfileService,
private val gameSessionRepository: GameSessionRepository,
private val playerCustomizeService: PlayerCustomizeService,
private val playerModuleService: PlayerModuleService,
private val playerPvRecordRepository: PlayerPvRecordRepository,
private val playerContestRepository: PlayerContestRepository
val db: DivaRepos
) {
fun handle(request: StartRequest): Any {
val profile = playerProfileService.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException>(
val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow<ProfileNotFoundException>(
Supplier { ProfileNotFoundException() })
val session = gameSessionRepository.findByPdId(profile)
val session = db.gameSession.findByPdId(profile)
.orElseThrow(Supplier { SessionNotFoundException() })
session.startMode = StartMode.START
gameSessionRepository.save<GameSession>(session)
db.gameSession.save<GameSession>(session)
val module_have = playerModuleService.getModuleHaveString(profile)
val customize_have = playerCustomizeService.getModuleHaveString(profile)
@ -121,7 +116,7 @@ class StartHandler(
}
private fun countClearStatus(profile: PlayerProfile): String {
val pvRecordList = playerPvRecordRepository.findByPdId(profile)
val pvRecordList = db.pvRecord.findByPdId(profile)
val clearTally = ClearTally()
pvRecordList.forEach(Consumer { x: PlayerPvRecord ->
when (x.edition) {
@ -151,14 +146,12 @@ class StartHandler(
return clearTally.toInternal()
}
private fun getDiff(record: PlayerPvRecord, clearTally: ClearTally): ClearSet {
when (record.difficulty) {
Difficulty.EASY -> return clearTally.easy
Difficulty.NORMAL -> return clearTally.normal
Difficulty.HARD -> return clearTally.hard
Difficulty.EXTREME -> return clearTally.extreme
else -> throw PvRecordDataException("Difficulty data not exist, record id:" + record.id)
}
private fun getDiff(record: PlayerPvRecord, clearTally: ClearTally) = when (record.difficulty) {
Difficulty.EASY -> clearTally.easy
Difficulty.NORMAL -> clearTally.normal
Difficulty.HARD -> clearTally.hard
Difficulty.EXTREME -> clearTally.extreme
else -> throw PvRecordDataException("Difficulty data not exist, record id:" + record.id)
}
private fun getContestResult(profile: PlayerProfile): MutableMap<String, String> {
@ -167,7 +160,7 @@ class StartHandler(
val cv_rr: MutableList<Int> = LinkedList<Int>()
val cv_bv: MutableList<Int> = LinkedList<Int>()
val cv_bf: MutableList<Int> = LinkedList<Int>()
val contestList = playerContestRepository.findTop4ByPdIdOrderByLastUpdateTimeDesc(profile)
val contestList = db.contest.findTop4ByPdIdOrderByLastUpdateTimeDesc(profile)
contestList.forEach(Consumer { x: PlayerContest ->
cv_cid.add(x.contestId)
cv_sc.add(x.startCount)

View File

@ -1,25 +0,0 @@
package icu.samnyan.aqua.sega.diva.service
import icu.samnyan.aqua.sega.diva.PlayerCustomizeRepository
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerCustomize
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import org.apache.commons.lang3.StringUtils
import org.springframework.stereotype.Service
import java.math.BigInteger
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Service
class PlayerCustomizeService(val repo: PlayerCustomizeRepository) {
fun buy(profile: PlayerProfile, customizeId: Int) = repo.save(PlayerCustomize(profile, customizeId))
fun getModuleHaveString(profile: PlayerProfile): String {
val customizeList = repo.findByPdId(profile)
var customize_have = BigInteger("0")
for (customize in customizeList) {
customize_have = customize_have.or(BigInteger.valueOf(1).shiftLeft(customize.customizeId))
}
return StringUtils.leftPad(customize_have.toString(16), 250, "0")
}
}

View File

@ -1,27 +0,0 @@
package icu.samnyan.aqua.sega.diva.service
import icu.samnyan.aqua.sega.diva.PlayerModuleRepository
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerModule
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import org.apache.commons.lang3.StringUtils
import org.springframework.stereotype.Service
import java.math.BigInteger
import java.util.*
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Service
class PlayerModuleService(val repo: PlayerModuleRepository) {
fun buy(profile: PlayerProfile, moduleId: Int) = repo.save(PlayerModule(profile, moduleId))
fun getModuleHaveString(profile: PlayerProfile): String {
val moduleList = repo.findByPdId(profile)
var module_have = BigInteger("0")
for (module in moduleList) {
module_have = module_have.or(BigInteger.valueOf(1).shiftLeft(module.moduleId))
}
println(module_have.toString(2))
return StringUtils.leftPad(module_have.toString(16), 250, "0").uppercase(Locale.getDefault())
}
}

View File

@ -1,25 +0,0 @@
package icu.samnyan.aqua.sega.diva.service
import icu.samnyan.aqua.sega.diva.PlayerProfileRepository
import icu.samnyan.aqua.sega.diva.model.request.card.RegistrationRequest
import icu.samnyan.aqua.sega.diva.model.userdata.PlayerProfile
import org.springframework.stereotype.Service
import java.util.*
/**
* @author samnyan (privateamusement@protonmail.com)
*/
@Service
class PlayerProfileService(val repo: PlayerProfileRepository) {
fun findByPdId(pdId: Long): Optional<PlayerProfile> = repo.findByPdId(pdId)
fun register(request: RegistrationRequest): PlayerProfile {
val profile = PlayerProfile()
profile.pdId = request.aime_id
profile.playerName = request.player_name
return repo.save(profile)
}
fun save(profile: PlayerProfile) = repo.save(profile)
}