From 365131bdb68ba3146138a6c6cd85a2830d328c72 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sat, 11 Mar 2023 20:43:11 +0900 Subject: [PATCH] =?UTF-8?q?feat,=20refac:=20=EA=B5=AD=EA=B0=80=EB=B3=84=20?= =?UTF-8?q?NPC=20=EC=A0=9C=EA=B3=B5=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20Event?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func_gamerule.php | 58 ------------ .../Event/Action/ProvideNPCTroopLeader.php | 93 +++++++++++++++++++ 2 files changed, 93 insertions(+), 58 deletions(-) create mode 100644 hwe/sammo/Event/Action/ProvideNPCTroopLeader.php diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index ec20b72c..a8d2f143 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -553,16 +553,12 @@ function updateNationState() $month = $admin['month']; $startYear = $admin['startyear']; - $assemblerCnts = []; $nationCityCounts = []; foreach($db->queryAllLists('SELECT nation, count(*) FROM city WHERE LEVEL>=4 GROUP BY nation') as [$nationID, $cityCnt]){ $nationCityCounts[$nationID] = $cityCnt; } - foreach ($db->queryAllLists('SELECT nation,count(no) FROM general WHERE npc = 5 GROUP BY nation') as [$nationID, $assemblerCnt]) { - $assemblerCnts[$nationID] = $assemblerCnt; - }; $nationLevelByCityCnt = [ 0, //방랑군 @@ -747,60 +743,6 @@ function updateNationState() } } } - - $assemblerCnt = $assemblerCnts[$nation['nation']] ?? 0; - $maxAssemblerCnt = [ - 1 => 0, - 2 => 1, - 3 => 3, - 4 => 4, - 5 => 6, - 6 => 7, - 7 => 9 - ][$nationlevel] ?? 0; - - if ($assemblerCnt < $maxAssemblerCnt) { - $lastAssemblerID = $gameStor->assembler_id ?? 0; - - $troopLeaderRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( - UniqueConst::$hiddenSeed, - 'troopLeader', - $year, - $month, - $nationID - ))); - - while ($assemblerCnt < $maxAssemblerCnt) { - $lastAssemblerID += 1; - $npcObj = new Scenario\GeneralBuilder( - $troopLeaderRng, - sprintf('부대장%4d', $lastAssemblerID), - false, - null, - $nation['nation'] - ); - $npcObj->setAffinity(999)->setStat(10, 10, 10) - ->setSpecialSingle('척사')->setEgo('che_은둔') - ->setKillturn(70)->setGoldRice(0, 0) - ->setNPCType(5)->fillRemainSpecAsZero($admin); - $npcObj->build($admin); - $npcID = $npcObj->getGeneralID(); - - $db->insert('troop', [ - 'troop_leader' => $npcID, - 'name' => $npcObj->getGeneralName(), - 'nation' => $nation['nation'], - ]); - $db->update('general', [ - 'troop' => $npcID - ], 'no=%i', $npcID); - - $cmd = buildGeneralCommandClass('che_집합', General::createGeneralObjFromDB($npcID), $admin); - _setGeneralCommand($cmd, iterator_to_array(Util::range(GameConst::$maxTurn))); - $assemblerCnt += 1; - $gameStor->assembler_id = $lastAssemblerID; - } - } } pushGlobalHistoryLog($history, $admin['year'], $admin['month']); } diff --git a/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php new file mode 100644 index 00000000..42773c8e --- /dev/null +++ b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php @@ -0,0 +1,93 @@ + 0, + 2 => 1, + 3 => 3, + 4 => 4, + 5 => 6, + 6 => 7, + 7 => 9 + ]; + + public function run(array $env) + { + $db = DB::db(); + $gameStor = KVStorage::getStorage($db, 'game_env'); + + $NPCTroopLeaderCntByNation = []; + foreach ($db->queryAllLists('SELECT nation,count(no) FROM general WHERE npc = 5 GROUP BY nation') as [$nationID, $NPCTroopLeaderCnt]) { + $NPCTroopLeaderCntByNation[$nationID] = $NPCTroopLeaderCnt; + }; + + $year = $env['year']; + $month = $env['month']; + + foreach ($db->query('SELECT nation,name,level,tech,aux FROM nation') as $nation) { + $nationID = $nation['nation']; + $maxNPCTroopLeaderCnt = self::MaxNPCTroopLeaderCnt[$nation['level']]; + $NPCTroopLeaderCnt = $NPCTroopLeaderCntByNation[$nationID] ?? 0; + + if ($NPCTroopLeaderCnt >= $maxNPCTroopLeaderCnt) { + continue; + } + + $lastNPCTroopLeaderID = $gameStor->lastNPCTroopLeaderID ?? 0; + + $troopLeaderRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'troopLeader', + $year, + $month, + $nationID + ))); + + while ($NPCTroopLeaderCnt < $maxNPCTroopLeaderCnt) { + $lastNPCTroopLeaderID += 1; + $npcObj = new \sammo\Scenario\GeneralBuilder( + $troopLeaderRng, + sprintf('부대장%4d', $lastNPCTroopLeaderID), + false, + null, + $nation['nation'] + ); + $npcObj->setAffinity(999)->setStat(10, 10, 10) + ->setSpecialSingle('척사')->setEgo('che_은둔') + ->setKillturn(70)->setGoldRice(0, 0) + ->setNPCType(5)->fillRemainSpecAsZero($env); + $npcObj->build($env); + $npcID = $npcObj->getGeneralID(); + + $db->insert('troop', [ + 'troop_leader' => $npcID, + 'name' => $npcObj->getGeneralName(), + 'nation' => $nation['nation'], + ]); + $db->update('general', [ + 'troop' => $npcID + ], 'no=%i', $npcID); + + $cmd = buildGeneralCommandClass('che_집합', General::createGeneralObjFromDB($npcID), $env); + _setGeneralCommand($cmd, iterator_to_array(Util::range(GameConst::$maxTurn))); + $NPCTroopLeaderCnt += 1; + $gameStor->lastNPCTroopLeaderID = $lastNPCTroopLeaderID; + } + } + } +}