From fad29e3faf8dee4dff7ef7e69ba402c226c766fd Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 28 Mar 2018 06:05:16 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=BC=EC=A1=B1=20=EC=B9=A8?= =?UTF-8?q?=EC=9E=85=20=EC=9D=BC=EB=B6=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twe/sammo/Event/Action/RaiseInvader.php | 90 +++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/twe/sammo/Event/Action/RaiseInvader.php b/twe/sammo/Event/Action/RaiseInvader.php index c23cb5ef..9395ecc0 100644 --- a/twe/sammo/Event/Action/RaiseInvader.php +++ b/twe/sammo/Event/Action/RaiseInvader.php @@ -9,8 +9,8 @@ use sammo\DB; * 양수 : 정해진 값. [절대값] * 음수 : 합산(장수 등), 혹은 평균(기술 등)을 나누어 적용한 값 [상대값] * - * event_1.php, 센 이민족 : npcEachCount = -3.5, specAvg = 195, specDist = 5, tech = 15000, dex = 450000 - * event_2.php, 약한 이민족 : npcEachCount = -3.5, specAvg = 150, specDist = 20, tech = -1, dex = 0 + * event_1.php, 센 이민족 : npcEachCount = -0.5, specAvg = 195, specDist = 5, tech = 15000, dex = 450000 + * event_2.php, 약한 이민족 : npcEachCount = -0.5, specAvg = 150, specDist = 20, tech = -1, dex = 0 * event_3.php, 엄청 약한 이민족 : npcEachCount = 100, specAvg = 50, specDist = 5, tech = 0, dex = 0 */ class RaiseInvader extends sammo\Event\Action{ @@ -20,16 +20,69 @@ class RaiseInvader extends sammo\Event\Action{ private $tech; private $dex; - public function __construct($npcEachCount = -3.5, int $specAvg = 150, int $specDist = 20, int $tech = -1, int $dex = 0){ + const INVADER_LIST = [ + '강'=>63, + '저'=>64, + '흉노'=>65, + '남만'=>66, + '산월'=>67, + '오환'=>68, + '왜'=>69 + ]; + + public function __construct( + $npcEachCount = -0.5, + int $specAvg = 150, + int $specDist = 20, + int $tech = -1, + int $dex = 0 + ){ $this->npcEachCount = $npcEachCount; $this->specAvg = $specAvg; $this->specDist = $specDist; $this->tech = $tech; $this->dex = $dex; + + if($specDist < 0){ + throw new \InvalidArgumentException('specDist는 음수를 지원하지 않습니다.'); + } } - private function calcNpcEachCount(){ + private function moveCapital(){ + $cities = array_map(function ($value) { + return $value; + }, INVADER_LIST); + $db = DB::db(); + + + foreach($db->queryFirstColumn('SELECT capital, nation from nation WHERE capital in (%li)', $cities) as $row){ + list($oldCapital, $nation) = $row; + $newCapital = $db->queryFirstRow('SELECT city from city where nation=%i and city !=%i \ + order by rand() limit 1', $nation, $oldCapital); + $db->update('nation', ['capital'=>$newCapital], 'nation=%i', $nation); + + $db->update('generals', ['city'=>$newCapital], 'nation=%i and city=%i', $nation, $city); + } + + $generals = []; + foreach($db->query('SELECT gen1, gen2, gen3 from city where city in (%li)', $cities) as $city){ + list($gen1, $gen2, $gen3) = $city; + if($gen1 != 0) $generals[]=$gen1; + if($gen2 != 0) $generals[]=$gen2; + if($gen3 != 0) $generals[]=$gen3; + } + + $db->update('general', [ + 'level'=>1 + ], 'no in (%li)', $generals); + + $db->update('city', [ + 'gen1'=>0, + 'gen2'=>0, + 'gen3'=>0, + 'nation'=>0 + ], 'city in (%li)', $cities); } public function run($env=null){ @@ -37,9 +90,36 @@ class RaiseInvader extends sammo\Event\Action{ $npcEachCount = $this->npcEachCount; if($npcEachCount < 0){ - $npcEachCount = $db->queryFirstField('SELECT count(no) from general where npc<5'); + $npcEachCount = + $db->queryFirstField('SELECT count(no) from general where npc<5') / count(self::INVADER_LIST); $npcEachCount /= -1 * $this->npcEachCount; } + + $specAvg = $this->specAvg; + if($specAvg < 0){ + $specAvg = $db->queryFirstField('SELECT avg(sum(`leader` + `power` + `intel`)) from general where npc<5'); + $specAvg /= -1 * $this->specAvg; + } + + $tech = $this->tech; + if($tech < 0){ + $tech = $db->queryFirstField("SELECT avg(tech) from nation where `level`>0"); + $tech /= -1 * $this->tech; + } + + $dex = $this->dex; + if($dex < 0){ + $dex = $db->queryFirstField("SELECT avg(dex0 + dex10 + dex20 + dex30 + dex40)/5 from nation where `level`>0"); + $dex /= -1 * $this->dex; + } + + $this->moveCapital(); + //TODO:국가를 만들고 + //TODO:장수를 세팅하고 + //TODO:외교를 설정한다. + + //TODO: 시나리오 구현 후 마무리. + return [__CLASS__, 'NYI']; } } \ No newline at end of file