diff --git a/hwe/sammo/Command/Nation/che_물자원조.php b/hwe/sammo/Command/Nation/che_물자원조.php index 07408f8d..05147e4e 100644 --- a/hwe/sammo/Command/Nation/che_물자원조.php +++ b/hwe/sammo/Command/Nation/che_물자원조.php @@ -209,7 +209,7 @@ class che_물자원조 extends Command\NationCommand{ $db->update('nation', [ 'gold'=>$db->sqleval('gold - %i', $goldAmount), 'rice'=>$db->sqleval('rice - %i', $riceAmount), - 'surlimit'=>$db->sqleval('surlimit + %i', 12) + 'surlimit'=>$db->sqleval('surlimit + %i', $this->getPostReqTurn()) ], 'nation = %i', $nationID); $db->update('nation', [ diff --git a/hwe/sammo/Command/Nation/che_초토화.php b/hwe/sammo/Command/Nation/che_초토화.php new file mode 100644 index 00000000..a5812431 --- /dev/null +++ b/hwe/sammo/Command/Nation/che_초토화.php @@ -0,0 +1,235 @@ +arg === null){ + return false; + } + + if(!key_exists('destCityID', $this->arg)){ + return false; + } + if(CityConst::byID($this->arg['destCityID']) === null){ + return false; + } + $destCityID = $this->arg['destCityID']; + + $this->arg = [ + 'destCityID'=>$destCityID, + ]; + return true; + } + + protected function init(){ + $general = $this->generalObj; + + $env = $this->env; + + $this->setCity(); + $this->setNation(['surlimit', 'gold', 'rice', 'capital']); + $this->setDestCity($this->arg['destCityID'], null); + + $this->runnableConstraints=[ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::OccupiedDestCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::SuppliedDestCity(), + ConstraintHelper::ReqNationValue('capital', '수도', '!=', $this->destCity['city'], '수도입니다.'), + ConstraintHelper::ReqNationValue('surlimit', '제한 턴', '>', 0, '외교제한 턴이 남아있습니다.'), + ConstraintHelper::AllowDiplomacyStatus($this->generalObj->getNationID(), [ + 2, 7 + ], '평시에만 가능합니다.'), + ]; + } + + public function getCost():array{ + return [0, 0]; + } + + public function getPreReqTurn():int{ + return 0; + } + + public function getPostReqTurn():int{ + return 24; + } + + public function addTermStack():bool{ + $lastTurn = $this->getLastTurn(); + $commandName = $this->getName(); + + $nationStor = \sammo\KVStorage::getStorage(DB::db(), 'nation_env'); + $general = $this->getGeneral(); + $nationID = $general->getNationID(); + $nationStor->setValue("last천도Trial_{$nationID}", [$general->getVar('officer_level'), $general->getTurnTime()]); + + if($lastTurn->getCommand() != $commandName || $lastTurn->getArg() !== $this->arg){ + $this->setResultTurn(new LastTurn( + $commandName, + $this->arg, + 1, + $this->nation['capset'] + )); + return false; + } + + if($lastTurn->getSeq() < $this->nation['capset']){ + //NOTE: 최근에 천도, 증축이 일어났으면 리셋됨 + $this->setResultTurn(new LastTurn( + $commandName, + $this->arg, + 1, + $this->nation['capset'] + )); + return false; + } + + if($lastTurn->getTerm() < $this->getPreReqTurn()){ + $this->setResultTurn(new LastTurn( + $commandName, + $this->arg, + $lastTurn->getTerm() + 1, + $this->nation['capset'] + )); + return false; + } + + return true; + } + + public function getBrief():string{ + $commandName = $this->getName(); + $destCityName = CityConst::byID($this->arg['destCityID'])->name; + $josaUl = JosaUtil::pick($destCityName, '을'); + return "【{$destCityName}】{$josaUl} {$commandName}"; + } + + public function run():bool{ + if(!$this->isRunnable()){ + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + + $general = $this->generalObj; + $generalID = $general->getID(); + $generalName = $general->getName(); + $date = $general->getTurnTime($general::TURNTIME_HM); + + $destCity = $this->destCity; + $destCityID = $destCity['city']; + $destCityName = $destCity['name']; + + $nationID = $general->getNationID(); + $nationName = $this->nation['name']; + + $josaUl = JosaUtil::pick($destCityName, '을'); + + $logger = $general->getLogger(); + + + $general->addExperience(-$general->getVar('experience') * 0.1, false); + $general->addExperience(5 * ($this->getPreReqTurn() + 1)); + $general->addDedication(5 * ($this->getPreReqTurn() + 1)); + + $josaYi = JosaUtil::pick($generalName, '이'); + $josaYiNation = JosaUtil::pick($nationName, '이'); + + $amount = $destCity['pop'] / 5; + foreach(['agri', 'comm', 'secu'] as $cityRes){ + $cityResMax = "{$cityRes}_max"; + $amount *= (($destCity[$cityRes] - $destCity[$cityResMax] * 0.5) / $destCity[$cityResMax]) + 1; + } + $amount = Util::toInt($amount); + + $db->update('general', [ + 'experience'=>$db->sqleval('experience * 0.9') + ], 'nation = %i AND officer_level >= 5 AND no!=%i', $nationID, $generalID); + + $db->update('city', [ + 'trust'=>$db->sqleval('greatest(50, trust)'), + 'pop'=>$db->sqleval('greatest(pop_max*0.1, pop*0.2)'), + 'agri'=>$db->sqleval('greatest(agri_max*0.1, agri*0.2)'), + 'comm'=>$db->sqleval('greatest(comm_max*0.1, comm*0.2)'), + 'nation'=>0, + 'front'=>0, + 'conflict'=>'{}' + ], 'city=%i', $destCityID); + + $db->update('nation', [ + 'gold' => $db->sqleval('gold + %i', $amount), + 'rice' => $db->sqleval('rice + %i', $amount), + 'surlimit' => $db->sqleval('surlimit + %i', $this->getPostReqTurn()), + ], 'nation=%i', $nationID); + + \sammo\refreshNationStaticInfo(); + \sammo\SetNationFront($nationID); + + $logger->pushGeneralActionLog("{$destCityName}{$josaUl} 초토화했습니다. <1>$date"); + $logger->pushGeneralHistoryLog("{$destCityName}{$josaUl} 초토화 명령"); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$destCityName}{$josaUl} 초토화 명령"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$destCityName}{$josaUl} 초토화하였습니다."); + $logger->pushGlobalHistoryLog("【초토화】{$nationName}{$josaYiNation} {$destCityName}{$josaUl} 초토화하였습니다."); + + $general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); + $general->applyDB($db); + return true; + } + + public function getJSFiles(): array + { + return [ + 'js/defaultSelectCityByMap.js' + ]; + } + + + public function getForm(): string + { + ob_start(); +?> +
+선택된 도시를 초토화 시킵니다.
+도시가 공백지가 되며, 도시의 인구, 내정 상태에 따라 상당량의 국고가 확보됩니다.
+국가의 수뇌들은 명성을 잃습니다.
+목록을 선택하거나 도시를 클릭하세요.
+
+
+[ - //'che_초토화', + 'che_초토화', 'che_천도', 'che_증축', 'che_감축', diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index fca22115..e36be34c 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -2218,6 +2218,8 @@ class GeneralAI $gold = $general->getVar('gold'); $gold -= $this->fullLeadership * 3; + //TODO: 소유 쌀을 생각해야할 필요가 있다. + if($gold <= 0){ return null; }