From 270cb25285a2ad91072ee6d263b5777e51d17a86 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 2 Oct 2022 17:33:23 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20GeneralAI=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=ED=95=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/GeneralAI.php | 48 +++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 0ca67a05..ee4c5993 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -11,8 +11,6 @@ class GeneralAI { protected RandUtil $rng; - /** @var General */ - protected $general; protected array $city; protected array $nation; protected int $genType; @@ -65,6 +63,9 @@ class GeneralAI /** @var General[] */ protected $chiefGenerals; + /** @var bool */ + protected $reqUpdateInstance = true; + /** @var General[] */ protected $lostGenerals; /** @var General[] 이번 턴에 '집합'하는 부대장 목록 */ @@ -80,15 +81,18 @@ class GeneralAI const d직전 = 3; const d전쟁 = 4; - //수뇌용 + protected function updateInstance(): void{ + if(!$this->reqUpdateInstance){ + return; + } + + $this->reqUpdateInstance = false; - public function __construct(General $general) - { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); $this->env = $gameStor->getAll(true); $this->baseDevelCost = $this->env['develcost'] * 12; - $this->general = $general; + $general = $this->general; $city = $general->getRawCity(); if ($city === null) { $city = $db->queryFirstRow('SELECT * FROM city WHERE city = %i', $general->getCityID()); @@ -96,14 +100,6 @@ class GeneralAI } $this->city = $city; - $this->rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( - UniqueConst::$hiddenSeed, - 'GeneralAI', - $this->env['year'], - $this->env['month'], - $general->getID(), - ))); - $this->nation = $db->queryFirstRow( 'SELECT nation,name,color,capital,capset,gennum,gold,rice,bill,rate,rate_tmp,scout,war,strategic_cmd_limit,surlimit,tech,power,level,chief_set,type,aux FROM nation WHERE nation = %i', $general->getNationID() @@ -142,6 +138,19 @@ class GeneralAI $this->nation['aux'] = Json::decode($this->nation['aux'] ?? '{}'); + $this->calcDiplomacyState(); + } + + public function __construct(protected General $general) + { + $this->rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'GeneralAI', + $this->env['year'], + $this->env['month'], + $general->getID(), + ))); + $this->leadership = $general->getLeadership(); $this->strength = $general->getStrength(); $this->intel = $general->getIntel(); @@ -150,10 +159,7 @@ class GeneralAI $this->fullStrength = $general->getStrength(false); $this->fullIntel = $general->getIntel(false); - $this->genType = $this->calcGenType($general); - - $this->calcDiplomacyState(); } public function getGeneralObj(): General @@ -2653,7 +2659,7 @@ class GeneralAI return $this->rng->choiceUsingWeightPair($cmdList); } - public function do소집해제(): ?GeneralCommand + protected function do소집해제(): ?GeneralCommand { if ($this->attackable) { return null; @@ -3573,6 +3579,8 @@ class GeneralAI public function chooseNationTurn(NationCommand $reservedCommand): NationCommand { + $this->updateInstance(); + //TODO: NationTurn과 InstantNationTurn 구분 필요 $lastTurn = $reservedCommand->getLastTurn(); $general = $this->general; @@ -3644,6 +3652,8 @@ class GeneralAI return $reservedCommand; } + $this->updateInstance(); + foreach ($this->nationPolicy->priority as $actionName) { /** @var ?NationCommand */ if (!key_exists($actionName, $this->nationPolicy::$availableInstantTurn)) { @@ -3666,6 +3676,8 @@ class GeneralAI $npcType = $general->getNPCType(); $nationID = $general->getNationID(); + $this->updateInstance(); + //특별 메세지 있는 경우 출력 $term = $this->env['turnterm']; if ($general->getVar('npcmsg') && $this->rng->nextBool(GameConst::$npcMessageFreqByDay * $term / (60 * 24))) {