From fd0f5edfe311b50bd259c9d385bbfd3adf6990d9 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 29 Mar 2018 01:23:58 +0900 Subject: [PATCH] =?UTF-8?q?build=20=EC=A0=84=EA=B9=8C=EC=A7=84=20=EC=8B=A4?= =?UTF-8?q?=EC=A0=9C=20=EC=9E=A5=EC=88=98=EB=A5=BC=20=EC=95=8C=20=EC=88=98?= =?UTF-8?q?=20=EC=97=86=EB=8A=94=20=EC=A0=90=20=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/sammo/Scenario.php | 42 +++++++++++++++++++++++++++++------ twe/sammo/Scenario/Nation.php | 38 +++++++++++++++---------------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/twe/sammo/Scenario.php b/twe/sammo/Scenario.php index 6507699c..3aa54636 100644 --- a/twe/sammo/Scenario.php +++ b/twe/sammo/Scenario.php @@ -79,7 +79,7 @@ class Scenario{ $this->tmpGeneralQueue[$name] = $rawGeneral; - $general = new Scenario\NPC( + return new Scenario\NPC( $affinity, $name, $pictureID, @@ -94,8 +94,6 @@ class Scenario{ $char, $text ); - - $this->nations[$nationID]->addNPC($general); }, Util::array_get($data['general'], [])); $this->generalsEx = array_map(function($rawGeneral){ @@ -115,7 +113,7 @@ class Scenario{ $this->tmpGeneralQueue[$name] = $rawGeneral; - $general = new Scenario\NPC( + return new Scenario\NPC( $affinity, $name, $pictureID, @@ -131,7 +129,6 @@ class Scenario{ $text ); - $this->nations[$nationID]->addNPC($general, true); }, Util::array_get($data['generalEx'], [])); $this->initialEvents = array_map(function($rawEvent){ @@ -232,14 +229,40 @@ class Scenario{ public function getScenarioBrief(){ $nations = []; + $nationGeneralCnt = []; + $nationGeneralExCnt = []; + + foreach($this->generals as $general){ + $nationID = $general->nationID; + if(!key_exists($nationID, $nationGeneralCnt)){ + $nationGeneralCnt[$nationID] = 1; + } + else{ + $nationGeneralCnt[$nationID] += 1; + } + } + + foreach($this->generalsEx as $general){ + $nationID = $general->nationID; + if(!key_exists($nationID, $nationGeneralExCnt)){ + $nationGeneralExCnt[$nationID] = 1; + } + else{ + $nationGeneralExCnt[$nationID] += 1; + } + } return [ 'year'=>$this->getYear(), 'title'=>$this->getTitle(), 'npc_cnt'=>count($this->getNPC()), 'npcEx_cnt'=>count($this->getNPCex()), - 'nation'=>array_map(function($nation){ - return $nation->getBrief(); + 'nation'=>array_map(function($nation) use ($nationGeneralCnt, $nationGeneralExCnt){ + $brief = $nation->getBrief(); + $brief['generals'] = Util::array_get($nationGeneralCnt[$nation->getID()], 0); + $brief['generalsEx'] = Util::array_get($nationGeneralExCnt[$nation->getID()], 0); + + return $brief; },$this->getNation()) ]; } @@ -339,6 +362,11 @@ class Scenario{ }, $this->events); $db->insert('event', $this->events); + + refreshNationStaticInfo(); + foreach(getAllNationStaticInfo() as $nation){ + SetNationFront($connect, $nation['nation']); + } } /** diff --git a/twe/sammo/Scenario/Nation.php b/twe/sammo/Scenario/Nation.php index 7f04417e..a2919e21 100644 --- a/twe/sammo/Scenario/Nation.php +++ b/twe/sammo/Scenario/Nation.php @@ -17,8 +17,6 @@ class Nation{ private $capital; private $cities = []; - private $generals = []; - private $generalsEx = []; public function __construct( int $id = null, @@ -50,22 +48,12 @@ class Nation{ $this->id = $id; } - public function addNPC(NPC $npc, bool $isExtend=false){ - if($isExtend){ - $this->generalsEx[] = $npc; - } - else{ - $this->generals[] = $npc; - } - + public function getID(){ + return $this->id; } public function build($env=[]){ - $npc_cnt = count($this->generals); - if($env['useExtentedGeneral']){ - $npc_cnt += count($this->generalsEx); - } - + //NOTE: NPC의 숫자는 아직 확정된 것이 아니다. $cities = array_map(function($cityName){ return \sammo\CityHelper::getCityByName($cityName)['id']; }, $this->cities); @@ -81,7 +69,7 @@ class Nation{ 'name'=>$this->name, 'color'=>$this->color, 'capital'=>$capital, - 'gennum'=>$npc_cnt, + 'gennum'=>0, 'gold'=>$this->gold, 'rice'=>$this->rice, 'bill'=>100, @@ -92,7 +80,7 @@ class Nation{ 'surlimit'=>72, 'scoutmsg'=>$this->infoText, 'tech'=>$this->tech, - 'totaltech'=>$this->tech*$npc_cnt, + 'totaltech'=>0, 'level'=>$this->level, 'type'=>$type, ]); @@ -118,6 +106,18 @@ class Nation{ $db->insert('diplomacy', $diplomacy); } + public function postBuild($env=[]){ + $npc_cnt = count($this->generals); + if($env['useExtentedGeneral']){ + $npc_cnt += count($this->generalsEx); + } + + $db->update('nation', [ + 'gennum'=>$npc_cnt, + 'totaltech'=>$this->tech*$npc_cnt + ], 'nation=%i', $this->id); + } + public function getBrief(){ return [ 'id'=>$this->id, @@ -129,9 +129,7 @@ class Nation{ 'tech'=>$this->tech, 'type'=>$this->type, 'nationLevel'=>$this->nationLevel, - 'cities'=>$this->cities, - 'generals'=>count($this->generals), - 'generalsEx'=>count($this->generalsEx) + 'cities'=>$this->cities ]; } } \ No newline at end of file