From 8e93c69582a93ed642c3f195390145ce8a3674ef Mon Sep 17 00:00:00 2001 From: Hide_D Date: Mon, 25 Dec 2023 16:19:44 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20GetFrontInfo=EC=9D=98=20General?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EA=B0=9C=EC=9D=B8=20=EC=A0=84=EB=9E=B5=20?= =?UTF-8?q?=EC=BF=A8=20=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/API/General/GetFrontInfo.php | 29 +++++++++++++++++++++++--- hwe/ts/defs/API/Global.ts | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hwe/sammo/API/General/GetFrontInfo.php b/hwe/sammo/API/General/GetFrontInfo.php index c36cd570..4c7abf13 100644 --- a/hwe/sammo/API/General/GetFrontInfo.php +++ b/hwe/sammo/API/General/GetFrontInfo.php @@ -5,11 +5,14 @@ namespace sammo\API\General; use DateTimeInterface; use MeekroDB; use sammo\CityConst; +use sammo\Command\UserActionCommand; use sammo\DB; +use sammo\DTO\UserAction; use sammo\DTO\VoteInfo; use sammo\Enums\APIRecoveryType; use sammo\Enums\CityColumn; use sammo\Enums\GeneralAccessLogColumn; +use sammo\Enums\GeneralAuxKey; use sammo\Enums\GeneralColumn; use sammo\Enums\GeneralQueryMode; use sammo\Enums\RankColumn; @@ -27,6 +30,7 @@ use function sammo\buildNationCommandClass; use function sammo\checkLimit; use function sammo\getTournamentTermText; use function sammo\buildNationTypeClass; +use function sammo\buildUserActionCommandClass; use function sammo\calcLeadershipBonus; use function sammo\checkSecretPermission; use function sammo\getBillByLevel; @@ -101,7 +105,8 @@ class GetFrontInfo extends \sammo\BaseAPI return $history; } - private function generateRecentRecord(int $generalID){ + private function generateRecentRecord(int $generalID) + { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); @@ -247,7 +252,7 @@ class GetFrontInfo extends \sammo\BaseAPI $nationID ); - if($nationPopulation['cityCnt'] == 0){ + if ($nationPopulation['cityCnt'] == 0) { $nationPopulation = [ 'cityCnt' => 0, 'now' => 0, @@ -361,6 +366,8 @@ class GetFrontInfo extends \sammo\BaseAPI public function generateGeneralInfo(MeekroDB $db, General $general, array $rawNation): array { + $gameStor = KVStorage::getStorage($db, 'game_env'); + $admin = $gameStor->getAll(true); $permission = checkSecretPermission($general->getRaw()); @@ -443,6 +450,21 @@ class GetFrontInfo extends \sammo\BaseAPI 'permission' => $permission, ]; + $rawUserAction = $general->getAuxVar(UserActionCommand::USER_ACTION_KEY) ?? []; + $userAction = UserAction::fromArray($rawUserAction); + $impossibleUserAction = []; + $yearMonth = Util::joinYearMonth($admin['year'], $admin['month']); + + if ($userAction->nextAvailableTurn) { + foreach ($userAction->nextAvailableTurn as $command => $nextAvailableTurn) { + if ($nextAvailableTurn > $yearMonth) { + $impossibleUserAction[] = [$command, $nextAvailableTurn - $yearMonth]; + } + } + } + + $result['impossibleUserAction'] = $impossibleUserAction; + $nationID = $general->getNationID(); $troopID = $general->getVar(GeneralColumn::troop); if (!$troopID) { @@ -483,6 +505,7 @@ class GetFrontInfo extends \sammo\BaseAPI 'name' => $troopName, ]; + return $result; } @@ -576,7 +599,7 @@ class GetFrontInfo extends \sammo\BaseAPI if ($globalInfo['lastVote']) { $myLastVoteID = $db->queryFirstField('SELECT vote_id FROM vote WHERE general_id = %i ORDER BY vote_id DESC LIMIT 1', $generalID); - if($myLastVoteID) { + if ($myLastVoteID) { $auxInfo['myLastVote'] = $myLastVoteID; } } diff --git a/hwe/ts/defs/API/Global.ts b/hwe/ts/defs/API/Global.ts index 54741808..c4920752 100644 --- a/hwe/ts/defs/API/Global.ts +++ b/hwe/ts/defs/API/Global.ts @@ -148,6 +148,7 @@ export type GetFrontInfoResponse = { }; name: string; }; + impossibleUserAction: [string, number][]; }; nation: { id: number;