From c8add882f888b548b09fef008ebd0e22e731d0a4 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 13 Oct 2018 01:44:20 +0900 Subject: [PATCH] =?UTF-8?q?NPC=20=EC=88=98=EB=87=8C=ED=84=B4=20=EC=A0=95?= =?UTF-8?q?=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/GeneralAI.php | 60 ++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 294f8a2b..de944b18 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -369,22 +369,16 @@ class GeneralAI{ } public function chooseNationTurn($command, $arg):array{ - $general = $this->getGeneralObj(); - $city = $this->city; - $nation = $this->nation; + $generalObj = $this->getGeneralObj(); + //NOTE: 수뇌 턴에서는 general과 city이름의 충돌 가능성이 있음 $env = $this->env; - $cityID = $general->getCityID(); - $nationID = $general->getNationID(); - - $genType = $this->genType; - $leadership = $this->leadership; - $power = $this->power; - $intel = $this->intel; + $cityID = $generalObj->getCityID(); + $nationID = $generalObj->getNationID(); $db = DB::db(); - if($general->getVar('npc') == 5){ + if($generalObj->getVar('npc') == 5){ return [$command, $arg]; } @@ -392,12 +386,54 @@ class GeneralAI{ return [$command, $arg]; } - if($general->getVar('level') == 12 && $this->dipState == self::d평화 && !$this->attackable){ + if($generalObj->getVar('level') == 12 && $this->dipState == self::d평화 && !$this->attackable){ $targetNationID = $this->findWarTarget(); if($targetNationID !== null){ return ['che_선전포고', ['destNationID'=>$targetNationID]]; } } + + $cityList = []; + $frontCity = []; + foreach($db->query('SELECT * FROM city WHERE nation = %i',$nationID) as $city){ + $cityList[$ownCity['city']] = $ownCity; + if($city['front'] > 0){ + $frontCity[$city['city']] = $city['front']; + } + } + + if(!key_exists($cityID, $cityList)){ + //수뇌가 아국에 없음 + return ['휴식', null]; + } + + $generalList = []; + foreach($db->query('SELECT no, npc, leader, power, intel, city, nation, level, gold, rice, troop, experience, dedication, killturn, injury, crew, crewtype, train, atmos, gold, rice FROM general WHERE nation = %i AND no != %i', $nationID, $generalObj->getID()) as $general){ + $generalList[$general['no']] = $general; + } + + //바깥에 있는 장수가 있나? + $outerGenerals = []; + foreach($generalList as $general){ + if(!key_exists($general['city'], $cityList)){ + $score = $general['npc'] < 2? 5 : 1; + $score *= sqrt($general['leader'] + $general['power'] + $general['intel']); + $outerGenerals[$general['no']] = $score; + } + } + if($outerGenerals){ + return ['che_발령', [ + 'destGeneralID' => Util::choiceRandomUsingWeight($outerGenerals), + 'destCityID' => Util::choiceRandom(array_keys($frontCity)) + ]]; + } + + + + + + + return [$command, $arg]; }