From 822b5d312552f2762eb920772f04a9f29d6ecb31 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 30 Jul 2023 13:05:19 +0000 Subject: [PATCH] =?UTF-8?q?refac:=20GeneralBase,=20GeneralLite,=20General?= =?UTF-8?q?=20-=20GeneralLite=20->=20General=20=EA=B5=AC=EC=A1=B0=EB=8A=94?= =?UTF-8?q?=20PHP=EC=97=90=EC=84=9C=20=EA=B2=BD=EA=B3=A0=EB=A5=BC=20?= =?UTF-8?q?=EC=95=88=EB=9D=84=EC=9B=9F=EC=84=9C=20=ED=8F=AC=EA=B8=B0=20-?= =?UTF-8?q?=20GeneralBase=EC=97=90=EC=84=9C=20=EA=B0=81=EA=B0=81=20?= =?UTF-8?q?=EC=9A=94=EC=B2=AD=ED=95=98=EB=8A=94=20=ED=98=95=ED=83=9C?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20-=20=EC=97=AC=EC=A0=84?= =?UTF-8?q?=ED=9E=88=20GeneralBase=EB=A5=BC=20=EC=9D=B8=EC=9E=90=EB=A1=9C?= =?UTF-8?q?=20=EB=B0=9B=EB=8A=94=20=ED=95=A8=EC=88=98=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=20=20GeneralLite=EB=A5=BC=20=EC=9A=94=EA=B5=AC=ED=95=98?= =?UTF-8?q?=EA=B1=B0=EB=82=98,=20General=EC=9D=84=20=EC=9A=94=EA=B5=AC?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=ED=95=A8=EC=88=98=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=EB=A1=9C=20=ED=98=B8=EC=B6=9C=ED=95=A0=20=EB=95=8C=20?= =?UTF-8?q?=20=20=EA=B2=BD=EA=B3=A0=EA=B0=80=20=EC=97=86=EC=9C=BC=EB=AF=80?= =?UTF-8?q?=EB=A1=9C=20=ED=8A=B9=ED=9E=88=20=EC=A3=BC=EC=9D=98=ED=95=B4?= =?UTF-8?q?=EC=95=BC=20=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/AutorunGeneralPolicy.php | 18 +-- hwe/sammo/AutorunNationPolicy.php | 2 +- hwe/sammo/General.php | 8 +- hwe/sammo/GeneralBase.php | 228 +++++++++++++++++++++++++++++ hwe/sammo/GeneralLite.php | 222 +--------------------------- 5 files changed, 240 insertions(+), 238 deletions(-) create mode 100644 hwe/sammo/GeneralBase.php diff --git a/hwe/sammo/AutorunGeneralPolicy.php b/hwe/sammo/AutorunGeneralPolicy.php index ac3b8cfc..6b5419fb 100644 --- a/hwe/sammo/AutorunGeneralPolicy.php +++ b/hwe/sammo/AutorunGeneralPolicy.php @@ -19,7 +19,7 @@ class AutorunGeneralPolicy{ static $소집해제 = '소집해제'; static $출병 = '출병'; - + //static $NPC증여 = 'NPC증여'; static $NPC헌납 = 'NPC헌납'; static $NPC사망대비 = 'NPC사망대비'; @@ -31,12 +31,12 @@ class AutorunGeneralPolicy{ static $귀환 = '귀환'; //static $전투이동 = '전투이동'; //static $내정이동 = '내정이동'; - + static $국가선택 = '국가선택'; static $집합 = '집합'; static $건국 = '건국'; static $선양 = '선양'; - + static public array $default_priority = [ @@ -74,7 +74,7 @@ class AutorunGeneralPolicy{ public $can소집해제 = true; public $can출병 = true; - + //public $canNPC증여 = true; public $canNPC헌납 = true; @@ -91,7 +91,7 @@ class AutorunGeneralPolicy{ public array $priority; - function doNPCState(General $general){ + function doNPCState(GeneralBase $general){ $npc = $general->getNPCType(); $nationID = $general->getNationID(); @@ -115,7 +115,7 @@ class AutorunGeneralPolicy{ } - function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ $this->priority = static::$default_priority; if($serverPolicy && key_exists('priority', $serverPolicy)){ @@ -165,7 +165,7 @@ class AutorunGeneralPolicy{ $this->can전투준비 = false; $this->can출병 = false; - + //$this->canNPC증여 = false; $this->canNPC헌납 = false; @@ -194,9 +194,9 @@ class AutorunGeneralPolicy{ $this->can금쌀구매 = true; $this->can상인무시 = true; break; - case 'recruit_high': + case 'recruit_high': $this->can모병 = true; - case 'recruit': + case 'recruit': $this->can징병 = true; $this->can소집해제 = true; $this->can금쌀구매 = true; diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index 3323041d..836fdd5e 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -179,7 +179,7 @@ class AutorunNationPolicy { 'cureThreshold'=>10, ]; - function __construct(GeneralLite $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) { foreach(static::$defaultPolicy as $policy=>$value){ $this->{$policy} = $value; diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 0012c40a..47c8f772 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -10,11 +10,8 @@ use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; use sammo\WarUnitTrigger as WarUnitTrigger; -class General extends GeneralLite implements iAction +class General extends GeneralBase implements iAction { - protected $rawCity = null; - - /** @var Map */ protected Map $rankVarRead; /** @var Map */ @@ -25,9 +22,6 @@ class General extends GeneralLite implements iAction /** @var Map */ protected ?Map $accessLogRead; - /** @var \sammo\ActionLogger */ - protected $logger; - protected $activatedSkill = []; protected $logActivatedSkill = []; protected $isFinished = false; diff --git a/hwe/sammo/GeneralBase.php b/hwe/sammo/GeneralBase.php new file mode 100644 index 00000000..865e10f2 --- /dev/null +++ b/hwe/sammo/GeneralBase.php @@ -0,0 +1,228 @@ + */ + protected Map $rankVarRead; + + /** @var \sammo\ActionLogger */ + protected $logger; + + const TURNTIME_FULL_MS = -1; + const TURNTIME_FULL = 0; + const TURNTIME_HMS = 1; + const TURNTIME_HM = 2; + + protected static $prohibitedDirectUpdateVars = [ + //Reason: iAction + 'leadership' => 1, + 'power' => 1, + 'intel' => 1, + 'nation' => 2, + 'officer_level' => 1, + //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. + 'special' => 1, + 'special2' => 1, + 'personal' => 1, + 'horse' => 1, + 'weapon' => 1, + 'book' => 1, + 'item' => 1 + ]; + + function initLogger(int $year, int $month) + { + $this->logger = new ActionLogger( + $this->getVar('no'), + $this->getVar('nation'), + $year, + $month, + false + ); + } + + function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string + { + if(!key_exists('turntime', $this->raw)){ + return null; + } + + return [ + self::TURNTIME_FULL_MS => function ($turntime) { + return $turntime; + }, + self::TURNTIME_FULL => function ($turntime) { + return substr($turntime, 0, 19); + }, + self::TURNTIME_HMS => function ($turntime) { + return substr($turntime, 11, 8); + }, + self::TURNTIME_HM => function ($turntime) { + return substr($turntime, 11, 5); + }, + ][$short]($this->getVar('turntime')); + } + + function getNPCType(): int + { + return $this->raw['npc']; + } + + function getName(): string + { + return $this->raw['name']; + } + + function getID(): int + { + return $this->raw['no']; + } + + function getRawCity(): ?array + { + return $this->rawCity; + } + + function setRawCity(?array $city) + { + $this->rawCity = $city; + } + + function getCityID(): int + { + return $this->raw['city']; + } + + function getNationID(): int + { + return $this->raw['nation']; + } + + function getStaticNation(): array + { + return getNationStaticInfo($this->raw['nation']); + } + + function getLogger(): ?ActionLogger + { + return $this->logger; + } + + function getDex(GameUnitDetail $crewType) + { + $armType = $crewType->armType; + + if ($armType == GameUnitConst::T_CASTLE) { + $armType = GameUnitConst::T_SIEGE; + } + + return $this->getVar("dex{$armType}"); + } + + function getRankVar(RankColumn $key, $defaultValue = null): int + { + if (!$this->rankVarRead->hasKey($key)) { + if ($defaultValue === null) { + throw new \RuntimeException('인자가 없음 : ' . $key->value); + } + return $defaultValue; + } + + return $this->rankVarRead[$key]; + } + + abstract function applyDB($db): bool; + + static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + { + $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; + $defaultEventColumn = [ + 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', + 'special', 'special2', 'personal', + 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', + ]; + $fullColumn = [ + 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', + 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', + 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', + 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', + 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', + 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', + 'recent_war', 'last_turn', 'myset', + 'specage', 'specage2', 'aux', 'permission', 'penalty', + ]; + $fullAcessLogColumn = [ + GeneralAccessLogColumn::refreshScore, + GeneralAccessLogColumn::refreshScoreTotal, + ]; + + if ($reqColumns === null) { + switch ($queryMode) { + case GeneralQueryMode::Core: + return [$minimumColumn, [], []]; + case GeneralQueryMode::Lite: + return [$defaultEventColumn, [], []]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [$fullColumn, RankColumn::cases(), []]; + case GeneralQueryMode::FullWithAccessLog: + return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; + } + } + + /** @var RankColumn[] */ + $rankColumn = []; + $subColumn = []; + $accessLogColumn = []; + foreach ($reqColumns as $column) { + if ($column instanceof RankColumn) { + $rankColumn[] = $column; + continue; + } + if ($column instanceof GeneralAccessLogColumn) { + $accessLogColumn[] = $column; + continue; + } + + + $enumKey = RankColumn::tryFrom($column); + if ($enumKey !== null) { + $rankColumn[] = $enumKey; + continue; + } + $enumKey = GeneralAccessLogColumn::tryFrom($column); + if ($enumKey !== null) { + $accessLogColumn[] = $enumKey; + continue; + } + $subColumn[] = $column; + } + + switch ($queryMode) { + case GeneralQueryMode::Core: + return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::Lite: + return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithoutIAction: + case GeneralQueryMode::Full: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithAccessLog: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; + default: + throw new \RuntimeException('invalid query mode'); + } + } + +} diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php index 90bd1cb9..96c55500 100644 --- a/hwe/sammo/GeneralLite.php +++ b/hwe/sammo/GeneralLite.php @@ -3,49 +3,11 @@ namespace sammo; use Ds\Map; -use sammo\Command\GeneralCommand; -use sammo\Enums\GeneralAccessLogColumn; use sammo\Enums\GeneralQueryMode; -use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; -use sammo\WarUnitTrigger as WarUnitTrigger; -class GeneralLite +class GeneralLite extends GeneralBase { - use LazyVarUpdater; - - protected $raw = []; - protected $rawCity = null; - - /** @var Map */ - protected Map $rankVarRead; - - /** @var \sammo\ActionLogger */ - protected $logger; - - const TURNTIME_FULL_MS = -1; - const TURNTIME_FULL = 0; - const TURNTIME_HMS = 1; - const TURNTIME_HM = 2; - - protected static $prohibitedDirectUpdateVars = [ - //Reason: iAction - 'leadership' => 1, - 'power' => 1, - 'intel' => 1, - 'nation' => 2, - 'officer_level' => 1, - //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. - 'special' => 1, - 'special2' => 1, - 'personal' => 1, - 'horse' => 1, - 'weapon' => 1, - 'book' => 1, - 'item' => 1 - ]; - - /** * @param array $raw DB row값. * @param null|array $city DB city 테이블의 row값 @@ -72,108 +34,6 @@ class GeneralLite } } - function initLogger(int $year, int $month) - { - $this->logger = new ActionLogger( - $this->getVar('no'), - $this->getVar('nation'), - $year, - $month, - false - ); - } - - function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string - { - if(!key_exists('turntime', $this->raw)){ - return null; - } - - return [ - self::TURNTIME_FULL_MS => function ($turntime) { - return $turntime; - }, - self::TURNTIME_FULL => function ($turntime) { - return substr($turntime, 0, 19); - }, - self::TURNTIME_HMS => function ($turntime) { - return substr($turntime, 11, 8); - }, - self::TURNTIME_HM => function ($turntime) { - return substr($turntime, 11, 5); - }, - ][$short]($this->getVar('turntime')); - } - - function getNPCType(): int - { - return $this->raw['npc']; - } - - function getName(): string - { - return $this->raw['name']; - } - - function getID(): int - { - return $this->raw['no']; - } - - function getRawCity(): ?array - { - return $this->rawCity; - } - - function setRawCity(?array $city) - { - $this->rawCity = $city; - } - - function getCityID(): int - { - return $this->raw['city']; - } - - function getNationID(): int - { - return $this->raw['nation']; - } - - function getStaticNation(): array - { - return getNationStaticInfo($this->raw['nation']); - } - - function getLogger(): ?ActionLogger - { - return $this->logger; - } - - function getDex(GameUnitDetail $crewType) - { - $armType = $crewType->armType; - - if ($armType == GameUnitConst::T_CASTLE) { - $armType = GameUnitConst::T_SIEGE; - } - - return $this->getVar("dex{$armType}"); - } - - function getRankVar(RankColumn $key, $defaultValue = null): int - { - if (!$this->rankVarRead->hasKey($key)) { - if ($defaultValue === null) { - throw new \RuntimeException('인자가 없음 : ' . $key->value); - } - return $defaultValue; - } - - return $this->rankVarRead[$key]; - } - - /** * @param \MeekroDB $db */ @@ -201,86 +61,6 @@ class GeneralLite return $result; } - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array - { - $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; - $defaultEventColumn = [ - 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', - 'special', 'special2', 'personal', - 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', - ]; - $fullColumn = [ - 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', - 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', - 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', - 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', - 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', - 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', - 'recent_war', 'last_turn', 'myset', - 'specage', 'specage2', 'aux', 'permission', 'penalty', - ]; - $fullAcessLogColumn = [ - GeneralAccessLogColumn::refreshScore, - GeneralAccessLogColumn::refreshScoreTotal, - ]; - - if ($reqColumns === null) { - switch ($queryMode) { - case GeneralQueryMode::Core: - return [$minimumColumn, [], []]; - case GeneralQueryMode::Lite: - return [$defaultEventColumn, [], []]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [$fullColumn, RankColumn::cases(), []]; - case GeneralQueryMode::FullWithAccessLog: - return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; - } - } - - /** @var RankColumn[] */ - $rankColumn = []; - $subColumn = []; - $accessLogColumn = []; - foreach ($reqColumns as $column) { - if ($column instanceof RankColumn) { - $rankColumn[] = $column; - continue; - } - if ($column instanceof GeneralAccessLogColumn) { - $accessLogColumn[] = $column; - continue; - } - - - $enumKey = RankColumn::tryFrom($column); - if ($enumKey !== null) { - $rankColumn[] = $enumKey; - continue; - } - $enumKey = GeneralAccessLogColumn::tryFrom($column); - if ($enumKey !== null) { - $accessLogColumn[] = $enumKey; - continue; - } - $subColumn[] = $column; - } - - switch ($queryMode) { - case GeneralQueryMode::Core: - return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::Lite: - return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithAccessLog: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; - default: - throw new \RuntimeException('invalid query mode'); - } - } - /** * @param ?int[] $generalIDList * @param null|array $column