From 7c9d5d34f68fb8543347de24b1f36fc8cc1548ff Mon Sep 17 00:00:00 2001 From: Hide_D Date: Wed, 10 Jul 2024 17:20:38 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8A=A4=ED=83=AF=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=EC=9A=A9=20API=20=EC=A4=80=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/InheritAction/ResetStat.php | 176 ++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 hwe/sammo/API/InheritAction/ResetStat.php diff --git a/hwe/sammo/API/InheritAction/ResetStat.php b/hwe/sammo/API/InheritAction/ResetStat.php new file mode 100644 index 00000000..89d7f609 --- /dev/null +++ b/hwe/sammo/API/InheritAction/ResetStat.php @@ -0,0 +1,176 @@ +args); + $v->rule('required', [ + 'leadership', + 'strength', + 'intel', + ]) + ->rule('int', [ + 'leadership', + 'strength', + 'intel', + ]) + ->rule('min', [ + 'leadership', + 'strength', + 'intel' + ], GameConst::$defaultStatMin) + ->rule('max', [ + 'leadership', + 'strength', + 'intel' + ], GameConst::$defaultStatMax) + ->rule('integerArray', 'inheritBonusStat'); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + //General.aux 쓰므로 lock; + return static::REQ_GAME_LOGIN; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType + { + $userID = $session->userID; + $generalID = $session->generalID; + + + $leadership = $this->args['leadership']; + $strength = $this->args['strength']; + $intel = $this->args['intel']; + $inheritBonusStat = $this->args['inheritBonusStat'] ?? null; + + if ($leadership + $strength + $intel > GameConst::$defaultStatTotal) { + return "능력치가 " . GameConst::$defaultStatTotal . "을 넘어섰습니다. 다시 가입해주세요!"; + } + + if ($inheritBonusStat) { + if (count($inheritBonusStat) != 3) { + return "보너스 능력치가 잘못 지정되었습니다. 다시 가입해주세요!"; + } + foreach ($inheritBonusStat as $stat) { + if ($stat < 0) { + return "보너스 능력치가 음수입니다. 다시 가입해주세요!"; + } + } + $sum = array_sum($inheritBonusStat); + if ($sum == 0) { + $inheritBonusStat = null; + } else if ($sum < 3 || $sum > 5) { + return "보너스 능력치 합이 잘못 지정되었습니다. 다시 가입해주세요!"; + } + } + + $general = General::createObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + $userLogger = new UserLogger($userID); + + + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + $gameStor->cacheValues([ + 'isunited', + 'season', + ]); + if ($gameStor->isunited) { + return '이미 천하가 통일되었습니다.'; + } + $userStor = KVStorage::getStorage($db, "user_{$userID}"); + + $lastUserStatReset = $userStor->getValue('last_stat_reset') ?? []; + $gameSeason = $gameStor->getValue('season'); + + if (array_search($gameSeason, $lastUserStatReset) !== false) { + return '이번 시즌에 이미 능력치를 초기화하셨습니다.'; + } + + + $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); + $previousPoint = ($inheritStor->getValue('previous') ?? [0, 0])[0]; + $reqAmount = 0; + if ($inheritBonusStat !== null) { + $reqAmount += GameConst::$inheritBornStatPoint; + } + + if ($previousPoint < $reqAmount) { + return '충분한 유산 포인트를 가지고 있지 않습니다.'; + } + + $userLogger->push("통솔 {$leadership}, 무력 {$strength}, 지력 {$intel} 스탯 재설정", "inheritPoint"); + + if ($inheritBonusStat) { + $pleadership = $inheritBonusStat[0] ?? 0; + $pstrength = $inheritBonusStat[1] ?? 0; + $pintel = $inheritBonusStat[2] ?? 0; + $userLogger->push("통솔 {$pleadership}, 무력 {$pstrength}, 지력 {$pintel} 보너스 능력치 적용", "inheritPoint"); + } else { + $rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'ResetStat', + $userID, + ))); + $pleadership = 0; + $pstrength = 0; + $pintel = 0; + foreach (Util::range($rng->nextRangeInt(3, 5)) as $statIdx) { + switch ($rng->choiceUsingWeight([$leadership, $strength, $intel])) { + case 0: + $pleadership++; + break; + case 1: + $pstrength++; + break; + case 2: + $pintel++; + break; + } + } + $userLogger->push("통솔 {$pleadership}, 무력 {$pstrength}, 지력 {$pintel} 보너스 능력치 적용", "inheritPoint"); + } + + $leadership += $pleadership; + $strength += $pstrength; + $intel += $pintel; + + + $general->setVar('leadership', $leadership); + $general->setVar('strength', $strength); + $general->setVar('intel', $intel); + + $userLogger->flush(); + + $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqAmount); + $general->applyDB($db); + return null; + } +}