From 38986b65f8327eefce79b30921d1d9a875319dde Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 28 Mar 2018 20:39:30 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9C=EB=82=98=EB=A6=AC=EC=98=A4=20?= =?UTF-8?q?=EA=B5=AD=EA=B0=80=20=EC=84=A4=EC=A0=95=20=EC=BD=94=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/sammo/CityHelper.php | 4 +- twe/sammo/Scenario.php | 101 ++++++++++++++++++++++++++++++---- twe/sammo/Scenario/NPC.php | 57 +++++++++++++++++++ twe/sammo/Scenario/Nation.php | 84 +++++++++++++++++++++++++++- 4 files changed, 230 insertions(+), 16 deletions(-) diff --git a/twe/sammo/CityHelper.php b/twe/sammo/CityHelper.php index 4bc7ef7c..991e7fba 100644 --- a/twe/sammo/CityHelper.php +++ b/twe/sammo/CityHelper.php @@ -1,7 +1,5 @@ scenarioIdx = $scenarioIdx; $this->scenarioPath = $scenarioPath; - $this->data = Json::decode(file_get_contents($scenarioPath)); + $data = Json::decode(file_get_contents($scenarioPath)); + $this->data = $data; - $this->initialEvents = array_map(function($rawEvent){ - return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1)); - }, Util::array_get($this->data['initialEvents'], [])); + $this->year = Util::array_get($data['startYear']); + $this->title = Util::array_get($data['title'] , ''); + + $this->history = Util::array_get($data['history'], []); $this->nations = []; $this->nations[0] = new Scenario\Nation(0, '재야', '#ffffff', 0, 0); - foreach (Util::array_get($this->data['nation'],[]) as $idx=>$nationRaw) { - list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $nationRaw; + foreach (Util::array_get($data['nation'],[]) as $idx=>$rawNation) { + list($name, $color, $gold, $rice, $infoText, $tech, $type, $nationLevel, $cities) = $rawNation; $nationID = $idx+1; - + $this->nations[$nationID] = new Scenario\Nation( $nationID, $name, @@ -47,6 +56,52 @@ class Scenario{ $cities ); } + + $this->displomacy = Util::array_get($data['diplomacy'], []); + + + $this->generals = array_map(function($rawGeneral){ + while(count($rawGeneral) < 14){ + $rawGeneral[] = null; + } + + list( + $affinity, $name, $npcID, $nationID, $locatedCity, + $leadership, $power, $intel, $birth, $death, $ego, + $char, $text + ) = $rawGeneral; + + if(!key_exists($nationID, $this->nations)){ + $nationID = 0; + } + + $general = new Scenario\NPC( + $affinity, + $name, + $npcID, + $nationID, + $locatedCity, + $leadership, + $power, + $intel, + $birth, + $death, + $ego, + $char, + $text + ); + + $this->nations[$nationID]->addNPC($general); + }, Util::array_get($data['general'], [])); + + $this->initialEvents = array_map(function($rawEvent){ + return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1)); + }, Util::array_get($data['initialEvents'], [])); + + $this->events = array_map(function($rawEvent){ + return new \sammo\Event\EventHandler($rawEvent[0], array_slice($rawEvent, 1)); + }, Util::array_get($data['events'], [])); + } public function getScenarioIdx(){ @@ -54,19 +109,19 @@ class Scenario{ } public function getYear(){ - return Util::array_get($this->data['startYear']); + return $this->year; } public function getTitle(){ - return Util::array_get($this->data['title']); + return $this->title; } public function getNPC(){ - return Util::array_get($this->data['general']); + return $this->generals; } public function getNPCex(){ - return Util::array_get($this->data['general_ex']); + return $this->generalsEx; } public function getNation(){ @@ -145,6 +200,30 @@ class Scenario{ public function buildGame($env=[]){ //NOTE: 초기화가 되어있다고 가정함. + + foreach($this->nations as $id=>$nation){ + if($id == 0){ + continue; + } + + $nation->build($env); + } + CityHelper::flushCache(); + foreach($this->generals as $general){ + $general->build($env); + } + + if($env['useExtentedGeneral']){ + foreach($this->generalsEx as $general){ + $general->build($env); + } + } + + //TODO: 외교를 추가해야함 + foreach($this->initialEvents as $event){ + $event->tryRunEvent($env); + } + //TODO: event를 전역 handler에 등록해야함. } /** diff --git a/twe/sammo/Scenario/NPC.php b/twe/sammo/Scenario/NPC.php index 9f3514ef..1631110b 100644 --- a/twe/sammo/Scenario/NPC.php +++ b/twe/sammo/Scenario/NPC.php @@ -1,7 +1,64 @@ affinity = $affinity; + $this->name = $name; + $this->npcID = $npcID; + $this->nationID = $nationID; + $this->locatedCity = $locatedCity; + $this->leadership = $leadership; + $this->power = $power; + $this->intel = $intel; + $this->birth = $birth; + $this->death = $death; + $this->ego = $ego; + $this->text = $text; + + $char = \sammo\SpecCall($char); + if($char < 40){ + $this->charDomestic = $char; + } + else{ + $this->charWar = $char; + } + } + + public function build($env=[]){ } diff --git a/twe/sammo/Scenario/Nation.php b/twe/sammo/Scenario/Nation.php index d3680176..268d28d5 100644 --- a/twe/sammo/Scenario/Nation.php +++ b/twe/sammo/Scenario/Nation.php @@ -1,5 +1,7 @@ id = $id; + $this->name = $name; + $this->color = $color; + $this->gold = $gold; + $this->rice = $rice; + $this->infoText = $infoText; + $this->tech = $tech; + $this->type = $type; + $this->nationLevel = $nationLevel; + $this->cities = $cities; + + $this->capital = count($cities)>0?$cities[0]:null; } public function setID(int $id){ $this->id = $id; } - public function build($env=[]){ + public function addNPC(NPC $npc, bool $isExtend=false){ + if($isExtend){ + $this->generalsEx[] = $npc; + } + else{ + $this->generals[] = $npc; + } + + } + public function build($env=[]){ + $npc_cnt = count($this->generals); + if($env['useExtentedGeneral']){ + $npc_cnt += count($this->generalsEx); + } + + $cities = array_map(function($cityName){ + return \sammo\CityHelper::getCityByName($cityName)['id']; + }, $this->cities); + $capital = \sammo\CityHelper::getCityByName($this->capital)['id']; + + $type = \sammo\NationCharCall($this->$type); + + $db = DB::db(); + $otherNations = $db->queryFirstColumn('SELECT nation FROM nation'); + + $db->insert('nation', [ + 'nation'=>$this->id, + 'name'=>$this->name, + 'color'=>$this->color, + 'capital'=>$capital, + 'gennum'=>$npc_cnt, + 'gold'=>$this->gold, + 'rice'=>$this->rice, + 'bill'=>100, + 'rate'=>15, + 'scout'=>0, + 'war'=>0, + 'tricklimit'=>24, + 'surlimit'=>72, + 'scoutmsg'=>$this->infoText, + 'tech'=>$this->tech, + 'totaltech'=>$this->tech*$npc_cnt, + 'level'=>$this->level, + 'type'=>$type, + ]); + + $db->update('city', [ + 'nation'=>$this->id + ], 'city IN (%li)', $cities); + + + $diplomacy = []; + foreach($otherNations as $nation){ + $diplomacy[] = [ + 'me'=>$this->$id, + 'you'=>$nation, + 'state'=>2 + ]; + $diplomacy[] = [ + 'me'=>$nation, + 'you'=>$this->$id, + 'state'=>2 + ]; + } + $db->insert('diplomacy', $diplomacy); } } \ No newline at end of file