From f06a8225d0c303439a9fce70e8078cec161d2f1b Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 11 Aug 2021 21:44:50 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9B=90=EC=A1=B0=20=EB=B0=9B=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20=EB=B6=88=EA=B0=80=EC=B9=A8=20=EC=A0=9C=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/b_npc_control.php | 1 + hwe/func_gamerule.php | 2 +- hwe/sammo/AutorunNationPolicy.php | 3 + hwe/sammo/Command/Nation/che_물자원조.php | 14 ++-- hwe/sammo/Command/Nation/che_불가침수락.php | 16 ++-- hwe/sammo/GeneralAI.php | 82 +++++++++++++++++++++ 6 files changed, 100 insertions(+), 18 deletions(-) diff --git a/hwe/b_npc_control.php b/hwe/b_npc_control.php index 9b79445b..aa15035d 100644 --- a/hwe/b_npc_control.php +++ b/hwe/b_npc_control.php @@ -91,6 +91,7 @@ $zeroPolicy = new AutorunNationPolicy($general, ($gameStor->autorun_user)['optio var availableGeneralActionPriorityItems = ; var btnHelpMessage = { + '불가침제의': '군주가 NPC이고, 타국에서 원조를 받았을 때,
세입(금/쌀) 대비 원조량에 따라 불가침제의를 합니다.', '선전포고': '군주가 NPC이고, 전쟁중이 아닐 때,
주변국중 하나를 골라 선포합니다.

선포 시점은 다음을 참고합니다.
- 인구율
- 도시내정률
- NPC전투장권장 금 충족률
- NPC전투장권장 쌀 충족률

국력이 낮은 국가를 조금 더 선호합니다.', '천도': '인구가 많은 곳을 찾아 천도를 시도합니다.
영토의 가운데를 선호합니다.

도시 인구가 충분하다면, 굳이 천도하지는 않습니다.', '유저장긴급포상': '금/쌀이 부족한 유저전투장에게 긴급하게 포상합니다.
국고가 권장량보다 적어지더라도 시도합니다.', diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index d289fa63..07d52f11 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -623,7 +623,7 @@ function updateNationState() $nation['nation'], $targetKillTurn ); - $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong'], 2); + $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong', 'npc'], 2); $chiefObj = null; $uniqueLotteryWeightList = []; diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index 079b2547..2641048d 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -28,6 +28,7 @@ class AutorunNationPolicy { static $NPC몰수 = 'NPC몰수'; // 군주 행동 + static $불가침제의 = '불가침제의'; static $선전포고 = '선전포고'; static $천도 = '천도'; @@ -35,6 +36,7 @@ class AutorunNationPolicy { //실제 행동 static public $defaultPriority = [ + '불가침제의', '선전포고', '천도', @@ -106,6 +108,7 @@ class AutorunNationPolicy { public $canNPC포상 = true; public $canNPC몰수 = true; + public $can불가침제의 = true; public $can선전포고 = true; public $can천도 = true; diff --git a/hwe/sammo/Command/Nation/che_물자원조.php b/hwe/sammo/Command/Nation/che_물자원조.php index 93b1aaa2..8e7cbef4 100644 --- a/hwe/sammo/Command/Nation/che_물자원조.php +++ b/hwe/sammo/Command/Nation/che_물자원조.php @@ -10,6 +10,7 @@ use \sammo\{ GameUnitConst, Command, Json, + KVStorage, StringUtil }; @@ -91,7 +92,7 @@ class che_물자원조 extends Command\NationCommand{ protected function initWithArg() { $destNationID = $this->arg['destNationID']; - $this->setDestNation($destNationID, ['gold', 'rice', 'surlimit', 'aux']); + $this->setDestNation($destNationID, ['gold', 'rice', 'surlimit']); [$goldAmount, $riceAmount] = $this->arg['amountList']; $limit = $this->nation['level'] * GameConst::$coefAidAmount; @@ -223,12 +224,10 @@ class che_물자원조 extends Command\NationCommand{ $destNationLogger = new ActionLogger(0, $destChiefID, $year, $month); $destNationLogger->pushNationalHistoryLog("{$nationName}{$josaRoSrc}부터 금{$goldAmountText} 쌀{$riceAmountText}을 지원 받음"); - - $destAux = Json::decode($this->destNation['aux']); - if(!key_exists('recv_assist', $destAux)){ - $destAux['recv_assist'] = []; - } - $destAux['recv_assist'][$nationID] = $destAux['recv_assist'][$nationID]??0 + $goldAmount + $riceAmount; + $destNationStor = KVStorage::getStorage(DB::db(), $destNationID, 'nation_env'); + $destRecvAssist = $destNationStor->getValue('recv_assist')??[]; + $destRecvAssist["n{$nationID}"] = [$nationID, ($destRecvAssist["n{$nationID}"][1]??0) + $goldAmount + $riceAmount]; + $destNationStor->setValue('recv_assist', $destRecvAssist); $db->update('nation', [ 'gold'=>$db->sqleval('gold - %i', $goldAmount), @@ -239,7 +238,6 @@ class che_물자원조 extends Command\NationCommand{ $db->update('nation', [ 'gold'=>$db->sqleval('gold + %i', $goldAmount), 'rice'=>$db->sqleval('rice + %i', $riceAmount), - 'aux'=>Json::encode($destAux) ], 'nation = %i', $destNationID); $general->addExperience(5); diff --git a/hwe/sammo/Command/Nation/che_불가침수락.php b/hwe/sammo/Command/Nation/che_불가침수락.php index b31c1ba8..74972570 100644 --- a/hwe/sammo/Command/Nation/che_불가침수락.php +++ b/hwe/sammo/Command/Nation/che_불가침수락.php @@ -26,6 +26,7 @@ use function \sammo\GetImageUR; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\Json; +use sammo\KVStorage; class che_불가침수락 extends Command\NationCommand { @@ -188,11 +189,12 @@ class che_불가침수락 extends Command\NationCommand $destNationID = $destNation['nation']; $destNationName = $destNation['name']; - $destNationAux = Json::decode($db->queryFirstField('SELECT aux FROM nation WHERE nation = %i', $destNationID)); - if(!key_exists('resp_assist', $destNationAux)){ - $destNationAux['resp_assist'] = []; - } - $destNationAux['resp_assist'][$nationID] = $destNationAux['recv_assist'][$nationID]??0; + $destNationStor = KVStorage::getStorage(DB::db(), $destNationID, 'nation_env'); + $destRecvAssist = $destNationStor->getValue('recv_assist')??[]; + $destRespAssist = $destNationStor->getValue('resp_assist')??[]; + + $destRespAssist["n{$nationID}"] = [$nationID, $destRecvAssist["n{$nationID}"][1]??0]; + $destNationStor->setValue('resp_assist', $destRespAssist); $year = $this->arg['year']; $month = $this->arg['month']; @@ -203,10 +205,6 @@ class che_불가침수락 extends Command\NationCommand $currentMonth = $env['year'] * 12 + $env['month'] - 1; $reqMonth = $year * 12 + $month - 1; - $db->update('nation', [ - 'aux'=>Json::encode($destNationAux) - ], 'nation=%i', $destNationID); - $db->update( 'diplomacy', [ diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index c32d4586..511cf223 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -1712,6 +1712,88 @@ class GeneralAI return $cmd; } + // 군주 행동 + protected function do불가침제의(LastTurn $lastTurn): ?NationCommand + { + $general = $this->general; + + if($general->getVar('officer_level') < 12){ + return null; + } + + $nation = $this->nation; + $nationID = $nation['nation']; + + $nationStor = KVStorage::getStorage(DB::db(), $nationID, 'nation_env'); + $recvAssist = $nationStor->getValue('recv_assist')??[]; + $respAssist = $nationStor->getValue('resp_assist')??[]; + $respAssistTry = $nationStor->getValue('resp_assist_try')??[]; + + $yearMonth = Util::joinYearMonth($this->env['year'], $this->env['month']); + + $candidateList = []; + foreach($recvAssist as [$candNationID, $amount]){ + $amount -= $respAssist["n{$candNationID}"][1]??0; + if($amount <= 0){ + continue; + } + if(key_exists($candNationID, $this->warTargetNation)){ + continue; + } + if(($respAssistTry["n{$candNationID}"][1]??0) >= $yearMonth - 8){ + continue; + } + $candidateList[$candNationID] = $amount; + } + + if(!$candidateList){ + return null; + } + + $cityList = $this->supplyCities; + + if (!$cityList) { + return null; + } + + $goldIncome = getGoldIncome($nation['nation'], $nation['level'], 15, $nation['capital'], $nation['type'], $cityList); + $riceIncome = getRiceIncome($nation['nation'], $nation['level'], 15, $nation['capital'], $nation['type'], $cityList); + $wallIncome = getWallIncome($nation['nation'], $nation['level'], 15, $nation['capital'], $nation['type'], $cityList); + $income = $goldIncome + $riceIncome + $wallIncome; + + arsort($candidateList); + $destNationID = null; + $diplomatMonth = 0; + foreach($candidateList as $candNationID => $amount){ + if($amount * 4 < $income){ + break; + } + $destNationID = $candNationID; + $diplomatMonth = 24 * $amount / $income; + break; + } + + if($destNationID === null){ + return null; + } + + + [$targetYear, $targetMonth] = Util::parseYearMonth($yearMonth + $diplomatMonth); + + $cmd = buildNationCommandClass('che_불가침제의', $this->general, $this->env, $lastTurn, [ + 'destNationID' => $destNationID, + 'year' => $targetYear, + 'month' => $targetMonth, + ]); + if(!$cmd->hasFullConditionMet()){ + return null; + } + + $respAssistTry["n{$destNationID}"] = [$destNationID, $yearMonth]; + $nationStor->setValue('resp_assist_try', $respAssistTry); + + return $cmd; + } // 군주 행동 protected function do선전포고(LastTurn $lastTurn): ?NationCommand