From d9de5a39e00d62f0bc35c3e1ea926053c7543818 Mon Sep 17 00:00:00 2001 From: hide_d Date: Thu, 29 Mar 2018 00:27:42 +0900 Subject: [PATCH] =?UTF-8?q?Scenario=20build=201=EC=B0=A8=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20-=20NPC=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20-=20=EC=83=9D=EC=84=B1=20=EC=95=88?= =?UTF-8?q?=EB=90=9C=20=EC=9E=A5=EC=88=98=EB=8A=94=20event=EB=A1=9C=20?= =?UTF-8?q?=EB=84=98=EA=B9=80=20-=20=EC=99=84=EB=A3=8C=EB=90=9C=20event=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=ED=95=98=EB=8A=94=20action=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/sammo/Event/Action/DeleteEvent.php | 22 +++++ twe/sammo/Event/Action/RegNPC.php | 46 +++++++++ twe/sammo/Scenario.php | 130 ++++++++++++++++++++++--- twe/sammo/Scenario/NPC.php | 105 +++++++++++++++++++- 4 files changed, 286 insertions(+), 17 deletions(-) create mode 100644 twe/sammo/Event/Action/DeleteEvent.php create mode 100644 twe/sammo/Event/Action/RegNPC.php diff --git a/twe/sammo/Event/Action/DeleteEvent.php b/twe/sammo/Event/Action/DeleteEvent.php new file mode 100644 index 00000000..3483ca4f --- /dev/null +++ b/twe/sammo/Event/Action/DeleteEvent.php @@ -0,0 +1,22 @@ +delete('event', 'id = %i', $eventID); + return [__CLASS__, $db->affectedRows()]; + } + +} \ No newline at end of file diff --git a/twe/sammo/Event/Action/RegNPC.php b/twe/sammo/Event/Action/RegNPC.php new file mode 100644 index 00000000..cb6208eb --- /dev/null +++ b/twe/sammo/Event/Action/RegNPC.php @@ -0,0 +1,46 @@ +npc = new \sammo\Scenario\NPC( + $affinity, + $name, + $pictureID, + $nationID, + $locatedCity, + $leadership, + $power, + $intel, + $birth, + $death, + $ego, + $char, + $text + ); + } + + public function run($env=null){ + $result = $this->npc->build($env); + return [__CLASS__, $result]; + } + +} \ No newline at end of file diff --git a/twe/sammo/Scenario.php b/twe/sammo/Scenario.php index b7962dd7..ba5d9faf 100644 --- a/twe/sammo/Scenario.php +++ b/twe/sammo/Scenario.php @@ -20,6 +20,8 @@ class Scenario{ private $generals; private $generalsEx; + private $tmpGeneralQueue = []; + private $initialEvents; private $events; @@ -66,7 +68,7 @@ class Scenario{ } list( - $affinity, $name, $npcID, $nationID, $locatedCity, + $affinity, $name, $pictureID, $nationID, $locatedCity, $leadership, $power, $intel, $birth, $death, $ego, $char, $text ) = $rawGeneral; @@ -75,10 +77,12 @@ class Scenario{ $nationID = 0; } + $this->tmpGeneralQueue[$name] = $rawGeneral; + $general = new Scenario\NPC( $affinity, $name, - $npcID, + $pictureID, $nationID, $locatedCity, $leadership, @@ -94,12 +98,52 @@ class Scenario{ $this->nations[$nationID]->addNPC($general); }, Util::array_get($data['general'], [])); + $this->generalsEx = array_map(function($rawGeneral){ + while(count($rawGeneral) < 14){ + $rawGeneral[] = null; + } + + list( + $affinity, $name, $pictureID, $nationID, $locatedCity, + $leadership, $power, $intel, $birth, $death, $ego, + $char, $text + ) = $rawGeneral; + + if(!key_exists($nationID, $this->nations)){ + $nationID = 0; + } + + $this->tmpGeneralQueue[$name] = $rawGeneral; + + $general = new Scenario\NPC( + $affinity, + $name, + $pictureID, + $nationID, + $locatedCity, + $leadership, + $power, + $intel, + $birth, + $death, + $ego, + $char, + $text + ); + + $this->nations[$nationID]->addNPC($general, true); + }, Util::array_get($data['generalEx'], [])); + $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)); + //event는 여기서 풀지 않는다. + return [ + 'cond' => $rawEvent[0], + 'action' => array_slice($rawEvent, 1) + ]; }, Util::array_get($data['events'], [])); } @@ -125,6 +169,7 @@ class Scenario{ } public function getNation(){ + return $this->nations; $nationsRaw = Util::array_get($this->data['nation']); if(!$nationsRaw){ @@ -197,33 +242,92 @@ class Scenario{ ]; } + private function buildGenerals($env){ + $remainGenerals = []; + foreach($this->generals as $general){ + if($general->build($env)){ + continue; + } + + $rawGeneral = $this->tmpGeneralQueue[$general->$name]; + $birth = $general->birth; + if(!key_exists($birth, $remainGenerals)){ + $remainGenerals[$birth] = []; + } + $remainGenerals[$birth][] = array_merge(['RegNPC'], $rawGeneral); + } + + if($env['useExtentedGeneral']){ + foreach($this->generalsEx as $general){ + if($general->build($env)){ + continue; + } + } + + $rawGeneral = $this->tmpGeneralQueue[$general->$name]; + $birth = $general->birth; + if(!key_exists($birth, $remainGenerals)){ + $remainGenerals[$birth] = []; + } + $remainGenerals[$birth][] = array_merge(['RegNPC'], $rawGeneral); + } + return $remainGenerals; + } + + private function buildDiplomacy($env){ + $db = DB::db(); + foreach($this->diplomacy as $diplomacy){ + list($me, $you, $state, $remain) = $diplomacy; + $db->update('diplomacy', [ + 'state'=>$state, + 'remain'=>$remain + ], '(me = %i_me AND you = %i_you) OR (me = %i_you AND you = %i_me)', [ + 'me'=>$me, + 'you'=>$you + ]); + } + } + public function buildGame($env=[]){ //NOTE: 초기화가 되어있다고 가정함. + /* + env로 사용된 것들, + 게임 변수 : year, month + game 테이블 변수 : startyear, year, month, genius, turnterm, show_img_level, extend, fiction, npcmode + install 변수 : npcmode, show_img_level, extend, scenario, fiction + */ + + $db = DB::db(); foreach($this->nations as $id=>$nation){ if($id == 0){ continue; } - + $nation->build($env); } CityHelper::flushCache(); - foreach($this->generals as $general){ - $general->build($env); + + $remainGenerals = $this->buildGenerals($env); + + foreach($remainGenerals as $birth=>$actions){ + $targetYear = $birth + 14;//FIXME: 14가 어디서 튀어나왔나? + + $actions[] = ['DeleteEvent']; + $this->events[] = [ + 'cond'=>['date', '==', $targetYear, '1'], + 'action'=>$actions + ]; } - if($env['useExtentedGeneral']){ - foreach($this->generalsEx as $general){ - $general->build($env); - } - } + $this->buildDiplomacy($env); - //TODO: 외교를 추가해야함 foreach($this->initialEvents as $event){ $event->tryRunEvent($env); } - //TODO: event를 전역 handler에 등록해야함. + + $db->insert('event', $this->events); } /** diff --git a/twe/sammo/Scenario/NPC.php b/twe/sammo/Scenario/NPC.php index 1631110b..e4dff203 100644 --- a/twe/sammo/Scenario/NPC.php +++ b/twe/sammo/Scenario/NPC.php @@ -8,7 +8,7 @@ class NPC{ public $affinity; public $name; - public $npcID; + public $pictureID; public $nationID; public $locatedCity; public $leadership; @@ -24,13 +24,13 @@ class NPC{ public function __construct( int $affinity, string $name, - int $npcID, + int $pictureID, int $nationID, string $locatedCity, int $leadership, int $power, int $intel, - int $birth = 150, + int $birth = 160, int $death = 300, string $ego = null, string $char = null, @@ -38,7 +38,7 @@ class NPC{ ){ $this->affinity = $affinity; $this->name = $name; - $this->npcID = $npcID; + $this->pictureID = $pictureID; $this->nationID = $nationID; $this->locatedCity = $locatedCity; $this->leadership = $leadership; @@ -60,6 +60,103 @@ class NPC{ public function build($env=[]){ + //scenario에 life==1인 경우 수명 제한이 없어지는 모양. + $nationID = $this->nationID; + if(!\sammo\getNationStaticInfo($nationID)){ + $nationID = 0; + }; + $year = $env['year']; + $month = $env['month']; + $age = $year - $this->birth; + + if($this->death < $year){ + return true; //죽었으니 넘어간다. + } + if($age < 14){ + return false; //예약. + } + + $db = DB::db(); + + if($age == 14 && $month == 1){//FIXME: 14가 어디서 튀어나왔나? + \sammo\pushHistory(["●1월:$name(이)가 성인이 되어 등장했습니다."]); + } + + if($this->ego == null){ + $this->ego = mt_rand(0, 9);//TODO: 나중에 성격을 따로 분리할 경우 클래스를 참조. + } + + $name = 'ⓝ'.$this->name; + + if($env['show_img_level'] == 3 && $pictureID > 0){ + $picture = "{$pictureID}.jpg"; + } + else{ + $picture = 'default.jpg'; + } + + $city = $this->city; + if($city === null){ + if($nationID == 0){ + $city = Util::choiceRandom(CityHelper::getAllCities())['id']; + } + else{ + $city = Util::choiceRandom(CityHelper::getAllNationCities($nationID))['id']; + } + } + + $experience = $age * 100; + $dedication = $age * 100; + $level = $nationID?1:0; + + $turntime = \sammo\getRandTurn($env['turnterm']); + + $killturn = ($this->death - $year) * 12 + mt_rand(0, 11); + + $specage = $age + 1; + $specage2 = $age + 1; + + + $db->insert('general',[ + 'npcid'=>$db->sqleval('max(npcid)+1'), + 'npc'=>2, + 'npc_org'=>2, + 'affinity'=>$this->affinity, + 'name'=>$name, + 'picture'=>$picture, + 'nation'=>$nationID, + 'city'=>$city, + 'leader'=>$this->leader, + 'power'=>$this->power, + 'intel'=>$this->intel, + 'experience'=>$experience, + 'dedication'=>$dedication, + 'level'=>$level, + 'gold'=>1000, + 'rice'=>1000, + 'crew'=>0, + 'crewtype'=>0, + 'train'=>0, + 'atmos'=>0, + 'weap'=>0, + 'book'=>0, + 'horse'=>0, + 'turntime'=>$turntime, + 'killturn'=>$killturn, + 'age'=>$age, + 'belong'=>1, + 'personal'=>$this->ego, + 'special'=>$this->charDomestic, + 'specage'=>$specage, + 'special2'=>$this->charWar, + 'specage2'=>$specage2, + 'npcmsg'=>$this->text, + 'makelimit'=>0, + 'bornyear'=>$this->birth, + 'deadyear'=>$this->death + ]); + + return true; //생성되었다. } } \ No newline at end of file