From 0816d14264db01d9795a42ff6f70b7720189aab0 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Wed, 17 Oct 2018 16:01:38 +0900 Subject: [PATCH] =?UTF-8?q?generalSource=20=ED=8F=90=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/Command/BaseCommand.php | 13 ----- hwe/sammo/Command/General/che_강행.php | 22 +++++---- hwe/sammo/Command/General/che_기술연구.php | 2 +- hwe/sammo/Command/General/che_단련.php | 2 +- hwe/sammo/Command/General/che_사기진작.php | 2 +- hwe/sammo/Command/General/che_상업투자.php | 2 +- hwe/sammo/Command/General/che_이동.php | 21 +++++---- hwe/sammo/Command/General/che_정착장려.php | 2 +- hwe/sammo/Command/General/che_주민선정.php | 2 +- hwe/sammo/Command/General/che_집합.php | 23 ++++----- hwe/sammo/Command/General/che_훈련.php | 2 +- hwe/sammo/General.php | 8 ++-- hwe/sammo/GeneralTrigger/che_도시치료.php | 2 +- hwe/sammo/TurnExecutionHelper.php | 55 ++++++++-------------- 14 files changed, 67 insertions(+), 91 deletions(-) diff --git a/hwe/sammo/Command/BaseCommand.php b/hwe/sammo/Command/BaseCommand.php index 1273a02f..1267d826 100644 --- a/hwe/sammo/Command/BaseCommand.php +++ b/hwe/sammo/Command/BaseCommand.php @@ -36,8 +36,6 @@ abstract class BaseCommand{ protected $runnableConstraints = null; protected $reservableConstraints = null; - - protected $generalSource = null; protected $logger; @@ -54,17 +52,6 @@ abstract class BaseCommand{ } - public function setGeneralSource(?array $generalSource){ - $this->generalSource = $generalSource; - } - - protected function getGeneralObjFromGeneralSource(int $generalNo):?General{ - if($this->generalSource === null){ - return null; - } - return $this->generalSource[$generalNo]??null; - } - protected function resetTestCache():void{ $this->runnable = null; $this->reservable = null; diff --git a/hwe/sammo/Command/General/che_강행.php b/hwe/sammo/Command/General/che_강행.php index 2efffda2..1589c9f8 100644 --- a/hwe/sammo/Command/General/che_강행.php +++ b/hwe/sammo/Command/General/che_강행.php @@ -92,16 +92,18 @@ class che_강행 extends Command\GeneralCommand{ $general->setVar('city', $destCityID); if($general->getVar('level') == 12 && $this->nation['level'] == 0){ - $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); - foreach($generalList as $targetRawGeneral){ - $targetGeneralID = $targetRawGeneral['no']; - $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); - if($targetGeneral === null){ - $targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false); - } - $targetGeneral->setVar('city', $destCityID); - $targetGeneral->getLogger()->pushGeneralActionLog("방랑군 세력이 {$destCityName}{$josaRo} 강행했습니다.", ActionLogger::PLAIN); - $targetGeneral = null; + + $generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); + if($generalList){ + $db->update('general', [ + 'city'=>$destCityID + ], 'no IN %li', $generalList); + } + foreach($generalList as $targetGeneralID){ + $targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1); + $targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']); + $targetLogger->pushGeneralActionLog("방랑군 세력이 {$destCityName}{$josaRo} 강행했습니다.", ActionLogger::PLAIN); + $targetLogger->flush(); } } diff --git a/hwe/sammo/Command/General/che_기술연구.php b/hwe/sammo/Command/General/che_기술연구.php index 2113618a..e2f9138a 100644 --- a/hwe/sammo/Command/General/che_기술연구.php +++ b/hwe/sammo/Command/General/che_기술연구.php @@ -131,7 +131,7 @@ class che_기술연구 extends che_상업투자{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_단련.php b/hwe/sammo/Command/General/che_단련.php index 72a9c29d..aa84ab05 100644 --- a/hwe/sammo/Command/General/che_단련.php +++ b/hwe/sammo/Command/General/che_단련.php @@ -114,7 +114,7 @@ class che_단련 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_사기진작.php b/hwe/sammo/Command/General/che_사기진작.php index 8bcd3d15..27d09bd8 100644 --- a/hwe/sammo/Command/General/che_사기진작.php +++ b/hwe/sammo/Command/General/che_사기진작.php @@ -96,7 +96,7 @@ class che_사기진작 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_상업투자.php b/hwe/sammo/Command/General/che_상업투자.php index 702424d6..05b52be1 100644 --- a/hwe/sammo/Command/General/che_상업투자.php +++ b/hwe/sammo/Command/General/che_상업투자.php @@ -174,7 +174,7 @@ class che_상업투자 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_이동.php b/hwe/sammo/Command/General/che_이동.php index 7297ca0c..3c4fa6a5 100644 --- a/hwe/sammo/Command/General/che_이동.php +++ b/hwe/sammo/Command/General/che_이동.php @@ -92,16 +92,17 @@ class che_이동 extends Command\GeneralCommand{ $general->setVar('city', $destCityID); if($general->getVar('level') == 12 && $this->nation['level'] == 0){ - $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); - foreach($generalList as $targetRawGeneral){ - $targetGeneralID = $targetRawGeneral['no']; - $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); - if($targetGeneral === null){ - $targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false); - } - $targetGeneral->setVar('city', $destCityID); - $targetGeneral->getLogger()->pushGeneralActionLog("방랑군 세력이 {$destCityName}{$josaRo} 이동했습니다.", ActionLogger::PLAIN); - $targetGeneral = null; + $generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no!=%i', $general->getNationID(), $general->getID()); + if($generalList){ + $db->update('general', [ + 'city'=>$destCityID + ], 'no IN %li', $generalList); + } + foreach($generalList as $targetGeneralID){ + $targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1); + $targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']); + $targetLogger->pushGeneralActionLog("방랑군 세력이 {$destCityName}{$josaRo} 이동했습니다.", ActionLogger::PLAIN); + $targetLogger->flush(); } } diff --git a/hwe/sammo/Command/General/che_정착장려.php b/hwe/sammo/Command/General/che_정착장려.php index 7df42c3b..895ed3aa 100644 --- a/hwe/sammo/Command/General/che_정착장려.php +++ b/hwe/sammo/Command/General/che_정착장려.php @@ -161,7 +161,7 @@ class che_정착장려 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_주민선정.php b/hwe/sammo/Command/General/che_주민선정.php index 760e63ab..71452ebd 100644 --- a/hwe/sammo/Command/General/che_주민선정.php +++ b/hwe/sammo/Command/General/che_주민선정.php @@ -158,7 +158,7 @@ class che_주민선정 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_집합.php b/hwe/sammo/Command/General/che_집합.php index 4b7a8bd3..145858a2 100644 --- a/hwe/sammo/Command/General/che_집합.php +++ b/hwe/sammo/Command/General/che_집합.php @@ -81,16 +81,17 @@ class che_집합 extends Command\GeneralCommand{ $logger->pushGeneralActionLog("{$cityName}에서 집합을 실시했습니다. <1>$date"); - $generalList = $db->query('SELECT no, name, city, nation, level FROM general WHERE nation=%i AND troop=%i AND no!=%i', $general->getNationID(), $troopID, $general->getID()); - foreach($generalList as $targetRawGeneral){ - $targetGeneralID = $targetRawGeneral['no']; - $targetGeneral = $this->getGeneralObjFromGeneralSource($targetGeneralID); - if($targetGeneral === null){ - $targetGeneral = new General($targetRawGeneral, null, $env['year'], $env['month'], false); - } - $targetGeneral->setVar('city', $destCityID); - $targetGeneral->getLogger()->pushGeneralActionLog("{$troopName}의 부대원들은 {$cityName}{$josaRo} 집합되었습니다.", ActionLogger::PLAIN); - $targetGeneral = null; + $generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND troop=%i AND no!=%i', $general->getNationID(), $troopID, $general->getID()); + if($generalList){ + $db->update('general', [ + 'city'=>$cityID + ], 'no IN %li', $generalList); + } + foreach($generalList as $targetGeneralID){ + $targetGeneral = General::createGeneralObjFromDB($targetGeneralID, [], 1); + $targetLogger = new ActionLogger($targetGeneralID, $general->getNationID(), $env['year'], $env['month']); + $targetLogger->pushGeneralActionLog("{$troopName}의 부대원들은 {$cityName}{$josaRo} 집합되었습니다.", ActionLogger::PLAIN); + $targetLogger->flush(); } $exp = 70; @@ -106,7 +107,7 @@ class che_집합 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/Command/General/che_훈련.php b/hwe/sammo/Command/General/che_훈련.php index cba8be4a..52e47942 100644 --- a/hwe/sammo/Command/General/che_훈련.php +++ b/hwe/sammo/Command/General/che_훈련.php @@ -93,7 +93,7 @@ class che_훈련 extends Command\GeneralCommand{ $general->checkStatChange(); $general->applyDB($db); - uniqueItemEx($general->getVar('no'), $logger); + uniqueItemEx($general->getID(), $logger); } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index ae2e429c..015d4f86 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -504,9 +504,9 @@ class General implements iAction{ return $caller; } - static public function createGeneralObjFromDB(int $generalID, ?array $column=null, bool $fullConstruct=true):self{ + static public function createGeneralObjFromDB(int $generalID, ?array $column=null, int $constructMode=2):self{ $db = DB::db(); - if($fullConstruct){ + if($constructMode > 0){ $gameStor = KVStorage::getStorage($db, 'game_env'); [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); } @@ -533,7 +533,7 @@ class General implements iAction{ if($column === null){ $column = $fullColumn; } - else if($fullConstruct){ + else if($constructMode > 1){ $column = array_unique(array_merge($defaultEventColumn, $column)); } else{ @@ -545,7 +545,7 @@ class General implements iAction{ throw new \InvalidArgumentException("generalID에 해당하는 장수가 없음: {$generalID}"); } - $general = new static($rawGeneral, null, $year, $month, $fullConstruct); + $general = new static($rawGeneral, null, $year, $month, $constructMode > 1); return $general; } diff --git a/hwe/sammo/GeneralTrigger/che_도시치료.php b/hwe/sammo/GeneralTrigger/che_도시치료.php index 5b9bcc88..79279234 100644 --- a/hwe/sammo/GeneralTrigger/che_도시치료.php +++ b/hwe/sammo/GeneralTrigger/che_도시치료.php @@ -27,7 +27,7 @@ class che_도시치료 extends BaseGeneralTrigger{ $patients = $db->queryAllLists( 'SELECT no,name,nation FROM general WHERE city=%i AND injury > 10 AND no != %i', $general->getVar('city'), - $general->getVar('no') + $general->getID() ); if(!$patients){ diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index 4b60b361..258dea33 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -8,12 +8,10 @@ class TurnExecutionHelper * @var General $generalObj; */ protected $generalObj; - protected $generalSource = null; - public function __construct(General $general, ?array $generalSource = null) + public function __construct(General $general) { $this->generalObj = $general; - $this->generalSource = $generalSource; } public function __destruct() @@ -77,7 +75,6 @@ class TurnExecutionHelper $gameStor = KVStorage::getStorage($db, 'game_env'); $commandObj = buildNationCommandClass($commandClassName, $general, $gameStor->getAll(true), $commandLast, $commandArg); - $commandObj->setGeneralSource($this->generalSource); $failReason = $commandObj->testReservable(); if($failReason){ @@ -103,7 +100,6 @@ class TurnExecutionHelper $commandClass = getGeneralCommandClass($commandClassName); /** @var \sammo\Command\GeneralCommand $commandObj */ $commandObj = new $commandClass($general, $gameStor->getAll(true), $commandArg, $commandLast); - $commandObj->setGeneralSource($this->generalSource); $failReason = $commandObj->testReservable(); if($failReason){ @@ -188,61 +184,47 @@ class TurnExecutionHelper static public function executeGeneralCommandUntil(string $date, \DateTimeInterface $limitActionTime, int $year, int $month){ $db = DB::db(); - $rawGeneralsTodo = $db->queryFirstRow( - 'SELECT no,name,name2,picture,imgsvr,nation,nations,city,troop,injury,affinity, -leader,leader2,power,power2,intel,intel2,weap,book,horse,item, -experience,dedication,level,gold,rice,crew,crewtype,train,atmos, -turntime,makenation,makelimit,killturn,block,dedlevel,explevel, -age,belong,personal,special,special2,term,mode, -npc,npc_org,npcid,deadyear,npcmsg, -dex0,dex10,dex20,dex30,dex40, -warnum,killnum,deathnum,killcrew,deathcrew,recwar,last_turn + $generalsTodo = $db->queryFirstRow( + 'SELECT no,name,turntime,killturn,block,npc,deadyear, general_turn.`action` AS `action`, general_turn.arg AS arg FROM general LEFT JOIN general_turn ON general.`no` = general_turn.general_id AND turn_idx = 0 WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', $date ); - $generalsTodo = []; - $generalSource = []; - foreach($rawGeneralsTodo as $rawGeneral){ + $currentTurn = null; + + foreach($generalsTodo as $rawGeneral){ $generalCommand = $rawGeneral['action']; $generalArg = Json::decode($rawGeneral['arg'])??[]; unset($rawGeneral['action']); unset($rawGeneral['arg']); - $general = new General($rawGeneral, $year, $month); - - $generalsTodo[] = [$general, $generalCommand, $generalArg]; - $generalSource[$general->getID()] = $general; - } - - $currentTurn = null; - - foreach($generalsTodo as [$general, $generalCommand, $generalArg]){ + $currActionTime = new \DateTimeImmutable(); if($currActionTime > $limitActionTime){ return [true, $currentTurn]; } - $turnObj = new static($general, $generalSource); + $general = General::createGeneralObjFromDB($rawGeneral['no']); + $turnObj = new static($general); $hasNationTurn = false; - if($generalWork['nation'] != 0 && $generalWork['level'] >= 5){ + if($general->getVar('nation') != 0 && $general->getVar('level') >= 5){ $nationStor = KVStorage::getStorage($db, 'nation_env'); - $lastNationTurnKey = "turn_last_{$generalWork['nation']}_{$generalWork['level']}"; + $lastNationTurnKey = "turn_last_{$general->getVar('nation')}_{$general->getVar('level')}"; $lastNationTurn = $nationStor->getDBValue($lastNationTurnKey)??[]; //수뇌 몇 없는데 매번 left join 하는건 낭비인것 같다. $rawNationTurn = Json::decode($db->queryFirstRow( 'SELECT action, arg FROM nation_turn WHERE nation_id = %i AND level = %i AND turn_idx =0', - $generalWork['nation'], - $generalWork['level'] + $general->getVar('nation'), + $general->getVar('level') ))??[]; $hasNationTurn = true; $nationCommand = $rawNationTurn['action']; $nationArg = Json::decode($rawNationTurn['arg']); } - if($generalWork['npc'] >= 2){ + if($general->getVar('npc') >= 2){ $ai = new GeneralAI($turnObj->getGeneral()); if($hasNationTurn){ [$nationCommand, $nationArg] = $ai->chooseNationTurn($nationCommand, $nationArg); @@ -264,12 +246,15 @@ WHERE turntime < %s ORDER BY turntime ASC, `no` ASC', } $turnObj->processCommand($generalCommand, $generalArg); } - pullNationCommand($generalWork['nation'], $generalWork['level']); - pullGeneralCommand($generalWork['no']); + pullNationCommand($general->getVar('nation'), $general->getVar('level')); + pullGeneralCommand($general->getID()); + + $currentTurn = $general->getVar('turntime'); + $turnObj->updateTurnTime(); $turnObj->applyDB(); - $currentTurn = $generalWork['turntime']; + } return [false, $currentTurn];