From 9f67ae1f4eaa20fd423642d1420368dcb5d0e27d Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 8 Jun 2024 14:38:31 +0000 Subject: [PATCH] feat: General::penaltyList --- hwe/j_myBossInfo.php | 5 ++++- hwe/sammo/Enums/PenaltyKey.php | 1 + hwe/sammo/General.php | 28 +++++++++++++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/hwe/j_myBossInfo.php b/hwe/j_myBossInfo.php index 8edb9a0f..24def6ab 100644 --- a/hwe/j_myBossInfo.php +++ b/hwe/j_myBossInfo.php @@ -4,6 +4,7 @@ namespace sammo; use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\Enums\MessageType; +use sammo\Enums\PenaltyKey; include "lib.php"; include "func.php"; @@ -174,7 +175,9 @@ function do추방(General $general, int $myOfficerLevel):?string{ $generalName = $general->getVar('name'); $nationID = $general->getNationID(); - + if($general->hasPenalty(PenaltyKey::NoBanGeneral)){ + return '추방할 수 없는 상태입니다.'; + } //추방할사람이 외교권자이면 불가 $permission = checkSecretPermission($general->getRaw()); diff --git a/hwe/sammo/Enums/PenaltyKey.php b/hwe/sammo/Enums/PenaltyKey.php index a4d2e54f..98ab5a74 100644 --- a/hwe/sammo/Enums/PenaltyKey.php +++ b/hwe/sammo/Enums/PenaltyKey.php @@ -10,4 +10,5 @@ enum PenaltyKey: string{ case NoTopSecret = 'noTopSecret'; case NoChief = 'noChief'; case NoAmbassador = 'noAmbassador'; + case NoBanGeneral = 'noBanGeneral'; } \ No newline at end of file diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 9194fd52..68066a78 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -7,6 +7,7 @@ use sammo\Command\GeneralCommand; use sammo\Enums\GeneralAccessLogColumn; use sammo\Enums\GeneralQueryMode; use sammo\Enums\InheritanceKey; +use sammo\Enums\PenaltyKey; use sammo\Enums\RankColumn; use sammo\WarUnitTrigger as WarUnitTrigger; @@ -28,6 +29,10 @@ class General extends GeneralBase implements iAction protected $logActivatedSkill = []; protected $isFinished = false; + + /** @var Map */ + protected Map $penaltyList; + /** @var ?iAction */ protected $nationType = null; /** @var ?iAction */ @@ -86,6 +91,16 @@ class General extends GeneralBase implements iAction $this->rankVarRead = new Map(); } + $penaltyList = new Map(); + foreach(Json::decode($raw['penalty'] ?? '{}') as $rawPenaltyKey => $penaltyValue){ + $penaltyKey = PenaltyKey::tryFrom($rawPenaltyKey); + if($penaltyKey === null){ + throw new \InvalidArgumentException('Invalid PenaltyKey: ' . $rawPenaltyKey); + } + $penaltyList[$penaltyKey] = $penaltyValue; + } + $this->penaltyList = $penaltyList; + $this->accessLogRead = $rawAccessLog; @@ -244,6 +259,17 @@ class General extends GeneralBase implements iAction return $this->crewType; } + function hasPenalty(PenaltyKey $penaltyKey): bool + { + return $this->penaltyList->hasKey($penaltyKey); + } + + /** @return Map */ + function getPenaltyList(): Map + { + return $this->penaltyList; + } + function calcRecentWarTurn(int $turnTerm): int { $cacheKey = "recent_war_turn_{$turnTerm}"; @@ -372,7 +398,7 @@ class General extends GeneralBase implements iAction } $this->calcCache[$cKey] = $statValue; - + return $statValue; }