From 11a8efac859a8dc2b678c4de33ce46211eb237c4 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Thu, 14 Jul 2022 22:48:03 +0900 Subject: [PATCH] wip --- hwe/sammo/API/Nation/GetNationInfo.php | 144 +++++++++++-------------- 1 file changed, 62 insertions(+), 82 deletions(-) diff --git a/hwe/sammo/API/Nation/GetNationInfo.php b/hwe/sammo/API/Nation/GetNationInfo.php index 4394c363..e0823ae0 100644 --- a/hwe/sammo/API/Nation/GetNationInfo.php +++ b/hwe/sammo/API/Nation/GetNationInfo.php @@ -3,9 +3,15 @@ namespace sammo\API\Nation; use sammo\DB; +use sammo\GameConst; +use sammo\General; +use sammo\KVStorage; +use sammo\LastTurn; use sammo\Session; +use sammo\Util; use sammo\Validator; +use function sammo\buildNationCommandClass; use function sammo\checkLimit; use function sammo\checkSecretPermission; use function sammo\getBattleDetailLogMore; @@ -18,91 +24,65 @@ use function sammo\getNationStaticInfo; class GetNationInfo extends \sammo\BaseAPI { - public function validateArgs(): ?string - { - return null; + public function validateArgs(): ?string + { + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $userID = $session->userID; + + $db = DB::db(); + $nationID = $db->queryFirstField('SELECT nation FROM general WHERE `owner` = %i', $userID); + + if (!$nationID) { + return [ + 'result' => true, + 'nation' => getNationStaticInfo(0) + ]; } - public function getRequiredSessionMode(): int - { - return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + $generalObj = General::createGeneralObjFromDB($session->generalID, null, 1); + + $gameStor = KVStorage::getStorage($db, 'game_env'); + $gameEnv = $gameStor->getValues(['year', 'month', 'startyear']); + + $nation = $db->queryFirstRow( + 'SELECT nation, `name`, color, capital, gennum, gold, rice, bill, rate, secretlimit, chief_set, scout, war, strategic_cmd_limit, surlimit, tech, `power`, `level`, `type` FROM nation WHERE id = %i', + $nationID + ); + $nationStor = \sammo\KVStorage::getStorage($db, $nationID, 'nation_env'); + $nationStor->cacheAll(); + + + //전략 정보를 매번 읽어와야하나? + $impossibleStrategicCommandLists = []; + $strategicCommandLists = GameConst::$availableChiefCommand['전략']; + $yearMonth = Util::joinYearMonth($gameEnv['year'], $gameEnv['month']); + foreach ($strategicCommandLists as $command) { + $cmd = buildNationCommandClass($command, $generalObj, $gameEnv, new LastTurn()); + $nextAvailableTurn = $cmd->getNextAvailableTurn(); + if ($nextAvailableTurn > $yearMonth) { + $impossibleStrategicCommandLists[] = [$cmd->getName(), $nextAvailableTurn - $yearMonth]; + } } - public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag) - { - $userID = $session->userID; - - $db = DB::db(); - $nationID = $db->queryFirstField('SELECT nation FROM general WHERE `owner` = %i', $userID); - - if(!$nationID){ - return [ - 'result' => true, - 'nation' => getNationStaticInfo(0) - ]; - } - - - - $targetGeneralID = $this->getTargetGeneralID($session); - $reqType = $this->args['type']; - $reqTo = $this->args['reqTo'] ?? null; - - - $me = $db->queryFirstRow('SELECT no,nation,officer_level,con,turntime,belong,permission,penalty from general where owner=%i', $userID); - - $con = checkLimit($me['con']); - if ($con >= 2) { - return '접속 제한입니다.'; - } - - $permissionResult = $this->checkPermission($me); - if ($permissionResult !== null) { - return $permissionResult; - } - - if ($reqType == static::GENERAL_HISTORY) { - return [ - 'result' => true, - 'reqType' => $reqType, - 'generalID' => $targetGeneralID, - 'log' => getGeneralHistoryLogAll($targetGeneralID) - ]; - } - - if ($reqType == static::GENERAL_ACTION) { - return [ - 'result' => true, - 'reqType' => $reqType, - 'generalID' => $targetGeneralID, - 'log' => $reqTo === null - ? getGeneralActionLogRecent($targetGeneralID, 30) - : getGeneralActionLogMore($targetGeneralID, $reqTo, 30) - ]; - } - - if ($reqType == static::BATTLE_RESULT) { - return [ - 'result' => true, - 'reqType' => $reqType, - 'generalID' => $targetGeneralID, - 'log' => $reqTo === null - ? getBattleResultRecent($targetGeneralID, 30) - : getBattleResultMore($targetGeneralID, $reqTo, 30) - ]; - } - - if ($reqType == static::BATTLE_DETAIL) { - return [ - 'result' => true, - 'reqType' => $reqType, - 'generalID' => $targetGeneralID, - 'log' => $reqTo === null - ? getBattleResultRecent($targetGeneralID, 30) - : getBattleDetailLogMore($targetGeneralID, $reqTo, 30) - ]; - } - - return '잘못된 요청입니다: ' . $reqType; + $troopName = []; + foreach ($db->queryAllLists('SELECT troop_leader, name FROM troop WHERE nation=%i', $nationID) as [$troopID, $tName]) { + $troopName[$troopID] = $tName; } + + return [ + 'result' => true, + 'nation' => $nation, + 'impossibleStrategicCommandLists' => $impossibleStrategicCommandLists, + 'troops' => $troopName, + ]; + } }