From f54bdfcea09217c67eb98ac0e79d989481b5a371 Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 15 Sep 2021 02:58:29 +0900 Subject: [PATCH] =?UTF-8?q?Inherit:=20Action=20=EC=99=84=EB=A3=8C=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/InheritAction/BuyHiddenBuff.php | 79 +++++++++++++++++++ .../API/InheritAction/BuySpecificUnique.php | 2 +- .../API/InheritAction/ResetSpecialWar.php | 64 +++++++++++++++ hwe/sammo/API/InheritAction/ResetTurnTime.php | 73 +++++++++++++++++ .../API/InheritAction/SetNextSpecialWar.php | 75 ++++++++++++++++++ hwe/sammo/GameConstBase.php | 3 + 6 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 hwe/sammo/API/InheritAction/BuyHiddenBuff.php create mode 100644 hwe/sammo/API/InheritAction/ResetSpecialWar.php create mode 100644 hwe/sammo/API/InheritAction/ResetTurnTime.php create mode 100644 hwe/sammo/API/InheritAction/SetNextSpecialWar.php diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php new file mode 100644 index 00000000..74468fb1 --- /dev/null +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -0,0 +1,79 @@ +args); + $v->rule('required', [ + 'type', + 'level', + ]) + ->rule('integer', 'level') + ->rule('min', 'level', 1) + ->rule('max', 'level', TriggerInheritBuff::MAX_STEP) + ->rule('keyExists', 'type', TriggerInheritBuff::BUFF_KEY_TEXT); + + 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) + { + $userID = $session->userID; + $generalID = $session->generalID; + + $type = $this->args['type']; + $level = $this->args['level']; + + $general = General::createGeneralObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + + $inheritBuffList = $general->getAuxVar('inheritBuff') ?? []; + $prevLevel = $inheritBuffList[$type] ?? 0; + + if ($prevLevel == $level) { + return '이미 구입했습니다.'; + } + if ($prevLevel > $level) { + return '이미 더 높은 등급을 구입했습니다.'; + } + + $reqAmount = GameConst::$inheritBuffPoints[$level] - GameConst::$inheritBuffPoints[$prevLevel]; + + $db = DB::db(); + $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); + $previousPoint = $inheritStor->getValue('previous') ?? 0; + if ($previousPoint < $reqAmount) { + return '충분한 유산 포인트를 가지고 있지 않습니다.'; + } + + $inheritBuffList[$type] = $level; + $general->setAuxVar('inheritBuff', $inheritBuffList); + $inheritStor->setValue('previous', $previousPoint - $reqAmount); + $general->flushUpdateValues(); + return null; + } +} diff --git a/hwe/sammo/API/InheritAction/BuySpecificUnique.php b/hwe/sammo/API/InheritAction/BuySpecificUnique.php index cd76e5e1..a5f5b76d 100644 --- a/hwe/sammo/API/InheritAction/BuySpecificUnique.php +++ b/hwe/sammo/API/InheritAction/BuySpecificUnique.php @@ -30,7 +30,7 @@ class BuySpecificUnique extends \sammo\BaseAPI ]) ->rule('integer', 'amount') ->rule('min', GameConst::$inheritItemUniqueMinPoint) - ->rule('keyExists', $availableItems); + ->rule('keyExists', 'item', $availableItems); if (!$v->validate()) { return $v->errorStr(); diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php new file mode 100644 index 00000000..815ce71e --- /dev/null +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -0,0 +1,64 @@ +userID; + $generalID = $session->generalID; + + $general = General::createGeneralObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + + + $currentSpecialWar = $general->getVar('special2'); + if($currentSpecialWar === null || $currentSpecialWar == 'None'){ + return '이미 전투 특기가 공란입니다.'; + } + + $currentLevel = $general->getAuxVar('inheritResetSpecialWar') ?? -1; + $nextLevel = $currentLevel + 1; + while (count(GameConst::$inheritResetAttrPointBase) <= $nextLevel) { + $baseLen = count(GameConst::$inheritResetAttrPointBase); + GameConst::$inheritResetAttrPointBase[] = GameConst::$inheritResetAttrPointBase[$baseLen - 1] + GameConst::$inheritResetAttrPointBase[$baseLen - 2]; + } + + $reqPoint = GameConst::$inheritResetAttrPointBase[$nextLevel]; + + $db = DB::db(); + $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); + $previousPoint = $inheritStor->getValue('previous') ?? 0; + if ($previousPoint < $reqPoint) { + return '충분한 유산 포인트를 가지고 있지 않습니다.'; + } + + $general->setAuxVar('inheritResetSpecialWar', $nextLevel); + $general->setVar('special2', 'None'); + $inheritStor->setValue('previous', $previousPoint - $reqPoint); + $general->flushUpdateValues(); + return null; + } +} diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php new file mode 100644 index 00000000..2b1226b3 --- /dev/null +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -0,0 +1,73 @@ +userID; + $generalID = $session->generalID; + + $general = General::createGeneralObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + + $currentLevel = $general->getAuxVar('inheritResetTurnTime') ?? -1; + $nextLevel = $currentLevel + 1; + while (count(GameConst::$inheritResetAttrPointBase) <= $nextLevel) { + $baseLen = count(GameConst::$inheritResetAttrPointBase); + GameConst::$inheritResetAttrPointBase[] = GameConst::$inheritResetAttrPointBase[$baseLen - 1] + GameConst::$inheritResetAttrPointBase[$baseLen - 2]; + } + + $reqPoint = GameConst::$inheritResetAttrPointBase[$nextLevel]; + + $db = DB::db(); + $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); + $previousPoint = $inheritStor->getValue('previous') ?? 0; + if ($previousPoint < $reqPoint) { + return '충분한 유산 포인트를 가지고 있지 않습니다.'; + } + + $gameStor = new KVStorage($db, 'game_env'); + [$turnTerm, $serverTurnTime] = $gameStor->getValuesAsArray(['turnterm', 'turntime']); + + $serverTurnTimeObj = new DateTimeImmutable($serverTurnTime); + $turnTime = new DateTimeImmutable($general->getTurnTime()); + + $afterTurn = Util::randRange($turnTerm * -60 / 2, $turnTerm * 60 / 2); + + $turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($afterTurn)); + if($turnTime <= $serverTurnTimeObj){ + $turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 60)); + } + + $general->setVar('turntime', TimeUtil::format($turnTime, true)); + $general->setAuxVar('inheritResetTurnTime', $nextLevel); + $inheritStor->setValue('previous', $previousPoint - $reqPoint); + $general->flushUpdateValues(); + return null; + } +} diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php new file mode 100644 index 00000000..8f837353 --- /dev/null +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -0,0 +1,75 @@ +args); + $v->rule('required', [ + 'type', + ]) + ->rule('in', 'type', GameConst::$availableSpecialWar); + + 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) + { + $userID = $session->userID; + $generalID = $session->generalID; + + $type = $this->args['type']; + + $general = General::createGeneralObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + + $inheritSpecificSpecialWar = $general->getAuxVar('inheritSpecificSpecialWar'); + $currentSpecialWar = $general->getVar('special2'); + + if ($currentSpecialWar == $type) { + return '이미 그 특기를 보유하고 있습니다.'; + } + if ($inheritSpecificSpecialWar == $type) { + return '이미 그 특기를 예약하였습니다.'; + } + + if($inheritSpecificSpecialWar !== null){ + return '이미 예약한 특기가 있습니다.'; + } + + $reqAmount = GameConst::$inheritSpecificSpecialPoint; + + $db = DB::db(); + $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); + $previousPoint = $inheritStor->getValue('previous') ?? 0; + if ($previousPoint < $reqAmount) { + return '충분한 유산 포인트를 가지고 있지 않습니다.'; + } + + $general->setAuxVar('inheritSpecificSpecialWar', $type); + $inheritStor->setValue('previous', $previousPoint - $reqAmount); + $general->flushUpdateValues(); + return null; + } +} diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index 5f9344ce..ba8c86de 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -201,6 +201,9 @@ class GameConstBase public static $inheritBornStatPoint = 1000; public static $inheritItemUniqueMinPoint = 5000; public static $inheritItemRandomPoint = 3000; + public static $inheritBuffPoints = [0, 250, 750, 1500, 2500, 3750]; + public static $inheritSpecificSpecialPoint = 5000; + public static $inheritResetAttrPointBase = [1000, 1000, 2000, 3000];//필요하면 늘려서 쓰기 public static $allItems = [ 'horse' => [