From 619caec2ff5d5ee1c39209461b4c052f1c785986 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sat, 25 Oct 2025 07:54:20 +0800 Subject: [PATCH] [O] Use global db --- .../aqua/sega/diva/{Repos.kt => DivaRepos.kt} | 1 + .../samnyan/aqua/sega/diva/DivaServices.kt | 63 +++++++++++++++++ .../diva/handler/card/RegistrationHandler.kt | 2 +- .../handler/databank/ContestInfoHandler.kt | 6 +- .../diva/handler/databank/PsRankingHandler.kt | 28 ++++---- .../diva/handler/ingame/BuyCstmzItmHandler.kt | 66 ++++++++---------- .../diva/handler/ingame/BuyModuleHandler.kt | 67 ++++++++----------- .../diva/handler/ingame/GetPvPdHandler.kt | 25 +++---- .../diva/handler/ingame/ShopExitHandler.kt | 18 ++--- .../diva/handler/ingame/StageResultHandler.kt | 57 ++++++---------- .../diva/handler/ingame/StageStartHandler.kt | 18 ++--- .../diva/handler/ingame/StoreSsHandler.kt | 14 ++-- .../aqua/sega/diva/handler/user/EndHandler.kt | 31 +++------ .../sega/diva/handler/user/PdUnlockHandler.kt | 17 ++--- .../sega/diva/handler/user/PreStartHandler.kt | 16 ++--- .../diva/handler/user/SpendCreditHandler.kt | 7 +- .../sega/diva/handler/user/StartHandler.kt | 39 +++++------ .../diva/service/PlayerCustomizeService.kt | 25 ------- .../sega/diva/service/PlayerModuleService.kt | 27 -------- .../sega/diva/service/PlayerProfileService.kt | 25 ------- 20 files changed, 228 insertions(+), 324 deletions(-) rename src/main/java/icu/samnyan/aqua/sega/diva/{Repos.kt => DivaRepos.kt} (99%) create mode 100644 src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt delete mode 100644 src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerCustomizeService.kt delete mode 100644 src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerModuleService.kt delete mode 100644 src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerProfileService.kt diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/Repos.kt b/src/main/java/icu/samnyan/aqua/sega/diva/DivaRepos.kt similarity index 99% rename from src/main/java/icu/samnyan/aqua/sega/diva/Repos.kt rename to src/main/java/icu/samnyan/aqua/sega/diva/DivaRepos.kt index a3ea4bf8..7e1121e3 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/Repos.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/DivaRepos.kt @@ -27,6 +27,7 @@ class DivaGameRepos( @Component class DivaRepos( val g: DivaGameRepos, + val s: DivaServices, val gameSession: GameSessionRepository, val playLog: PlayLogRepository, val contest: PlayerContestRepository, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt b/src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt new file mode 100644 index 00000000..b8dac399 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/sega/diva/DivaServices.kt @@ -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 = 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") + } +} \ No newline at end of file diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/card/RegistrationHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/card/RegistrationHandler.kt index c91a2367..6873fa3f 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/card/RegistrationHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/card/RegistrationHandler.kt @@ -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 /** diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/ContestInfoHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/ContestInfoHandler.kt index 4e388641..afa8b8f8 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/ContestInfoHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/ContestInfoHandler.kt @@ -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() diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/PsRankingHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/PsRankingHandler.kt index 7d79b04f..9b9dff89 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/PsRankingHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/databank/PsRankingHandler.kt @@ -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 = LinkedHashMap() 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 { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - edition1.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - edition2.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - edition3.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - score1.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - score2.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - score3.stream().map { obj: Int? -> obj.toString() }.collect(Collectors.joining(",")), - name1.stream().map { obj: String? -> obj.toString() }.collect(Collectors.joining(",")), - name2.stream().map { obj: String? -> obj.toString() }.collect(Collectors.joining(",")), - name3.stream().map { 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 ) } } diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyCstmzItmHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyCstmzItmHandler.kt index 3241fe8c..b33872fc 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyCstmzItmHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyCstmzItmHandler.kt @@ -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(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(session) + + return BuyCstmzItmResponse( + request.cmd, + request.req_id, + "ok", + Result.SUCCESS, + request.cstmz_itm_id, + db.s.customize.getModuleHaveString(profile), + session.vp + ) } } diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyModuleHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyModuleHandler.kt index 548856fd..750eadca 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyModuleHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/BuyModuleHandler.kt @@ -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( + 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 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(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(session) + + return BuyModuleResponse( + request.cmd, + request.req_id, + "ok", + Result.SUCCESS, + request.mdl_id, + db.s.module.getModuleHaveString(profile), + session.vp + ) } } diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/GetPvPdHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/GetPvPdHandler.kt index 0d4bc47c..7484d1f4 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/GetPvPdHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/GetPvPdHandler.kt @@ -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, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/ShopExitHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/ShopExitHandler.kt index 1bf2fb2e..38480083 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/ShopExitHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/ShopExitHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.pd_id).orElseThrow( 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(customize) + db.profile.save(profile) + db.pvCustomize.save(customize) return ShopExitResponse( request.cmd, request.req_id, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageResultHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageResultHandler.kt index 4f8c99ab..7e6d5bad 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageResultHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageResultHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow( Supplier { ProfileNotFoundException() }) - val session = gameSessionRepository.findByPdId(profile) + val session = db.gameSession.findByPdId(profile) .orElseThrow(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(record) - playLogRepository.save(log) - gameSessionRepository.save(session) + db.pvRecord.save(record) + db.playLog.save(log) + db.gameSession.save(session) return StageResultResponse( @@ -368,7 +351,7 @@ class StageResultHandler( borders: Int, reward: kotlin.String? ): MutableMap? { - if (currentValue > borders && previousValue < borders) { + if (borders in (previousValue + 1).. = 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( + db.inventory.save( 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( + db.inventory.save( 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() diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageStartHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageStartHandler.kt index 4f9d4ae9..8dbf7fd2 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageStartHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StageStartHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow( Supplier { ProfileNotFoundException() }) - val session = gameSessionRepository.findByPdId(profile) + val session = db.gameSession.findByPdId(profile) .orElseThrow(Supplier { SessionNotFoundException() }) val stageArr = request.getStg_ply_pv_id() @@ -40,7 +36,7 @@ class StageStartHandler( stageIndex = 3 } session.stageIndex = stageIndex - gameSessionRepository.save(session) + db.gameSession.save(session) } return BaseResponse( diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StoreSsHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StoreSsHandler.kt index e88eaa6d..07788753 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StoreSsHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/ingame/StoreSsHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.pd_id).orElseThrow( Supplier { ProfileNotFoundException() }) var response: BaseResponse? @@ -43,7 +39,7 @@ class StoreSsHandler( request.ss_mdl_id.csv, request.ss_c_itm_id.csv ) - screenShotRepository.save(ss) + db.screenShot.save(ss) return BaseResponse( request.cmd, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/EndHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/EndHandler.kt index a6386cfa..e22458e8 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/EndHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/EndHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow( Supplier { ProfileNotFoundException() }) - val session = gameSessionRepository.findByPdId(profile) + val session = db.gameSession.findByPdId(profile) .orElseThrow(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(contestRecord) + db.contest.save(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, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PdUnlockHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PdUnlockHandler.kt index cdfed69f..89151451 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PdUnlockHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PdUnlockHandler.kt @@ -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( + 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() }) - gameSessionRepository.delete(session) + db.gameSession.delete(session) return BaseResponse( request.cmd, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PreStartHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PreStartHandler.kt index 5cc08cdb..c3875263 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PreStartHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/PreStartHandler.kt @@ -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, diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/SpendCreditHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/SpendCreditHandler.kt index c864cf25..ae1d3a63 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/SpendCreditHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/SpendCreditHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.pd_id).orElseThrow( Supplier { ProfileNotFoundException() }) return SpendCreditResponse( diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/StartHandler.kt b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/StartHandler.kt index c032f07f..80b83f0f 100644 --- a/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/StartHandler.kt +++ b/src/main/java/icu/samnyan/aqua/sega/diva/handler/user/StartHandler.kt @@ -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( + val profile = db.profile.findByPdId(request.getPd_id()).orElseThrow( Supplier { ProfileNotFoundException() }) - val session = gameSessionRepository.findByPdId(profile) + val session = db.gameSession.findByPdId(profile) .orElseThrow(Supplier { SessionNotFoundException() }) session.startMode = StartMode.START - gameSessionRepository.save(session) + db.gameSession.save(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 { @@ -167,7 +160,7 @@ class StartHandler( val cv_rr: MutableList = LinkedList() val cv_bv: MutableList = LinkedList() val cv_bf: MutableList = LinkedList() - 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) diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerCustomizeService.kt b/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerCustomizeService.kt deleted file mode 100644 index 22e4f081..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerCustomizeService.kt +++ /dev/null @@ -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") - } -} diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerModuleService.kt b/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerModuleService.kt deleted file mode 100644 index 4d6c7f6f..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerModuleService.kt +++ /dev/null @@ -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()) - } -} diff --git a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerProfileService.kt b/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerProfileService.kt deleted file mode 100644 index a36e376e..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/diva/service/PlayerProfileService.kt +++ /dev/null @@ -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 = 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) -}