From 9121533b9385143cbd42e9e14d70fc0a1b138b0b Mon Sep 17 00:00:00 2001 From: Hide_D Date: Fri, 24 Mar 2023 02:43:07 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B5=AD=EA=B0=80=20=EC=8A=B9=EA=B8=89?= =?UTF-8?q?=EC=9D=84=20Event=EB=A1=9C=20=EB=96=BC=EB=82=B4=EC=96=B4?= =?UTF-8?q?=EC=95=BC=20=ED=95=A8=20-=20=EB=B6=80=EB=8C=80=EC=9E=A5=20?= =?UTF-8?q?=EC=A7=80=EA=B8=89=EB=B3=B4=EB=8B=A4=20=EC=95=9E=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func_gamerule.php | 205 ----------------- hwe/sammo/Event/Action/UpdateNationLevel.php | 225 +++++++++++++++++++ hwe/sammo/GameConstBase.php | 1 + 3 files changed, 226 insertions(+), 205 deletions(-) create mode 100644 hwe/sammo/Event/Action/UpdateNationLevel.php diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 728fb9dc..68490651 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -423,8 +423,6 @@ function postUpdateMonthly(RandUtil $rng) if ($admin['year'] >= $admin['startyear'] + 2) { checkWander($rng); } - // 작위 업데이트 - updateNationState(); updateGeneralNumber(); refreshNationStaticInfo(); // 천통여부 검사 @@ -467,209 +465,6 @@ function checkWander(RandUtil $rng) } } -function updateNationState() -{ - $db = DB::db(); - $gameStor = KVStorage::getStorage($db, 'game_env'); - - $admin = $gameStor->getValues(['killturn', 'year', 'month', 'fiction', 'startyear', 'show_img_level', 'turnterm', 'turntime']); - $year = $admin['year']; - $month = $admin['month']; - $startYear = $admin['startyear']; - - - $nationCityCounts = []; - foreach($db->queryAllLists('SELECT nation, count(*) FROM city WHERE LEVEL>=4 GROUP BY nation') as [$nationID, $cityCnt]){ - $nationCityCounts[$nationID] = $cityCnt; - } - - - $nationLevelByCityCnt = [ - 0, //방랑군 - 1, //호족 - 2, //군벌 - 5, //주자사 - 8, //주목 - 11, //공 - 16, //왕 - 21, //황제 - ]; - - foreach ($db->query('SELECT nation,name,level,tech,aux FROM nation') as $nation) { - //TODO: level이 진관수이소중대특 체계를 벗어날 수 있음 - $nationID = $nation['nation']; - $cityCnt = $nationCityCounts[$nationID] ?? 0; - - /** @var int */ - $nationlevel = 0; - foreach($nationLevelByCityCnt as $cmpNationLevel => $cmpCityCnt){ - if($cityCnt < $cmpCityCnt){ - break; - } - $nationlevel = $cmpNationLevel; - } - - if ($nationlevel > $nation['level']) { - $levelDiff = $nationlevel - $nation['level']; - $oldLevel = $nation['level']; - $nation['level'] = $nationlevel; - - $updateVals = [ - 'level' => $nationlevel, - 'gold' => $db->sqleval('gold + %i', $nationlevel * 1000), - 'rice' => $db->sqleval('rice + %i', $nationlevel * 1000), - ]; - - $nationName = $nation['name']; - $lordName = $db->queryFirstField('SELECT name FROM general WHERE nation = %i AND officer_level = 12', $nationID); - - $oldNationLevelText = getNationLevel($oldLevel); - $nationLevelText = getNationLevel($nationlevel); - - $logger = new ActionLogger(0, $nationID, $year, $month, false); - $josaYi = JosaUtil::pick($lordName, '이'); - - switch ($nationlevel) { - case 7: //황제 - $josaRo = JosaUtil::pick($nationLevelText, '로'); - $logger->pushGlobalHistoryLog("【작위】{$nationName} {$oldNationLevelText} {$lordName}{$josaYi} {$nationLevelText}{$josaRo} 옹립되었습니다."); - $logger->pushNationalHistoryLog("{$nationName} {$oldNationLevelText} {$lordName}{$josaYi} {$nationLevelText}{$josaRo} 옹립"); - $auxVal = Json::decode($nation['aux']); - $auxVal['can_국기변경'] = 1; - $auxVal['can_국호변경'] = 1; - $updateVals['aux'] = Json::encode($auxVal); - break; - case 6: //왕 - $josaRo = JosaUtil::pick($nationLevelText, '로'); - $logger->pushGlobalHistoryLog("【작위】{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 책봉되었습니다."); - $logger->pushNationalHistoryLog("{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 책봉"); - break; - case 5: //공 - case 4: //주목 - case 3: //주자사 - $josaRo = JosaUtil::pick($nationLevelText, '로'); - $logger->pushGlobalHistoryLog("【작위】{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 임명되었습니다."); - $logger->pushNationalHistoryLog("{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 임명됨"); - break; - case 2: //군벌 - $josaRa = JosaUtil::pick($nationName, '라'); - $josaRo = JosaUtil::pick($nationLevelText, '로'); - $logger->pushGlobalHistoryLog("【작위】{$lordName}{$josaYi} 독립하여 {$nationName}{$josaRa}는 $nationLevelText{$josaRo} 나섰습니다."); - $logger->pushNationalHistoryLog("{$lordName}{$josaYi} 독립하여 {$nationName}{$josaRa}는 $nationLevelText{$josaRo} 나서다"); - break; - } - - $db->update('nation', $updateVals, 'nation=%i', $nation['nation']); - $logger->flush(); - - $turnRows = []; - foreach (Util::range(getNationChiefLevel($nation['level']), 12) as $chiefLevel) { - foreach (Util::range(GameConst::$maxChiefTurn) as $turnIdx) { - $turnRows[] = [ - 'nation_id' => $nation['nation'], - 'officer_level' => $chiefLevel, - 'turn_idx' => $turnIdx, - 'action' => '휴식', - 'arg' => null, - 'brief' => '휴식' - ]; - } - } - $db->insertIgnore('nation_turn', $turnRows); - - if ($levelDiff) { - //유니크 아이템 하나 돌리자 - $targetKillTurn = $admin['killturn']; - $targetKillTurn -= 24 * 60 / $admin['turnterm']; - $nationGenIDList = $db->queryFirstColumn( - 'SELECT no FROM general WHERE nation = %i AND killturn >= %i AND npc < 2', - $nation['nation'], - $targetKillTurn - ); - $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux'], 2); - $chiefID = null; - - $uniqueLotteryWeightList = []; - - $relYear = $year - $startYear; - $maxTrialCountByYear = 1; - foreach (GameConst::$maxUniqueItemLimit as $tmpVals) { - [$targetYear, $targetTrialCnt] = $tmpVals; - if ($relYear < $targetYear) { - break; - } - $maxTrialCountByYear = $targetTrialCnt; - } - foreach ($nationGenList as $nationGen) { - if ($nationGen->getVar('officer_level') == 12) { - $chiefID = $nationGen->getID(); - } - $trialCnt = min($maxTrialCountByYear, count(GameConst::$allItems)); - - foreach ($nationGen->getItems() as $item) { - if (!$item->isBuyable()) { - $trialCnt -= 1; - } - } - - if ($trialCnt <= 0) { - continue; - } - - $score = $nationGen->getVar('belong') + 10; - - if ($nationGen->getVar('officer_level') == 12) { - $score += 60; - } else if ($nationGen->getVar('officer_level') == 11) { - $score += 30; - } else if ($nationGen->getVar('officer_level') > 4) { - $score += 15; - } - - $score *= 2 ** $trialCnt; - - $uniqueLotteryWeightList[$nationGen->getID()] = [$nationGen, $score]; - } - - $nationLevelUpRNG = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( - UniqueConst::$hiddenSeed, - 'nationLevelUp', - $year, - $month, - $nationID - ))); - - foreach (Util::range($levelDiff) as $idx) { - if (!$uniqueLotteryWeightList) { - break; - } - - /** @var General */ - $winnerObj = $nationLevelUpRNG->choiceUsingWeightPair($uniqueLotteryWeightList); - unset($uniqueLotteryWeightList[$winnerObj->getID()]); - - $givenUniqueRNG = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( - UniqueConst::$hiddenSeed, - 'givenUnique', - $year, - $month, - $nationID, - $winnerObj->getID(), - ))); - giveRandomUniqueItem($givenUniqueRNG, $winnerObj, '작위보상'); - $winnerObj->applyDB($db); - } - - if ($chiefID) { - $chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], 2); - $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); - $chiefObj->applyDB($db); - } - } - } - } -} - function checkStatistic() { $db = DB::db(); diff --git a/hwe/sammo/Event/Action/UpdateNationLevel.php b/hwe/sammo/Event/Action/UpdateNationLevel.php new file mode 100644 index 00000000..ea520cd0 --- /dev/null +++ b/hwe/sammo/Event/Action/UpdateNationLevel.php @@ -0,0 +1,225 @@ +queryAllLists('SELECT nation, count(*) FROM city WHERE LEVEL>=4 GROUP BY nation') as [$nationID, $cityCnt]) { + $nationCityCounts[$nationID] = $cityCnt; + } + + + $nationLevelByCityCnt = [ + 0, //방랑군 + 1, //호족 + 2, //군벌 + 5, //주자사 + 8, //주목 + 11, //공 + 16, //왕 + 21, //황제 + ]; + + foreach ($db->query('SELECT nation,name,level,tech,aux FROM nation') as $nation) { + //TODO: level이 진관수이소중대특 체계를 벗어날 수 있음 + $nationID = $nation['nation']; + $cityCnt = $nationCityCounts[$nationID] ?? 0; + + /** @var int */ + $nationlevel = 0; + foreach ($nationLevelByCityCnt as $cmpNationLevel => $cmpCityCnt) { + if ($cityCnt < $cmpCityCnt) { + break; + } + $nationlevel = $cmpNationLevel; + } + + if ($nationlevel > $nation['level']) { + $levelDiff = $nationlevel - $nation['level']; + $oldLevel = $nation['level']; + $nation['level'] = $nationlevel; + + $updateVals = [ + 'level' => $nationlevel, + 'gold' => $db->sqleval('gold + %i', $nationlevel * 1000), + 'rice' => $db->sqleval('rice + %i', $nationlevel * 1000), + ]; + + $nationName = $nation['name']; + $lordName = $db->queryFirstField('SELECT name FROM general WHERE nation = %i AND officer_level = 12', $nationID); + + $oldNationLevelText = getNationLevel($oldLevel); + $nationLevelText = getNationLevel($nationlevel); + + $logger = new ActionLogger(0, $nationID, $year, $month, false); + $josaYi = JosaUtil::pick($lordName, '이'); + + switch ($nationlevel) { + case 7: //황제 + $josaRo = JosaUtil::pick($nationLevelText, '로'); + $logger->pushGlobalHistoryLog("【작위】{$nationName} {$oldNationLevelText} {$lordName}{$josaYi} {$nationLevelText}{$josaRo} 옹립되었습니다."); + $logger->pushNationalHistoryLog("{$nationName} {$oldNationLevelText} {$lordName}{$josaYi} {$nationLevelText}{$josaRo} 옹립"); + $auxVal = Json::decode($nation['aux']); + $auxVal['can_국기변경'] = 1; + $auxVal['can_국호변경'] = 1; + $updateVals['aux'] = Json::encode($auxVal); + break; + case 6: //왕 + $josaRo = JosaUtil::pick($nationLevelText, '로'); + $logger->pushGlobalHistoryLog("【작위】{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 책봉되었습니다."); + $logger->pushNationalHistoryLog("{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 책봉"); + break; + case 5: //공 + case 4: //주목 + case 3: //주자사 + $josaRo = JosaUtil::pick($nationLevelText, '로'); + $logger->pushGlobalHistoryLog("【작위】{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 임명되었습니다."); + $logger->pushNationalHistoryLog("{$nationName}{$lordName}{$josaYi} $nationLevelText{$josaRo} 임명됨"); + break; + case 2: //군벌 + $josaRa = JosaUtil::pick($nationName, '라'); + $josaRo = JosaUtil::pick($nationLevelText, '로'); + $logger->pushGlobalHistoryLog("【작위】{$lordName}{$josaYi} 독립하여 {$nationName}{$josaRa}는 $nationLevelText{$josaRo} 나섰습니다."); + $logger->pushNationalHistoryLog("{$lordName}{$josaYi} 독립하여 {$nationName}{$josaRa}는 $nationLevelText{$josaRo} 나서다"); + break; + } + + $db->update('nation', $updateVals, 'nation=%i', $nation['nation']); + $logger->flush(); + + $turnRows = []; + foreach (Util::range(getNationChiefLevel($nation['level']), 12) as $chiefLevel) { + foreach (Util::range(GameConst::$maxChiefTurn) as $turnIdx) { + $turnRows[] = [ + 'nation_id' => $nation['nation'], + 'officer_level' => $chiefLevel, + 'turn_idx' => $turnIdx, + 'action' => '휴식', + 'arg' => null, + 'brief' => '휴식' + ]; + } + } + $db->insertIgnore('nation_turn', $turnRows); + + if ($levelDiff) { + //유니크 아이템 하나 돌리자 + $targetKillTurn = $env['killturn']; + $targetKillTurn -= 24 * 60 / $env['turnterm']; + $nationGenIDList = $db->queryFirstColumn( + 'SELECT no FROM general WHERE nation = %i AND killturn >= %i AND npc < 2', + $nation['nation'], + $targetKillTurn + ); + $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux'], 2); + $chiefID = null; + + $uniqueLotteryWeightList = []; + + $relYear = $year - $startYear; + $maxTrialCountByYear = 1; + foreach (GameConst::$maxUniqueItemLimit as $tmpVals) { + [$targetYear, $targetTrialCnt] = $tmpVals; + if ($relYear < $targetYear) { + break; + } + $maxTrialCountByYear = $targetTrialCnt; + } + foreach ($nationGenList as $nationGen) { + if ($nationGen->getVar('officer_level') == 12) { + $chiefID = $nationGen->getID(); + } + $trialCnt = min($maxTrialCountByYear, count(GameConst::$allItems)); + + foreach ($nationGen->getItems() as $item) { + if (!$item->isBuyable()) { + $trialCnt -= 1; + } + } + + if ($trialCnt <= 0) { + continue; + } + + $score = $nationGen->getVar('belong') + 10; + + if ($nationGen->getVar('officer_level') == 12) { + $score += 60; + } else if ($nationGen->getVar('officer_level') == 11) { + $score += 30; + } else if ($nationGen->getVar('officer_level') > 4) { + $score += 15; + } + + $score *= 2 ** $trialCnt; + + $uniqueLotteryWeightList[$nationGen->getID()] = [$nationGen, $score]; + } + + $nationLevelUpRNG = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'nationLevelUp', + $year, + $month, + $nationID + ))); + + foreach (Util::range($levelDiff) as $idx) { + if (!$uniqueLotteryWeightList) { + break; + } + + /** @var General */ + $winnerObj = $nationLevelUpRNG->choiceUsingWeightPair($uniqueLotteryWeightList); + unset($uniqueLotteryWeightList[$winnerObj->getID()]); + + $givenUniqueRNG = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( + UniqueConst::$hiddenSeed, + 'givenUnique', + $year, + $month, + $nationID, + $winnerObj->getID(), + ))); + giveRandomUniqueItem($givenUniqueRNG, $winnerObj, '작위보상'); + $winnerObj->applyDB($db); + } + + if ($chiefID) { + $chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], 2); + $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); + $chiefObj->applyDB($db); + } + } + } + } + } +} diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index 0e19bc56..73f0f8ef 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -486,6 +486,7 @@ class GameConstBase [ "month", 1000, true, + ["UpdateNationLevel"] ["ProvideNPCTroopLeader"] ], [