diff --git a/.phan/config.php b/.phan/config.php index 4f979335..41e33801 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -15,9 +15,8 @@ return [ // Note that the **only** effect of choosing `'5.6'` is to infer // that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) - "target_php_version" => '8.1', - "minimum_target_php_version" => '8.1', - 'backward_compatibility_checks ' => true, + "target_php_version" => '8.2', + "minimum_target_php_version" => '8.2', 'minimum_severity' => \Phan\Issue::SEVERITY_NORMAL, 'file_list' => [ diff --git a/hwe/_admin2_submit.php b/hwe/_admin2_submit.php index 968d34d4..1f946345 100644 --- a/hwe/_admin2_submit.php +++ b/hwe/_admin2_submit.php @@ -33,7 +33,7 @@ $src = MessageTarget::buildQuick($session->generalID); $genObjList = []; $env = []; if ($genlist) { - $genObjList = General::createGeneralObjListFromDB($genlist); + $genObjList = General::createObjListFromDB($genlist); $env = $gameStor->cacheAll(); } switch ($btn) { diff --git a/hwe/_admin7.php b/hwe/_admin7.php index e5035cb3..f62cad85 100644 --- a/hwe/_admin7.php +++ b/hwe/_admin7.php @@ -76,7 +76,7 @@ if (!$gen) { $gen = $generalBasicList[0]['no']; } -$generalObj = General::createGeneralObjFromDB($gen, null, GeneralQueryMode::FullWithAccessLog); +$generalObj = General::createObjFromDB($gen, null, GeneralQueryMode::FullWithAccessLog); ?> diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index b4bce2b8..3f64f3ac 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -26,7 +26,7 @@ foreach ($db->queryFirstColumn( } $inheritPointManager = InheritancePointManager::getInstance(); -foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ +foreach(General::createObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ $inheritPointManager->mergeTotalInheritancePoint($genObj); $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); } \ No newline at end of file diff --git a/hwe/b_betting.php b/hwe/b_betting.php index 35b4fae8..d6b234c3 100644 --- a/hwe/b_betting.php +++ b/hwe/b_betting.php @@ -2,6 +2,7 @@ namespace sammo; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\Enums\RankColumn; @@ -564,12 +565,12 @@ if ($str3) { $winColumn = RankColumn::from("{$rankColumn}w"); $drawColumn = RankColumn::from("{$rankColumn}d"); $loseColumn = RankColumn::from("{$rankColumn}l"); - $tournamentRankerList = General::createGeneralObjListFromDB( + $tournamentRankerList = GeneralLite::createObjListFromDB( $db->queryFirstColumn('SELECT general_id FROM rank_data WHERE `type`= %s ORDER BY value DESC LIMIT 40', $gameColumn->value), [$prizeColumn->value, $gameColumn->value, $winColumn->value, $drawColumn->value, $loseColumn->value, 'leadership', 'strength', 'intel', 'no', 'npc', 'name'], - GeneralQueryMode::Core + GeneralLiteQueryMode::Core ); - usort($tournamentRankerList, function (General $lhs, General $rhs) use ($gameColumn, $winColumn, $drawColumn, $loseColumn) { + usort($tournamentRankerList, function (GeneralLite $lhs, GeneralLite $rhs) use ($gameColumn, $winColumn, $drawColumn, $loseColumn) { $result = - ($lhs->getRankVar($gameColumn) <=> $rhs->getRankVar($gameColumn)); if ($result !== 0) return $result; $result = - ( diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php index 7728a5fd..4762892c 100644 --- a/hwe/b_currentCity.php +++ b/hwe/b_currentCity.php @@ -327,8 +327,7 @@ $templates = new \League\Plates\Engine('templates'); if ($ourGeneral && !$isNPC) { $turnText = []; - $generalObj = new General($general, null, null, null, null, null, null, false); - foreach ($generalTurnList[$generalObj->getID()] as $turnRawIdx => $turn) { + foreach ($generalTurnList[$general['no']] as $turnRawIdx => $turn) { $turnIdx = $turnRawIdx + 1; $turnText[] = "{$turnIdx} : $turn"; } diff --git a/hwe/b_myPage.php b/hwe/b_myPage.php index 9859e0e2..110bc8cb 100644 --- a/hwe/b_myPage.php +++ b/hwe/b_myPage.php @@ -24,7 +24,7 @@ $gameStor->cacheValues(['turntime', 'opentime', 'autorun_user', 'npcmode']); increaseRefresh("내정보", 1); -$me = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); +$me = General::createObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); $myset = $me->getVar('myset'); if ($myset > 0) { diff --git a/hwe/func.php b/hwe/func.php index adae4f2f..e8b198e9 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -149,7 +149,7 @@ function getRandGenName(RandUtil $rng) -function cityInfo(General $generalObj) +function cityInfo(GeneralLite $generalObj) { $db = DB::db(); @@ -1324,7 +1324,7 @@ function CheckHall($no) ["betrate", 'calc'], ]; - $generalObj = General::createGeneralObjFromDB($no); + $generalObj = General::createObjFromDB($no); $ttw = $generalObj->getRankVar(RankColumn::ttw); $ttd = $generalObj->getRankVar(RankColumn::ttd); @@ -1714,14 +1714,13 @@ function deleteNation(General $lord, bool $applyDB): array $logger->pushGlobalHistoryLog("【멸망】{$nationName}{$josaUn} 멸망했습니다."); - $nationGeneralList = General::createGeneralObjListFromDB( + $nationGeneralList = General::createObjListFromDB( $db->queryFirstColumn( 'SELECT `no` FROM general WHERE nation=%i AND no != %i', $nationID, $lordID ), ['npc', 'owner', 'gold', 'rice', 'experience', 'explevel', 'dedication', 'dedlevel', 'belong', 'aux'], - GeneralQueryMode::Lite, ); $nationGeneralList[$lordID] = $lord; diff --git a/hwe/func_command.php b/hwe/func_command.php index dbdf1b31..eebd0ca2 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -350,7 +350,7 @@ function setGeneralCommand(int $generalID, array $rawTurnList, string $command, $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); $env = $gameStor->getAll(); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); try{ $commandObj = buildGeneralCommandClass($command, $general, $env, $arg); @@ -425,7 +425,7 @@ function setNationCommand(int $generalID, array $turnList, string $command, ?arr $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); $env = $gameStor->getAll(); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if($general->getVar('officer_level') < 5){ return [ diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 465c97eb..fdfae574 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -451,7 +451,7 @@ function checkWander(RandUtil $rng) $wanderers = $db->queryFirstColumn('SELECT general.`no` FROM general LEFT JOIN nation ON general.nation = nation.nation WHERE nation.`level` = 0 AND general.`officer_level` = 12'); - foreach (General::createGeneralObjListFromDB($wanderers) as $wanderer) { + foreach (General::createObjListFromDB($wanderers) as $wanderer) { $wanderCmd = buildGeneralCommandClass('che_해산', $wanderer, $admin); if ($wanderCmd->hasFullConditionMet()) { $logger = $wanderer->getLogger(); @@ -743,7 +743,7 @@ function checkEmperior() } $inheritPointManager = InheritancePointManager::getInstance(); - $allUserGenerals = General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')); + $allUserGenerals = General::createObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')); foreach ($allUserGenerals as $genObj) { if ($genObj->getNationID() == $nationID) { if ($genObj->getVar('officer_level') > 4) { diff --git a/hwe/func_time_event.php b/hwe/func_time_event.php index 22086dd8..bd1086b4 100644 --- a/hwe/func_time_event.php +++ b/hwe/func_time_event.php @@ -364,7 +364,14 @@ function disaster(RandUtil $rng) { $logger->flush(); if (!$isGood) { - $generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city'); + [$queryColumns,,] = General::mergeQueryColumn(); + $generalListByCity = Util::arrayGroupBy( + $db->query( + 'SELECT %l FROM general WHERE city IN %li', + Util::formatListOfBackticks($queryColumns), + Util::squeezeFromArray($targetCityList, 'city') + ), + 'city'); //NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기 foreach ($targetCityList as $city) { $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 4973f31a..9cac4a1b 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -882,7 +882,7 @@ function setGift($tnmt_type, $tnmt, $phase) //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; $resultHelper[$generalID]['msg'] = "4강 진출"; - General::createGeneralObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10); + General::createObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10); } //결승자 명성 돈 $cost = $admin['develcost'] * 6; @@ -946,7 +946,7 @@ function setGift($tnmt_type, $tnmt, $phase) $winnerLogger->pushGlobalHistoryLog("【대회】{$tp} 대회에서 {$winner['name']}{$josaYiWinner} 우승, {$runnerUp['name']}{$josaYiRunnerUp} 준우승을 차지하여 천하에 이름을 떨칩니다!", ActionLogger::EVENT_YEAR_MONTH); $winnerLogger->pushGlobalHistoryLog("【대회】{$tp} 대회의 우승자에게는 {$winnerRewardText}, 준우승자에겐 {$runnerUpRewardText}의 상금과 약간의 명성이 주어집니다!", ActionLogger::EVENT_YEAR_MONTH); - $generalObjList = General::createGeneralObjListFromDB(array_keys($resultHelper)); + $generalObjList = General::createObjListFromDB(array_keys($resultHelper)); foreach ($resultHelper as $generalID => $general) { $rewardText = number_format($general['reward']); diff --git a/hwe/j_myBossInfo.php b/hwe/j_myBossInfo.php index 53f69dfd..867668cb 100644 --- a/hwe/j_myBossInfo.php +++ b/hwe/j_myBossInfo.php @@ -1,6 +1,7 @@ setVar('nation', $nationID); } else{ - $general = General::createGeneralObjFromDB($destGeneralID, [ + $general = GeneralLite::createObjFromDB($destGeneralID, [ 'name', 'leadership', 'strength', 'intel', 'gold','rice', 'troop','officer_level','npc','picture','imgsvr', 'permission','penalty','belong', 'crewtype', 'experience', 'dedication', 'betray', 'dedlevel', 'explevel', 'makelimit', 'aux', - ], GeneralQueryMode::Lite); + ], GeneralLiteQueryMode::Lite); - if($general instanceof DummyGeneral){ + if($general instanceof DummyGeneralLite){ Json::die([ 'result'=>false, 'reason'=>'올바르지 않은 장수입니다.' diff --git a/hwe/j_set_my_setting.php b/hwe/j_set_my_setting.php index 04d4e2b3..422b6670 100644 --- a/hwe/j_set_my_setting.php +++ b/hwe/j_set_my_setting.php @@ -36,7 +36,7 @@ if($tnmt < 0 || $tnmt > 1){ } $db = DB::db(); -$me = General::createGeneralObjFromDB($generalID); +$me = General::createObjFromDB($generalID); if($defence_train !== $me->getVar('defence_train')){ diff --git a/hwe/j_update_picked_general.php b/hwe/j_update_picked_general.php index 56c7a3fc..e5aac0d0 100644 --- a/hwe/j_update_picked_general.php +++ b/hwe/j_update_picked_general.php @@ -66,7 +66,7 @@ if(!$ownerInfo){ $info = Json::decode($info); -$generalObj = General::createGeneralObjFromDB($generalID); +$generalObj = General::createObjFromDB($generalID); $oldGeneralName = $generalObj->getName(); $db->update('select_pool', [ 'general_id'=>-$generalID, diff --git a/hwe/old_index.php b/hwe/old_index.php index a7b7d263..901a775c 100644 --- a/hwe/old_index.php +++ b/hwe/old_index.php @@ -59,7 +59,7 @@ if ($limitState >= 2) { exit(); } -$generalObj = General::createGeneralObjFromDB($me['no'], null, GeneralQueryMode::FullWithAccessLog); +$generalObj = General::createObjFromDB($me['no'], null, GeneralQueryMode::FullWithAccessLog); $generalObj->setRawCity($db->queryFirstRow('SELECT * FROM city WHERE city = %i', $generalObj->getCityID())); $scenario = $gameStor->scenario_text; diff --git a/hwe/process_war.php b/hwe/process_war.php index c7789a69..444e1370 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -38,7 +38,7 @@ function processWar(string $warSeed, General $attackerGeneral, array $rawAttacke $city = new WarUnitCity($rng, $rawDefenderCity, $rawDefenderNation, $year, $month, $startYear); $defenderIDList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i AND nation!=0 and crew > 0 and rice>(crew/100) and train>=defence_train and atmos>=defence_train', $city->getVar('nation'), $city->getVar('city')); - $defenderGeneralList = General::createGeneralObjListFromDB($defenderIDList, null); + $defenderGeneralList = General::createObjListFromDB($defenderIDList, null); /** @var WarUnit[] */ $defenderList = []; @@ -596,10 +596,10 @@ function ConquerCity(array $admin, General $general, array $city) $lord = new General($db->queryFirstRow( 'SELECT %l FROM general WHERE nation = %i AND officer_level = %i LIMIT 1', - Util::formatListOfBackticks(General::mergeQueryColumn(['npc', 'gold', 'rice', 'experience', 'explevel', 'belong', 'dedication', 'dedlevel', 'aux'], GeneralQueryMode::Lite)[0]), + Util::formatListOfBackticks(General::mergeQueryColumn()[0]), $defenderNationID, 12 - ), null, null, $city, $loseNation, $year, $month, false); + ), null, null, $city, $loseNation, $year, $month); $josaUl = JosaUtil::pick($defenderNationName, '을'); $attackerLogger->pushNationalHistoryLog("{$defenderNationName}{$josaUl} 정복"); diff --git a/hwe/sammo/API/Auction/BidBuyRiceAuction.php b/hwe/sammo/API/Auction/BidBuyRiceAuction.php index 0771d7a1..249e9591 100644 --- a/hwe/sammo/API/Auction/BidBuyRiceAuction.php +++ b/hwe/sammo/API/Auction/BidBuyRiceAuction.php @@ -39,7 +39,7 @@ class BidBuyRiceAuction extends \sammo\BaseAPI $amount = $this->args['amount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionBuyRice($auctionID, $general); $result = $auction->bid($amount, true); diff --git a/hwe/sammo/API/Auction/BidSellRiceAuction.php b/hwe/sammo/API/Auction/BidSellRiceAuction.php index 11549c42..66a78f54 100644 --- a/hwe/sammo/API/Auction/BidSellRiceAuction.php +++ b/hwe/sammo/API/Auction/BidSellRiceAuction.php @@ -38,7 +38,7 @@ class BidSellRiceAuction extends \sammo\BaseAPI $amount = $this->args['amount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionSellRice($auctionID, $general); $result = $auction->bid($amount, true); diff --git a/hwe/sammo/API/Auction/BidUniqueAuction.php b/hwe/sammo/API/Auction/BidUniqueAuction.php index de637442..d026ad3a 100644 --- a/hwe/sammo/API/Auction/BidUniqueAuction.php +++ b/hwe/sammo/API/Auction/BidUniqueAuction.php @@ -41,7 +41,7 @@ class BidUniqueAuction extends \sammo\BaseAPI $tryExtendCloseDate = $this->args['extendCloseDate'] ?? false; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $auction = new AuctionUniqueItem($auctionID, $general); $result = $auction->bid($amount, $tryExtendCloseDate); diff --git a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php index b3f36e6f..782995f3 100644 --- a/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php +++ b/hwe/sammo/API/Auction/GetUniqueItemAuctionDetail.php @@ -77,7 +77,7 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI $inheritMgr = InheritancePointManager::getInstance(); //preveious라서 column을 최대한 비울 수 있다. $remainPoint = $inheritMgr->getInheritancePoint( - General::createGeneralObjFromDB($generalID, ['owner'], GeneralQueryMode::Core), + General::createObjFromDB($generalID), InheritanceKey::previous ); diff --git a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php index d9c71f1a..cc7e999d 100644 --- a/hwe/sammo/API/Auction/OpenBuyRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenBuyRiceAuction.php @@ -66,7 +66,7 @@ class OpenBuyRiceAuction extends \sammo\BaseAPI $finishBidAmount = $this->args['finishBidAmount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/Auction/OpenSellRiceAuction.php b/hwe/sammo/API/Auction/OpenSellRiceAuction.php index 9eab113e..5ee12653 100644 --- a/hwe/sammo/API/Auction/OpenSellRiceAuction.php +++ b/hwe/sammo/API/Auction/OpenSellRiceAuction.php @@ -66,7 +66,7 @@ class OpenSellRiceAuction extends \sammo\BaseAPI $finishBidAmount = $this->args['finishBidAmount']; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/Auction/OpenUniqueAuction.php b/hwe/sammo/API/Auction/OpenUniqueAuction.php index 1b4425d3..955504a8 100644 --- a/hwe/sammo/API/Auction/OpenUniqueAuction.php +++ b/hwe/sammo/API/Auction/OpenUniqueAuction.php @@ -57,7 +57,7 @@ class OpenUniqueAuction extends \sammo\BaseAPI $generalID = $session->generalID; $itemObj = buildItemClass($itemID); - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); diff --git a/hwe/sammo/API/General/BuildNationCandidate.php b/hwe/sammo/API/General/BuildNationCandidate.php index 8ce2e797..5a4b2d1b 100644 --- a/hwe/sammo/API/General/BuildNationCandidate.php +++ b/hwe/sammo/API/General/BuildNationCandidate.php @@ -59,7 +59,7 @@ class BuildNationCandidate extends \sammo\BaseAPI $env = $gameStor->getAll(); - $generalObj = General::createGeneralObjFromDB($general['no']); + $generalObj = General::createObjFromDB($general['no']); $validCmd = false; foreach(GameConst::$availableGeneralCommand as $cmdList){ diff --git a/hwe/sammo/API/General/DieOnPrestart.php b/hwe/sammo/API/General/DieOnPrestart.php index ce5fa56b..e2c8552b 100644 --- a/hwe/sammo/API/General/DieOnPrestart.php +++ b/hwe/sammo/API/General/DieOnPrestart.php @@ -68,7 +68,7 @@ class DieOnPrestart extends \sammo\BaseAPI return "아직 삭제할 수 없습니다. {$targetTimeShort} 부터 가능합니다."; } - $generalObj = General::createGeneralObjFromDB($general['no']); + $generalObj = General::createObjFromDB($general['no']); if ($generalObj instanceof DummyGeneral) { trigger_error("올바르지 않은 삭제 프로세스 $userID", E_USER_WARNING); } diff --git a/hwe/sammo/API/General/DropItem.php b/hwe/sammo/API/General/DropItem.php index 1ab36005..cd4fc7e2 100644 --- a/hwe/sammo/API/General/DropItem.php +++ b/hwe/sammo/API/General/DropItem.php @@ -37,7 +37,7 @@ class DropItem extends \sammo\BaseAPI public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType { $generalID = $session->generalID; - $me = General::createGeneralObjFromDB($generalID); + $me = General::createObjFromDB($generalID); $itemType = $this->args['itemType']; $item = $me->getItem($itemType); diff --git a/hwe/sammo/API/General/GetCommandTable.php b/hwe/sammo/API/General/GetCommandTable.php index 7e0a4ee2..6acff92b 100644 --- a/hwe/sammo/API/General/GetCommandTable.php +++ b/hwe/sammo/API/General/GetCommandTable.php @@ -21,7 +21,7 @@ class GetCommandTable extends \sammo\BaseAPI{ public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag): null | string | array | APIRecoveryType { $generalID = $session->generalID; - $me = General::createGeneralObjFromDB($generalID); + $me = General::createObjFromDB($generalID); $commandTable = getCommandTable($me); return [ diff --git a/hwe/sammo/API/General/GetFrontInfo.php b/hwe/sammo/API/General/GetFrontInfo.php index c0805c57..c36cd570 100644 --- a/hwe/sammo/API/General/GetFrontInfo.php +++ b/hwe/sammo/API/General/GetFrontInfo.php @@ -534,7 +534,7 @@ class GetFrontInfo extends \sammo\BaseAPI { $generalID = $session->generalID; //NOTE: 이 경우 staticNation 정보를 조회한다. - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); + $general = General::createObjFromDB($generalID, null, GeneralQueryMode::FullWithAccessLog); $nationID = $general->getNationID(); $cityID = $general->getCityID(); diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php index 91ce0917..097a260c 100644 --- a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -49,7 +49,7 @@ class BuyHiddenBuff extends \sammo\BaseAPI $type = $this->args['type']; $level = $this->args['level']; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/BuyRandomUnique.php b/hwe/sammo/API/InheritAction/BuyRandomUnique.php index 4a18a557..6e907b2e 100644 --- a/hwe/sammo/API/InheritAction/BuyRandomUnique.php +++ b/hwe/sammo/API/InheritAction/BuyRandomUnique.php @@ -31,7 +31,7 @@ class BuyRandomUnique extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if($userID != $general->getVar('owner')){ return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php index 428e9c55..e888b385 100644 --- a/hwe/sammo/API/InheritAction/ResetSpecialWar.php +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -31,7 +31,7 @@ class ResetSpecialWar extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php index ba39d6bf..3ecb5c5f 100644 --- a/hwe/sammo/API/InheritAction/ResetTurnTime.php +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -36,7 +36,7 @@ class ResetTurnTime extends \sammo\BaseAPI $userID = $session->userID; $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php index 8d490f82..0e074ac9 100644 --- a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -44,7 +44,7 @@ class SetNextSpecialWar extends \sammo\BaseAPI $type = $this->args['type']; - $general = General::createGeneralObjFromDB($generalID); + $general = General::createObjFromDB($generalID); if ($userID != $general->getVar('owner')) { return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; } diff --git a/hwe/sammo/API/Nation/GeneralList.php b/hwe/sammo/API/Nation/GeneralList.php index 4a740589..dcf25d37 100644 --- a/hwe/sammo/API/Nation/GeneralList.php +++ b/hwe/sammo/API/Nation/GeneralList.php @@ -5,8 +5,10 @@ namespace sammo\API\Nation; use ArrayObject; use sammo\DB; use sammo\Enums\APIRecoveryType; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\General; +use sammo\GeneralLite; use sammo\Session; use sammo\Util; @@ -165,7 +167,7 @@ class GeneralList extends \sammo\BaseAPI - [$queryColumns, $rankColumns, $accessLogColumns] = General::mergeQueryColumn(array_keys(static::$viewColumns), GeneralQueryMode::Lite); + [$queryColumns, $rankColumns, $accessLogColumns] = GeneralLite::mergeQueryColumn(array_keys(static::$viewColumns), GeneralLiteQueryMode::Lite); $rawGeneralList = Util::convertArrayToDict( $db->query( diff --git a/hwe/sammo/API/Nation/GetNationInfo.php b/hwe/sammo/API/Nation/GetNationInfo.php index 0dc1423f..5133bfd0 100644 --- a/hwe/sammo/API/Nation/GetNationInfo.php +++ b/hwe/sammo/API/Nation/GetNationInfo.php @@ -58,7 +58,7 @@ class GetNationInfo extends \sammo\BaseAPI ]; } - $generalObj = General::createGeneralObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID); $gameStor = KVStorage::getStorage($db, 'game_env'); $gameEnv = $gameStor->getValues(['year', 'month', 'startyear']); diff --git a/hwe/sammo/API/NationCommand/GetReservedCommand.php b/hwe/sammo/API/NationCommand/GetReservedCommand.php index 42f8a9ca..660bb252 100644 --- a/hwe/sammo/API/NationCommand/GetReservedCommand.php +++ b/hwe/sammo/API/NationCommand/GetReservedCommand.php @@ -113,7 +113,7 @@ class GetReservedCommand extends \sammo\BaseAPI ]; } - $generalObj = General::createGeneralObjFromDB($session->generalID, null, GeneralQueryMode::FullWithoutIAction); + $generalObj = General::createObjFromDB($session->generalID); return [ diff --git a/hwe/sammo/API/Vote/AddComment.php b/hwe/sammo/API/Vote/AddComment.php index 417dd5de..40b1899f 100644 --- a/hwe/sammo/API/Vote/AddComment.php +++ b/hwe/sammo/API/Vote/AddComment.php @@ -6,8 +6,10 @@ use DateTimeInterface; use sammo\DB; use sammo\DTO\VoteComment; use sammo\Enums\APIRecoveryType; +use sammo\Enums\GeneralLiteQueryMode; use sammo\Enums\GeneralQueryMode; use sammo\General; +use sammo\GeneralLite; use sammo\Session; use sammo\TimeUtil; use sammo\Validator; @@ -41,7 +43,7 @@ class AddComment extends \sammo\BaseAPI $text = mb_substr($this->args['text'], 0, 200); $generalID = $session->generalID; - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::Core); + $general = GeneralLite::createObjFromDB($generalID, null, GeneralLiteQueryMode::Core); $generalName = $general->getName(); $nationID = $general->getNationID(); $nationName = $general->getStaticNation()['name']; diff --git a/hwe/sammo/API/Vote/Vote.php b/hwe/sammo/API/Vote/Vote.php index 090ad87c..fea230c3 100644 --- a/hwe/sammo/API/Vote/Vote.php +++ b/hwe/sammo/API/Vote/Vote.php @@ -106,7 +106,7 @@ class Vote extends \sammo\BaseAPI $gameStor = KVStorage::getStorage($db, 'game_env'); $voteReward = $gameStor->getValue('develcost') * 5; - $general = General::createGeneralObjFromDB($generalID, null, GeneralQueryMode::Full); + $general = General::createObjFromDB($generalID, null, GeneralQueryMode::Full); $general->increaseVar('gold', $voteReward); $uniqueRng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize( UniqueConst::$hiddenSeed, diff --git a/hwe/sammo/Auction.php b/hwe/sammo/Auction.php index 7c393d84..b656ad64 100644 --- a/hwe/sammo/Auction.php +++ b/hwe/sammo/Auction.php @@ -218,7 +218,7 @@ abstract class Auction if ($bidItem->generalID === $this->general->getID()) { $oldBidder = $this->general; } else { - $oldBidder = General::createGeneralObjFromDB($bidItem->generalID); + $oldBidder = General::createObjFromDB($bidItem->generalID); } if ($this->info->reqResource === ResourceType::inheritancePoint) { @@ -485,7 +485,7 @@ abstract class Auction } } - $bidder = General::createGeneralObjFromDB($highestBid->generalID); + $bidder = General::createObjFromDB($highestBid->generalID); $failReason = $this->finishAuction($highestBid, $bidder); if ($failReason === null) { $this->closeAuction(); diff --git a/hwe/sammo/AuctionBasicResource.php b/hwe/sammo/AuctionBasicResource.php index dbc5dce5..4302a1b8 100644 --- a/hwe/sammo/AuctionBasicResource.php +++ b/hwe/sammo/AuctionBasicResource.php @@ -116,7 +116,7 @@ abstract class AuctionBasicResource extends Auction } else if ($this->info->hostGeneralID == 0) { $auctionHost = $this->genDummy(); } else { - $auctionHost = General::createGeneralObjFromDB($this->info->hostGeneralID); + $auctionHost = General::createObjFromDB($this->info->hostGeneralID); } $hostRes = static::$hostRes; @@ -164,7 +164,7 @@ abstract class AuctionBasicResource extends Auction } else if ($this->info->hostGeneralID == 0) { $auctionHost = $this->genDummy(); } else { - $auctionHost = General::createGeneralObjFromDB($this->info->hostGeneralID); + $auctionHost = General::createObjFromDB($this->info->hostGeneralID); } $highestBid = $this->getHighestBid(); @@ -175,7 +175,7 @@ abstract class AuctionBasicResource extends Auction if ($this->general->getID() === $highestBid->generalID) { $bidder = $this->general; } else { - $bidder = General::createGeneralObjFromDB($highestBid->generalID); + $bidder = General::createObjFromDB($highestBid->generalID); } $hostRes = static::$hostRes; diff --git a/hwe/sammo/AutorunGeneralPolicy.php b/hwe/sammo/AutorunGeneralPolicy.php index ac3b8cfc..6b5419fb 100644 --- a/hwe/sammo/AutorunGeneralPolicy.php +++ b/hwe/sammo/AutorunGeneralPolicy.php @@ -19,7 +19,7 @@ class AutorunGeneralPolicy{ static $소집해제 = '소집해제'; static $출병 = '출병'; - + //static $NPC증여 = 'NPC증여'; static $NPC헌납 = 'NPC헌납'; static $NPC사망대비 = 'NPC사망대비'; @@ -31,12 +31,12 @@ class AutorunGeneralPolicy{ static $귀환 = '귀환'; //static $전투이동 = '전투이동'; //static $내정이동 = '내정이동'; - + static $국가선택 = '국가선택'; static $집합 = '집합'; static $건국 = '건국'; static $선양 = '선양'; - + static public array $default_priority = [ @@ -74,7 +74,7 @@ class AutorunGeneralPolicy{ public $can소집해제 = true; public $can출병 = true; - + //public $canNPC증여 = true; public $canNPC헌납 = true; @@ -91,7 +91,7 @@ class AutorunGeneralPolicy{ public array $priority; - function doNPCState(General $general){ + function doNPCState(GeneralBase $general){ $npc = $general->getNPCType(); $nationID = $general->getNationID(); @@ -115,7 +115,7 @@ class AutorunGeneralPolicy{ } - function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env){ $this->priority = static::$default_priority; if($serverPolicy && key_exists('priority', $serverPolicy)){ @@ -165,7 +165,7 @@ class AutorunGeneralPolicy{ $this->can전투준비 = false; $this->can출병 = false; - + //$this->canNPC증여 = false; $this->canNPC헌납 = false; @@ -194,9 +194,9 @@ class AutorunGeneralPolicy{ $this->can금쌀구매 = true; $this->can상인무시 = true; break; - case 'recruit_high': + case 'recruit_high': $this->can모병 = true; - case 'recruit': + case 'recruit': $this->can징병 = true; $this->can소집해제 = true; $this->can금쌀구매 = true; diff --git a/hwe/sammo/AutorunNationPolicy.php b/hwe/sammo/AutorunNationPolicy.php index 86748efa..836fdd5e 100644 --- a/hwe/sammo/AutorunNationPolicy.php +++ b/hwe/sammo/AutorunNationPolicy.php @@ -179,7 +179,7 @@ class AutorunNationPolicy { 'cureThreshold'=>10, ]; - function __construct(General $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) + function __construct(GeneralBase $general, $aiOptions, ?array $nationPolicy, ?array $serverPolicy, array $nation, array $env) { foreach(static::$defaultPolicy as $policy=>$value){ $this->{$policy} = $value; diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index 4f7b9edf..15619fc1 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -402,7 +402,7 @@ class Betting $userLogger->flush(); } } else { - $generalList = General::createGeneralObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID')), ['gold', 'npc', 'betgold'], GeneralQueryMode::Lite); + $generalList = General::createObjListFromDB(array_unique(Util::squeezeFromArray($rewardList, 'generalID'))); foreach ($rewardList as $rewardItem) { $gambler = $generalList[$rewardItem['generalID']]; $reward = Util::round($rewardItem['amount']); diff --git a/hwe/sammo/Command/General/che_등용.php b/hwe/sammo/Command/General/che_등용.php index 0b4b035e..d8216008 100644 --- a/hwe/sammo/Command/General/che_등용.php +++ b/hwe/sammo/Command/General/che_등용.php @@ -7,11 +7,7 @@ use \sammo\{ Util, JosaUtil, General, - DummyGeneral, - ActionLogger, - GameConst, LastTurn, - GameUnitConst, Command, ScoutMessage }; @@ -77,7 +73,7 @@ class che_등용 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation', 'experience', 'dedication'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); [$reqGold, $reqRice] = $this->getCost(); diff --git a/hwe/sammo/Command/General/che_등용수락.php b/hwe/sammo/Command/General/che_등용수락.php index 959e66a0..dc608383 100644 --- a/hwe/sammo/Command/General/che_등용수락.php +++ b/hwe/sammo/Command/General/che_등용수락.php @@ -68,7 +68,7 @@ class che_등용수락 extends Command\GeneralCommand{ protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID'], null); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID'], ['gennum', 'scout']); diff --git a/hwe/sammo/Command/General/che_모반시도.php b/hwe/sammo/Command/General/che_모반시도.php index c5e0d005..8e533cc7 100644 --- a/hwe/sammo/Command/General/che_모반시도.php +++ b/hwe/sammo/Command/General/che_모반시도.php @@ -67,7 +67,7 @@ class che_모반시도 extends Command\GeneralCommand{ $lordID = $db->queryFirstField('SELECT no FROM general WHERE nation = %i AND officer_level = 12', $nationID); - $lordGeneral = General::createGeneralObjFromDB($lordID); + $lordGeneral = General::createObjFromDB($lordID); $generalName = $general->getName(); $lordName = $lordGeneral->getName(); diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index 23be46a6..9c2ec45e 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -66,7 +66,7 @@ class che_선양 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/General/che_장수대상임관.php b/hwe/sammo/Command/General/che_장수대상임관.php index 70bd734b..5f97b9c9 100644 --- a/hwe/sammo/Command/General/che_장수대상임관.php +++ b/hwe/sammo/Command/General/che_장수대상임관.php @@ -84,7 +84,7 @@ class che_장수대상임관 extends Command\GeneralCommand{ protected function initWithArg() { $destGeneralID = $this->arg['destGeneralID']; - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($destGeneralID); $this->setDestGeneral($destGeneral); $this->setDestNation($this->destGeneralObj->getVar('nation'), ['gennum', 'scout']); diff --git a/hwe/sammo/Command/General/che_증여.php b/hwe/sammo/Command/General/che_증여.php index c38493b4..e6e2e6f9 100644 --- a/hwe/sammo/Command/General/che_증여.php +++ b/hwe/sammo/Command/General/che_증여.php @@ -87,7 +87,7 @@ class che_증여 extends Command\GeneralCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->fullConditionConstraints = [ diff --git a/hwe/sammo/Command/General/che_화계.php b/hwe/sammo/Command/General/che_화계.php index 1be84a5c..b07c77ef 100644 --- a/hwe/sammo/Command/General/che_화계.php +++ b/hwe/sammo/Command/General/che_화계.php @@ -269,7 +269,7 @@ class che_화계 extends Command\GeneralCommand $destCityGeneralList = []; $cityGeneralID = $db->queryFirstColumn('SELECT no FROM general WHERE city = %i AND nation = %i', $destCityID, $destNationID); - $destCityGeneralList = General::createGeneralObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crewtype', 'crew', 'atmos', 'train']); + $destCityGeneralList = General::createObjListFromDB($cityGeneralID, ['name', 'city', 'nation', 'officer_level', 'leadership', 'horse', 'strength', 'weapon', 'intel', 'book', 'item', 'last_turn', 'injury', 'special', 'special2', 'injury', 'crewtype', 'crew', 'atmos', 'train']); foreach ($destCityGeneralList as &$destCityGeneral) { $destCityGeneral->setRawCity($this->destCity); unset($destCityGeneral); diff --git a/hwe/sammo/Command/Nation/che_몰수.php b/hwe/sammo/Command/Nation/che_몰수.php index 8b51bd94..9658a6ff 100644 --- a/hwe/sammo/Command/Nation/che_몰수.php +++ b/hwe/sammo/Command/Nation/che_몰수.php @@ -92,7 +92,7 @@ class che_몰수 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'npc', 'nation', 'imgsvr', 'picture'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $env = $this->env; diff --git a/hwe/sammo/Command/Nation/che_발령.php b/hwe/sammo/Command/Nation/che_발령.php index ddc3369a..7917f796 100644 --- a/hwe/sammo/Command/Nation/che_발령.php +++ b/hwe/sammo/Command/Nation/che_발령.php @@ -72,7 +72,7 @@ class che_발령 extends Command\NationCommand { $this->setDestCity($this->arg['destCityID']); - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); if ($this->arg['destGeneralID'] == $this->getGeneral()->getID()) { diff --git a/hwe/sammo/Command/Nation/che_불가침수락.php b/hwe/sammo/Command/Nation/che_불가침수락.php index ec348ecd..2056900d 100644 --- a/hwe/sammo/Command/Nation/che_불가침수락.php +++ b/hwe/sammo/Command/Nation/che_불가침수락.php @@ -104,7 +104,7 @@ class che_불가침수락 extends Command\NationCommand $env = $this->env; $relYear = $env['year'] - $env['startyear']; - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_불가침파기수락.php b/hwe/sammo/Command/Nation/che_불가침파기수락.php index a6962c7e..4b5efebe 100644 --- a/hwe/sammo/Command/Nation/che_불가침파기수락.php +++ b/hwe/sammo/Command/Nation/che_불가침파기수락.php @@ -78,7 +78,7 @@ class che_불가침파기수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_종전수락.php b/hwe/sammo/Command/Nation/che_종전수락.php index 9e42ac30..2441ee5a 100644 --- a/hwe/sammo/Command/Nation/che_종전수락.php +++ b/hwe/sammo/Command/Nation/che_종전수락.php @@ -87,7 +87,7 @@ class che_종전수락 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], null, GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); $this->setDestNation($this->arg['destNationID']); diff --git a/hwe/sammo/Command/Nation/che_포상.php b/hwe/sammo/Command/Nation/che_포상.php index 790fd504..73791692 100644 --- a/hwe/sammo/Command/Nation/che_포상.php +++ b/hwe/sammo/Command/Nation/che_포상.php @@ -82,7 +82,7 @@ class che_포상 extends Command\NationCommand protected function initWithArg() { - $destGeneral = General::createGeneralObjFromDB($this->arg['destGeneralID'], ['gold', 'rice', 'nation'], GeneralQueryMode::Lite); + $destGeneral = General::createObjFromDB($this->arg['destGeneralID']); $this->setDestGeneral($destGeneral); if($this->arg['destGeneralID'] == $this->getGeneral()->getID()){ diff --git a/hwe/sammo/Command/Nation/che_필사즉생.php b/hwe/sammo/Command/Nation/che_필사즉생.php index 9d56addb..ed7662f1 100644 --- a/hwe/sammo/Command/Nation/che_필사즉생.php +++ b/hwe/sammo/Command/Nation/che_필사즉생.php @@ -95,7 +95,7 @@ class che_필사즉생 extends Command\NationCommand{ $broadcastMessage = "{$generalName}{$josaYi} 필사즉생을 발동하였습니다."; $targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND no != %i', $nationID, $generalID); - foreach(General::createGeneralObjListFromDB($targetGeneralList, ['train', 'atmos'], GeneralQueryMode::Lite) as $targetGeneral){ + foreach(General::createObjListFromDB($targetGeneralList) as $targetGeneral){ $targetGeneral->getLogger()->pushGeneralActionLog($broadcastMessage, ActionLogger::PLAIN); if($targetGeneral->getVar('train') < 100){ $targetGeneral->setVar('train', 100); diff --git a/hwe/sammo/Command/Nation/che_허보.php b/hwe/sammo/Command/Nation/che_허보.php index b3c201b7..c0b1ff38 100644 --- a/hwe/sammo/Command/Nation/che_허보.php +++ b/hwe/sammo/Command/Nation/che_허보.php @@ -163,7 +163,7 @@ class che_허보 extends Command\NationCommand $destNationCityList = $db->queryFirstColumn('SELECT city FROM city WHERE nation = %i AND supply = 1', $destNationID); $targetGeneralList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city=%i', $destNationID, $destCityID); - foreach (General::createGeneralObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral) { + foreach (General::createObjListFromDB($targetGeneralList) as $targetGeneralID => $targetGeneral) { $targetLogger = $targetGeneral->getLogger(); $targetLogger->pushGeneralActionLog($destBroadcastMessage, ActionLogger::PLAIN); diff --git a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php index 1f8f5e8d..0896bb1f 100644 --- a/hwe/sammo/Constraint/ReqGeneralCrewMargin.php +++ b/hwe/sammo/Constraint/ReqGeneralCrewMargin.php @@ -39,7 +39,7 @@ class ReqGeneralCrewMargin extends Constraint{ //XXX: 왜 General -> obj -> General 변환을 하고 있나? //FIXME: RankVar, city에 따라 통솔이 바뀐다면 이 부분에 문제가 발생. - $generalObj = new General($this->general, null, null, null, null, null, null, true); + $generalObj = new General($this->general, null, null, null, null, 180, 1); if($reqCrewType->id != $generalObj->getCrewTypeObj()->id){ return true; diff --git a/hwe/sammo/DiplomaticMessage.php b/hwe/sammo/DiplomaticMessage.php index 1df2c596..7d9a2596 100644 --- a/hwe/sammo/DiplomaticMessage.php +++ b/hwe/sammo/DiplomaticMessage.php @@ -76,7 +76,7 @@ class DiplomaticMessage extends Message{ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_불가침수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -100,7 +100,7 @@ class DiplomaticMessage extends Message{ protected function cancelNA(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_불가침파기수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, @@ -122,7 +122,7 @@ class DiplomaticMessage extends Message{ protected function stopWar(){ $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $destGeneralObj = General::createGeneralObjFromDB($this->dest->generalID, ['picture', 'imgsvr', 'aux'], GeneralQueryMode::Lite); + $destGeneralObj = General::createObjFromDB($this->dest->generalID); $commandObj = buildNationCommandClass('che_종전수락', $destGeneralObj, $gameStor->getAll(true), new LastTurn(), [ 'destNationID'=>$this->src->nationID, diff --git a/hwe/sammo/DummyGeneralLite.php b/hwe/sammo/DummyGeneralLite.php new file mode 100644 index 00000000..f4134cd5 --- /dev/null +++ b/hwe/sammo/DummyGeneralLite.php @@ -0,0 +1,45 @@ + 0, + 'name' => 'Dummy', + 'npc' => 3, + 'city' => 0, + 'nation' => 0, + 'officer_level' => 0, + 'crewtype' => -1, + 'turntime' => '2012-03-04 05:06:07.000000', + 'experience' => 0, + 'dedication' => 0, + 'gold' => 0, + 'rice' => 0, + 'leadership' => 10, + 'strength' => 10, + 'intel' => 10, + 'imgsvr' => 0, + 'picture' => 'default.jpg', + ]; + + $this->raw = $raw; + + if ($initLogger) { + $this->initLogger(1, 1); + } + } + + function applyDB($db): bool + { + if ($this->logger) { + $this->initLogger($this->logger->getYear(), $this->logger->getMonth()); + } + return true; + } +} diff --git a/hwe/sammo/Enums/GeneralLiteQueryMode.php b/hwe/sammo/Enums/GeneralLiteQueryMode.php new file mode 100644 index 00000000..e449cc34 --- /dev/null +++ b/hwe/sammo/Enums/GeneralLiteQueryMode.php @@ -0,0 +1,14 @@ +allocate(count($generals)); diff --git a/hwe/sammo/Event/Action/ProcessIncome.php b/hwe/sammo/Event/Action/ProcessIncome.php index 7173070f..599fc9fc 100644 --- a/hwe/sammo/Event/Action/ProcessIncome.php +++ b/hwe/sammo/Event/Action/ProcessIncome.php @@ -39,7 +39,11 @@ class ProcessIncome extends \sammo\Event\Action $nationList = $db->query('SELECT name,nation,capital,gold,level,rate_tmp,bill,type from nation'); $cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation'); - $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,gold,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation'); + //FIXME: factory 형태로 바꿔야함 + $generalRawListByNation = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE npc != 5', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]) + ), 'nation'); //국가별 처리 foreach ($nationList as $nation) { @@ -119,7 +123,11 @@ class ProcessIncome extends \sammo\Event\Action $nationList = $db->query('SELECT name,level,nation,capital,rice,rate_tmp,bill,type from nation'); $cityListByNation = Util::arrayGroupBy($db->query('SELECT * FROM city'), 'nation'); - $generalRawListByNation = Util::arrayGroupBy($db->query('SELECT no,name,nation,rice,officer_level,dedication,city FROM general WHERE npc != 5'), 'nation'); + //FIXME: factory 형태로 바꿔야함 + $generalRawListByNation = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE npc != 5', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]) + ), 'nation'); //국가별 처리 foreach ($nationList as $nation) { diff --git a/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php index d8d4ab9f..50e06030 100644 --- a/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php +++ b/hwe/sammo/Event/Action/ProvideNPCTroopLeader.php @@ -84,7 +84,7 @@ class ProvideNPCTroopLeader extends \sammo\Event\Action 'troop' => $npcID ], 'no=%i', $npcID); - $cmd = buildGeneralCommandClass('che_집합', General::createGeneralObjFromDB($npcID), $env); + $cmd = buildGeneralCommandClass('che_집합', General::createObjFromDB($npcID), $env); _setGeneralCommand($cmd, iterator_to_array(Util::range(GameConst::$maxTurn))); $NPCTroopLeaderCnt += 1; $gameStor->lastNPCTroopLeaderID = $lastNPCTroopLeaderID; diff --git a/hwe/sammo/Event/Action/RaiseDisaster.php b/hwe/sammo/Event/Action/RaiseDisaster.php index da7cb8b0..793b279a 100644 --- a/hwe/sammo/Event/Action/RaiseDisaster.php +++ b/hwe/sammo/Event/Action/RaiseDisaster.php @@ -112,7 +112,12 @@ class RaiseDisaster extends \sammo\Event\Action $logger->flush(); if (!$isGood) { - $generalListByCity = Util::arrayGroupBy($db->query('SELECT no, name, nation, city, officer_level, injury, leadership, strength, intel, horse, weapon, book, item, crew, crewtype, atmos, train, special, special2 FROM general WHERE city IN %li', Util::squeezeFromArray($targetCityList, 'city')), 'city'); + //FIXME: factory 형태로 바꿔야함 + $generalListByCity = Util::arrayGroupBy($db->query( + 'SELECT %l FROM general WHERE city IN %li', + Util::formatListOfBackticks(General::mergeQueryColumn()[0]), + Util::squeezeFromArray($targetCityList, 'city')), + 'city'); //NOTE: 쿼리 1번이지만 복잡하기 vs 쿼리 여러번이지만 조금 더 깔끔하기 foreach ($targetCityList as $city) { $affectRatio = Util::valueFit($city['secu'] / $city['secu_max'] / 0.8, 0, 1); diff --git a/hwe/sammo/Event/Action/UpdateNationLevel.php b/hwe/sammo/Event/Action/UpdateNationLevel.php index 72b7bc26..88751956 100644 --- a/hwe/sammo/Event/Action/UpdateNationLevel.php +++ b/hwe/sammo/Event/Action/UpdateNationLevel.php @@ -140,7 +140,7 @@ class UpdateNationLevel extends \sammo\Event\Action $nation['nation'], $targetKillTurn ); - $nationGenList = General::createGeneralObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux']); + $nationGenList = General::createObjListFromDB($nationGenIDList, ['belong', 'npc', 'aux']); $chiefID = null; $uniqueLotteryWeightList = []; @@ -215,7 +215,7 @@ class UpdateNationLevel extends \sammo\Event\Action } if ($chiefID) { - $chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], GeneralQueryMode::Lite); + $chiefObj = General::createObjFromDB($chiefID); $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); $chiefObj->applyDB($db); } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 698bc580..0cf70ebb 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -10,27 +10,20 @@ use sammo\Enums\InheritanceKey; use sammo\Enums\RankColumn; use sammo\WarUnitTrigger as WarUnitTrigger; -class General implements iAction +class General extends GeneralBase implements iAction { - use LazyVarUpdater; + use LazyVarAndAuxUpdater; - protected $raw = []; - protected $rawCity = null; - - - /** @var Map */ + /** @var Map */ protected Map $rankVarRead; - /** @var Map */ + /** @var Map */ protected Map $rankVarIncrease; - /** @var Map */ + /** @var Map */ protected Map $rankVarSet; - /** @var Map */ + /** @var Map */ protected ?Map $accessLogRead; - /** @var \sammo\ActionLogger */ - protected $logger; - protected $activatedSkill = []; protected $logActivatedSkill = []; protected $isFinished = false; @@ -55,41 +48,17 @@ class General implements iAction protected $lastTurn = null; protected $resultTurn = null; - const TURNTIME_FULL_MS = -1; - const TURNTIME_FULL = 0; - const TURNTIME_HMS = 1; - const TURNTIME_HM = 2; - protected $calcCache = []; - protected static $prohibitedDirectUpdateVars = [ - //Reason: iAction - 'leadership' => 1, - 'power' => 1, - 'intel' => 1, - 'nation' => 2, - 'officer_level' => 1, - //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. - 'special' => 1, - 'special2' => 1, - 'personal' => 1, - 'horse' => 1, - 'weapon' => 1, - 'book' => 1, - 'item' => 1 - ]; - - /** * @param array $raw DB row값. * @param null|Map $rawRank * @param null|Map $rawAccessLog * @param null|array $city DB city 테이블의 row값 - * @param int|null $year 게임 연도 - * @param int|null $month 게임 월 - * @param bool $fullConstruct iAction, 및 ActionLogger 초기화 여부, false인 경우 no, name, city, nation, officer_level 정도로 초기화 가능 + * @param int $year 게임 연도 + * @param int $month 게임 월 */ - public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, ?int $year, ?int $month, bool $fullConstruct = true) + public function __construct(array $raw, ?Map $rawRank, ?Map $rawAccessLog, ?array $city, ?array $nation, int $year, int $month) { //TODO: 밖에서 가져오도록 하면 버그 확률이 높아짐. 필요한 raw 값을 직접 구해야함. @@ -106,9 +75,7 @@ class General implements iAction $this->resultTurn = $this->lastTurn->duplicate(); } - if ($year !== null && $month !== null) { - $this->initLogger($year, $month); - } + $this->initLogger($year, $month); if ($rawRank) { $this->rankVarRead = $rawRank; @@ -122,10 +89,6 @@ class General implements iAction $this->rankVarIncrease = new Map(); $this->rankVarSet = new Map(); - if (!$fullConstruct) { - return; - } - $this->nationType = buildNationTypeClass($nation['type']); $this->officerLevelObj = new TriggerOfficerLevel($this->raw, $nation['level']); @@ -141,43 +104,12 @@ class General implements iAction $this->itemObjs['book'] = buildItemClass($raw['book']); $this->itemObjs['item'] = buildItemClass($raw['item']); - if (key_exists('aux', $this->raw)) { - $rawInheritBuff = $this->getAuxVar('inheritBuff'); - if ($rawInheritBuff !== null) { - $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); - } + $rawInheritBuff = $this->getAuxVar('inheritBuff'); + if ($rawInheritBuff !== null) { + $this->inheritBuffObj = new TriggerInheritBuff($rawInheritBuff); } } - function initLogger(int $year, int $month) - { - $this->logger = new ActionLogger( - $this->getVar('no'), - $this->getVar('nation'), - $year, - $month, - false - ); - } - - function getTurnTime(int $short = self::TURNTIME_FULL_MS) - { - return [ - self::TURNTIME_FULL_MS => function ($turntime) { - return $turntime; - }, - self::TURNTIME_FULL => function ($turntime) { - return substr($turntime, 0, 19); - }, - self::TURNTIME_HMS => function ($turntime) { - return substr($turntime, 11, 8); - }, - self::TURNTIME_HM => function ($turntime) { - return substr($turntime, 11, 5); - }, - ][$short]($this->getVar('turntime')); - } - function setItem(string $itemKey = 'item', ?string $itemCode) { if ($itemCode === null) { @@ -200,11 +132,6 @@ class General implements iAction return $this->itemObjs[$itemKey]; } - function getNPCType(): int - { - return $this->raw['npc']; - } - /** @return BaseItem[] */ function getItems(): array { @@ -281,48 +208,13 @@ class General implements iAction } } - function getName(): string - { - return $this->raw['name']; - } - function getInfo(): string { //iAction용 info로는 적절하지 않음 return ''; } - function getID(): int - { - return $this->raw['no']; - } - - function getRawCity(): ?array - { - return $this->rawCity; - } - - function setRawCity(?array $city) - { - $this->rawCity = $city; - } - - function getCityID(): int - { - return $this->raw['city']; - } - - function getNationID(): int - { - return $this->raw['nation']; - } - - function getStaticNation(): array - { - return getNationStaticInfo($this->raw['nation']); - } - - function getLogger(): ?ActionLogger + function getLogger(): ActionLogger { return $this->logger; } @@ -505,17 +397,6 @@ class General implements iAction return $this->getStatValue('intel', $withInjury, $withIActionObj, $withStatAdjust, $useFloor); } - function getDex(GameUnitDetail $crewType) - { - $armType = $crewType->armType; - - if ($armType == GameUnitConst::T_CASTLE) { - $armType = GameUnitConst::T_SIEGE; - } - - return $this->getVar("dex{$armType}"); - } - function addDex(GameUnitDetail $crewType, float $exp, bool $affectTrainAtmos = false) { $armType = $crewType->armType; @@ -593,8 +474,11 @@ class General implements iAction } } - function updateVar(string $key, $value) + function updateVar(string|\BackedEnum $key, $value) { + if($key instanceof \BackedEnum){ + $key = $key->value; + } if (($this->raw[$key] ?? null) === $value) { return; } @@ -1032,86 +916,6 @@ class General implements iAction return $caller; } - static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array - { - $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; - $defaultEventColumn = [ - 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', - 'special', 'special2', 'personal', - 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', - ]; - $fullColumn = [ - 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', - 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', - 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', - 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', - 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', - 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', - 'recent_war', 'last_turn', 'myset', - 'specage', 'specage2', 'aux', 'permission', 'penalty', - ]; - $fullAcessLogColumn = [ - GeneralAccessLogColumn::refreshScore, - GeneralAccessLogColumn::refreshScoreTotal, - ]; - - if ($reqColumns === null) { - switch ($queryMode) { - case GeneralQueryMode::Core: - return [$minimumColumn, [], []]; - case GeneralQueryMode::Lite: - return [$defaultEventColumn, [], []]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [$fullColumn, RankColumn::cases(), []]; - case GeneralQueryMode::FullWithAccessLog: - return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; - } - } - - /** @var RankColumn[] */ - $rankColumn = []; - $subColumn = []; - $accessLogColumn = []; - foreach ($reqColumns as $column) { - if ($column instanceof RankColumn) { - $rankColumn[] = $column; - continue; - } - if ($column instanceof GeneralAccessLogColumn) { - $accessLogColumn[] = $column; - continue; - } - - - $enumKey = RankColumn::tryFrom($column); - if ($enumKey !== null) { - $rankColumn[] = $enumKey; - continue; - } - $enumKey = GeneralAccessLogColumn::tryFrom($column); - if ($enumKey !== null) { - $accessLogColumn[] = $enumKey; - continue; - } - $subColumn[] = $column; - } - - switch ($queryMode) { - case GeneralQueryMode::Core: - return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::Lite: - return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithoutIAction: - case GeneralQueryMode::Full: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; - case GeneralQueryMode::FullWithAccessLog: - return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; - default: - throw new \RuntimeException('invalid query mode'); - } - } - /** * @param ?int[] $generalIDList * @param null|array $column @@ -1119,20 +923,15 @@ class General implements iAction * @return \sammo\General[] * @throws MustNotBeReachedException */ - static public function createGeneralObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array + static public function createObjListFromDB(?array $generalIDList, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): array { if ($generalIDList === []) { return []; } $db = DB::db(); - if ($queryMode->value > 0) { - $gameStor = KVStorage::getStorage($db, 'game_env'); - [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); - } else { - $year = null; - $month = null; - } + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); /** * @var string[] $column @@ -1197,25 +996,24 @@ class General implements iAction $result[$generalID] = new DummyGeneral($queryMode->value > 0); continue; } - if ($rawRanks->hasKey($generalID) && $rawRanks[$generalID]->count() !== count($rankColumn)) { + /** @var Map */ + $generalRankValues = $rawRanks[$generalID] ?? new Map(); + if ($generalRankValues->count() !== count($rankColumn)) { throw new \RuntimeException('column의 수가 일치하지 않음 : ' . $generalID); } - $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, $rawAccessLogs[$generalID] ?? null, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + + $generalAccessLog = $rawAccessLogs[$generalID] ?? new Map(); + $result[$generalID] = new static($rawGenerals[$generalID], $generalRankValues, $generalAccessLog, null, null, $year, $month); } return $result; } - static public function createGeneralObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self + static public function createObjFromDB(int $generalID, ?array $column = null, GeneralQueryMode $queryMode = GeneralQueryMode::Full): self { $db = DB::db(); - if ($queryMode->value > 0) { - $gameStor = KVStorage::getStorage($db, 'game_env'); - [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); - } else { - $year = null; - $month = null; - } + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); /** * @var string[] $column @@ -1269,7 +1067,7 @@ class General implements iAction } - $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month, $queryMode->value >= GeneralQueryMode::Full->value); + $general = new static($rawGeneral, $rawRankValues, $rawAccessLog, null, null, $year, $month); return $general; } diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index 0a8a5018..7afb068a 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -3514,7 +3514,7 @@ class GeneralAI $db = DB::db(); $generalIDList = $db->queryFirstColumn('SELECT no FROM general WHERE nation = %i AND no != %i', $nationID, $this->general->getID()); - $nationGenerals = General::createGeneralObjListFromDB($generalIDList); + $nationGenerals = General::createObjListFromDB($generalIDList); $lastWar = \PHP_INT_MAX; foreach ($nationGenerals as $nationGeneral) { diff --git a/hwe/sammo/GeneralBase.php b/hwe/sammo/GeneralBase.php new file mode 100644 index 00000000..9b9c6757 --- /dev/null +++ b/hwe/sammo/GeneralBase.php @@ -0,0 +1,229 @@ + */ + protected Map $rankVarRead; + + /** @var \sammo\ActionLogger */ + protected $logger; + + const TURNTIME_FULL_MS = -1; + const TURNTIME_FULL = 0; + const TURNTIME_HMS = 1; + const TURNTIME_HM = 2; + + protected static $prohibitedDirectUpdateVars = [ + //Reason: iAction + 'leadership' => 1, + 'power' => 1, + 'intel' => 1, + 'nation' => 2, + 'officer_level' => 1, + //NOTE: officerLevelObj로 인해 국가의 '레벨'이 바뀌는 것도 조심해야 하나, 국가 레벨의 변경은 월 초/말에만 일어남. + 'special' => 1, + 'special2' => 1, + 'personal' => 1, + 'horse' => 1, + 'weapon' => 1, + 'book' => 1, + 'item' => 1 + ]; + + function initLogger(int $year, int $month) + { + $this->logger = new ActionLogger( + $this->getVar('no'), + $this->getVar('nation'), + $year, + $month, + false + ); + } + + function getTurnTime(int $short = self::TURNTIME_FULL_MS): ?string + { + if(!key_exists('turntime', $this->raw)){ + return null; + } + + return [ + self::TURNTIME_FULL_MS => function ($turntime) { + return $turntime; + }, + self::TURNTIME_FULL => function ($turntime) { + return substr($turntime, 0, 19); + }, + self::TURNTIME_HMS => function ($turntime) { + return substr($turntime, 11, 8); + }, + self::TURNTIME_HM => function ($turntime) { + return substr($turntime, 11, 5); + }, + ][$short]($this->getVar('turntime')); + } + + function getNPCType(): int + { + return $this->raw['npc']; + } + + function getName(): string + { + return $this->raw['name']; + } + + function getID(): int + { + return $this->raw['no']; + } + + function getRawCity(): ?array + { + return $this->rawCity; + } + + function setRawCity(?array $city) + { + $this->rawCity = $city; + } + + function getCityID(): int + { + return $this->raw['city']; + } + + function getNationID(): int + { + return $this->raw['nation']; + } + + function getStaticNation(): array + { + return getNationStaticInfo($this->raw['nation']); + } + + function getLogger(): ?ActionLogger + { + return $this->logger; + } + + function getDex(GameUnitDetail $crewType) + { + $armType = $crewType->armType; + + if ($armType == GameUnitConst::T_CASTLE) { + $armType = GameUnitConst::T_SIEGE; + } + + return $this->getVar("dex{$armType}"); + } + + function getRankVar(RankColumn $key, $defaultValue = null): int + { + if (!$this->rankVarRead->hasKey($key)) { + if ($defaultValue === null) { + throw new \RuntimeException('인자가 없음 : ' . $key->value); + } + return $defaultValue; + } + + return $this->rankVarRead[$key]; + } + + abstract function applyDB($db): bool; + + static public function mergeQueryColumn(?array $reqColumns = null, GeneralQueryMode|GeneralLiteQueryMode $queryMode = GeneralQueryMode::Full): array + { + $minimumColumn = ['no', 'name', 'owner', 'npc', 'city', 'nation', 'officer_level', 'officer_city']; + $defaultEventColumn = [ + 'no', 'name', 'npc', 'owner', 'city', 'nation', 'officer_level', 'officer_city', + 'special', 'special2', 'personal', + 'horse', 'weapon', 'book', 'item', 'last_turn', 'aux', 'turntime', + ]; + $fullColumn = [ + 'no', 'name', 'owner', 'owner_name', 'picture', 'imgsvr', 'nation', 'city', 'troop', 'injury', 'affinity', + 'leadership', 'leadership_exp', 'strength', 'strength_exp', 'intel', 'intel_exp', 'weapon', 'book', 'horse', 'item', + 'experience', 'dedication', 'officer_level', 'officer_city', 'gold', 'rice', 'crew', 'crewtype', 'train', 'atmos', 'turntime', + 'makelimit', 'killturn', 'block', 'dedlevel', 'explevel', 'age', 'startage', 'belong', + 'personal', 'special', 'special2', 'defence_train', 'tnmt', 'npc', 'npc_org', 'deadyear', 'npcmsg', + 'dex1', 'dex2', 'dex3', 'dex4', 'dex5', 'betray', + 'recent_war', 'last_turn', 'myset', + 'specage', 'specage2', 'aux', 'permission', 'penalty', + ]; + $fullAcessLogColumn = [ + GeneralAccessLogColumn::refreshScore, + GeneralAccessLogColumn::refreshScoreTotal, + ]; + + if ($reqColumns === null) { + switch ($queryMode) { + case GeneralLiteQueryMode::Core: + return [$minimumColumn, [], []]; + case GeneralLiteQueryMode::Lite: + return [$defaultEventColumn, [], []]; + case GeneralLiteQueryMode::Full: + case GeneralQueryMode::Full: + return [$fullColumn, RankColumn::cases(), []]; + case GeneralQueryMode::FullWithAccessLog: + return [$fullColumn, RankColumn::cases(), $fullAcessLogColumn]; + } + } + + /** @var RankColumn[] */ + $rankColumn = []; + $subColumn = []; + $accessLogColumn = []; + foreach ($reqColumns as $column) { + if ($column instanceof RankColumn) { + $rankColumn[] = $column; + continue; + } + if ($column instanceof GeneralAccessLogColumn) { + $accessLogColumn[] = $column; + continue; + } + + + $enumKey = RankColumn::tryFrom($column); + if ($enumKey !== null) { + $rankColumn[] = $enumKey; + continue; + } + $enumKey = GeneralAccessLogColumn::tryFrom($column); + if ($enumKey !== null) { + $accessLogColumn[] = $enumKey; + continue; + } + $subColumn[] = $column; + } + + switch ($queryMode) { + case GeneralLiteQueryMode::Core: + return [array_unique(array_merge($minimumColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralLiteQueryMode::Lite: + return [array_unique(array_merge($defaultEventColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralLiteQueryMode::Full: + case GeneralQueryMode::Full: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, $accessLogColumn]; + case GeneralQueryMode::FullWithAccessLog: + return [array_unique(array_merge($fullColumn, $subColumn)), $rankColumn, array_unique(array_merge($fullAcessLogColumn, $accessLogColumn))]; + default: + throw new \RuntimeException('invalid query mode'); + } + } + +} diff --git a/hwe/sammo/GeneralLite.php b/hwe/sammo/GeneralLite.php new file mode 100644 index 00000000..7a2b6626 --- /dev/null +++ b/hwe/sammo/GeneralLite.php @@ -0,0 +1,179 @@ +raw = $raw; + $this->rawCity = $city; + + if ($year !== null && $month !== null) { + $this->initLogger($year, $month); + } + + if ($rawRank) { + $this->rankVarRead = $rawRank; + } else { + $this->rankVarRead = new Map(); + } + } + + /** + * @param \MeekroDB $db + */ + function applyDB($db): bool + { + $updateVals = $this->getUpdatedValues(); + + + $generalID = $this->getID(); + $result = false; + + if ($updateVals) { + $db->update('general', $updateVals, 'no=%i', $generalID); + $result = $result || $db->affectedRows() > 0; + if (key_exists('nation', $updateVals)) { + $db->update('rank_data', [ + 'nation_id' => $updateVals['nation'] + ], 'general_id = %i', $generalID); + $result = true; + } + $this->flushUpdateValues(); + } + + $this->getLogger()->flush(); + return $result; + } + + /** + * @param ?int[] $generalIDList + * @param null|array $column + * @param GeneralLiteQueryMode $queryMode + * @return \sammo\GeneralLite[] + * @throws MustNotBeReachedException + */ + static public function createObjListFromDB(?array $generalIDList, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): array + { + if ($generalIDList === []) { + return []; + } + + if($queryMode > GeneralLiteQueryMode::Full){ + throw new \InvalidArgumentException('지원하지 않는 queryMode:' . $queryMode->name); + } + + $db = DB::db(); + if ($queryMode->value > 0) { + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + } else { + $year = null; + $month = null; + } + + /** + * @var string[] $column + */ + [$column, $rankColumn,] = static::mergeQueryColumn($column, $queryMode); + + if ($generalIDList === null) { + $rawGenerals = Util::convertArrayToDict( + $db->query('SELECT %l FROM general WHERE 1', Util::formatListOfBackticks($column)), + 'no' + ); + + $generalIDList = array_keys($rawGenerals); + } else { + $rawGenerals = Util::convertArrayToDict( + $db->query('SELECT %l FROM general WHERE no IN %li', Util::formatListOfBackticks($column), $generalIDList), + 'no' + ); + } + + /** @var Map> */ + $rawRanks = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `general_id`, `type`, `value` FROM rank_data WHERE general_id IN %li AND `type` IN %ls', + $generalIDList, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$generalID, $rawRankType, $rankValue]) { + if (!$rawRanks->hasKey($generalID)) { + $rawRanks[$generalID] = new Map(); + } + + $rankType = RankColumn::from($rawRankType); + $rawRanks[$generalID][$rankType] = $rankValue; + } + } + + $result = []; + foreach ($generalIDList as $generalID) { + if (!key_exists($generalID, $rawGenerals)) { + $result[$generalID] = new DummyGeneral($queryMode->value > 0); + continue; + } + $result[$generalID] = new static($rawGenerals[$generalID], $rawRanks[$generalID] ?? null, null, null, $year, $month); + } + + return $result; + } + + static public function createObjFromDB(int $generalID, ?array $column = null, GeneralLiteQueryMode $queryMode = GeneralLiteQueryMode::Full): self + { + $db = DB::db(); + if ($queryMode->value > 0) { + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$year, $month] = $gameStor->getValuesAsArray(['year', 'month']); + } else { + $year = null; + $month = null; + } + + /** + * @var string[] $column + * @var RankColumn[] $rankColumn + */ + [$column, $rankColumn,] = static::mergeQueryColumn($column, $queryMode); + + $rawGeneral = $db->queryFirstRow('SELECT %l FROM general WHERE no = %i', Util::formatListOfBackticks($column), $generalID); + + if (!$rawGeneral) { + return new DummyGeneralLite($queryMode->value > 0); + } + + $rawRankValues = new Map(); + if ($rankColumn) { + $rawValue = $db->queryAllLists( + 'SELECT `type`, `value` FROM rank_data WHERE general_id = %i AND `type` IN %ls', + $generalID, + array_map(fn (\BackedEnum $e) => $e->value, $rankColumn) + ); + foreach ($rawValue as [$rawRankType, $rankValue]) { + $rankType = RankColumn::tryFrom($rawRankType); + $rawRankValues->put($rankType, $rankValue); + } + } + + $general = new static($rawGeneral, $rawRankValues, null, null, $year, $month); + + return $general; + } +} diff --git a/hwe/sammo/LazyVarAndAuxUpdater.php b/hwe/sammo/LazyVarAndAuxUpdater.php new file mode 100644 index 00000000..497698e7 --- /dev/null +++ b/hwe/sammo/LazyVarAndAuxUpdater.php @@ -0,0 +1,73 @@ +getAuxVar(''); + + } + return $this->raw; + } + + function unpackAux(){ + if(!key_exists('auxVar', $this->raw)){ + if(!key_exists('aux', $this->raw)){ + throw new \RuntimeException('aux is not set'); + } + $this->raw['auxVar'] = Json::decode($this->raw['aux']??'{}'); + } + } + + function getAuxVar(string|\BackedEnum $key){ + if($key instanceof \BackedEnum){ + $key = $key->value; + } + $this->unpackAux(); + return $this->raw['auxVar'][$key]??null; + } + + function setAuxVar(string|\BackedEnum $key, $var){ + if($key instanceof \BackedEnum){ + $key = $key->value; + } + $oldVar = $this->getAuxVar($key); + + if($oldVar === $var){ + return; + } + + if($var === null){ + unset($this->raw['auxVar'][$key]); + $this->auxUpdated = true; + return; + } + $this->raw['auxVar'][$key] = $var; + $this->auxUpdated = true; + } + + function getUpdatedValues():array { + if($this->auxUpdated){ + $this->setVar('aux', Json::encode($this->raw['auxVar'])); + $this->auxUpdated = false; + } + $updateVals = []; + foreach(array_keys($this->updatedVar) as $key){ + $updateVals[$key] = $this->raw[$key]; + } + return $updateVals; + } + + function flushUpdateValues():void { + $this->updatedVar = []; + if(key_exists('auxVar', $this->raw)){ + $this->auxUpdated = false; + unset($this->raw['auxVar']); + } + } +} \ No newline at end of file diff --git a/hwe/sammo/LazyVarUpdater.php b/hwe/sammo/LazyVarUpdater.php index b53891b6..988d20a9 100644 --- a/hwe/sammo/LazyVarUpdater.php +++ b/hwe/sammo/LazyVarUpdater.php @@ -4,14 +4,8 @@ namespace sammo; trait LazyVarUpdater{ protected $raw = []; protected $updatedVar = []; - protected $auxVar = null; - protected $auxUpdated = false; - function getRaw(bool $extractAux=false):array{ - if($extractAux){ - $this->getAuxVar(''); - - } + function getRaw():array{ return $this->raw; } @@ -38,15 +32,6 @@ trait LazyVarUpdater{ return true; } - function unpackAux(){ - if(!key_exists('auxVar', $this->raw)){ - if(!key_exists('aux', $this->raw)){ - throw new \RuntimeException('aux is not set'); - } - $this->raw['auxVar'] = Json::decode($this->raw['aux']??'{}'); - } - } - function setVar(string|\BackedEnum $key, $value){ if($key instanceof \BackedEnum){ $key = $key->value; @@ -54,33 +39,6 @@ trait LazyVarUpdater{ return $this->updateVar($key, $value); } - function getAuxVar(string|\BackedEnum $key){ - if($key instanceof \BackedEnum){ - $key = $key->value; - } - $this->unpackAux(); - return $this->raw['auxVar'][$key]??null; - } - - function setAuxVar(string|\BackedEnum $key, $var){ - if($key instanceof \BackedEnum){ - $key = $key->value; - } - $oldVar = $this->getAuxVar($key); - - if($oldVar === $var){ - return; - } - - if($var === null){ - unset($this->raw['auxVar'][$key]); - $this->auxUpdated = true; - return; - } - $this->raw['auxVar'][$key] = $var; - $this->auxUpdated = true; - } - function updateVar(string|\BackedEnum $key, $value){ if($key instanceof \BackedEnum){ $key = $key->value; @@ -160,10 +118,6 @@ trait LazyVarUpdater{ } function getUpdatedValues():array { - if($this->auxUpdated){ - $this->setVar('aux', Json::encode($this->raw['auxVar'])); - $this->auxUpdated = false; - } $updateVals = []; foreach(array_keys($this->updatedVar) as $key){ $updateVals[$key] = $this->raw[$key]; @@ -173,9 +127,5 @@ trait LazyVarUpdater{ function flushUpdateValues():void { $this->updatedVar = []; - if(key_exists('auxVar', $this->raw)){ - $this->auxUpdated = false; - unset($this->raw['auxVar']); - } } } \ No newline at end of file diff --git a/hwe/sammo/RaiseInvaderMessage.php b/hwe/sammo/RaiseInvaderMessage.php index 33b65e89..e70fee8e 100644 --- a/hwe/sammo/RaiseInvaderMessage.php +++ b/hwe/sammo/RaiseInvaderMessage.php @@ -66,7 +66,7 @@ class RaiseInvaderMessage extends Message } $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $general = \sammo\General::createGeneralObjFromDB($receiverID); + $general = \sammo\General::createObjFromDB($receiverID); $logger = $general->getLogger(); diff --git a/hwe/sammo/ScoutMessage.php b/hwe/sammo/ScoutMessage.php index bf954234..6b847d64 100644 --- a/hwe/sammo/ScoutMessage.php +++ b/hwe/sammo/ScoutMessage.php @@ -68,7 +68,7 @@ class ScoutMessage extends Message } $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $general = \sammo\General::createGeneralObjFromDB($receiverID); + $general = \sammo\General::createObjFromDB($receiverID); $logger = $general->getLogger(); @@ -125,8 +125,8 @@ class ScoutMessage extends Message $now = TimeUtil::now(); //XXX: 뭔가 기존 쿼리가 애매하다. invalid 관련해서 다른 옵션이 가능한가? $rawMsgList = Util::convertArrayToDict($db->query( - 'SELECT * FROM `message` WHERE - `mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND + 'SELECT * FROM `message` WHERE + `mailbox` = %i AND `type` = "private" AND `dest` = `mailbox` AND `valid_until` > %s AND JSON_VALUE(message, "$.option.action") = %s', $generalID, $now, diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index ca17ad71..482839b3 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -239,7 +239,7 @@ class TurnExecutionHelper return [true, $currentTurn]; } - $general = General::createGeneralObjFromDB($rawGeneral['no']); + $general = General::createObjFromDB($rawGeneral['no']); $nationStor = KVStorage::getStorage($db, $general->getNationID(), 'nation_env'); $turnObj = new static($general); diff --git a/hwe/v_NPCControl.php b/hwe/v_NPCControl.php index c9307359..0ab1df23 100644 --- a/hwe/v_NPCControl.php +++ b/hwe/v_NPCControl.php @@ -43,7 +43,7 @@ $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env'); $nationStor->cacheValues(['npc_nation_policy', 'npc_general_policy']); $gameStor->cacheAll(); -$general = new General($me, null, null, null, $nation, $gameStor->year, $gameStor->month, false); +$general = General::createObjFromDB($me['no']); $rawServerPolicy = $gameStor->getValue('npc_nation_policy') ?? []; $rawNationPolicy = $nationStor->getValue('npc_nation_policy') ?? []; diff --git a/hwe/v_chiefCenter.php b/hwe/v_chiefCenter.php index 6193047b..c807f83d 100644 --- a/hwe/v_chiefCenter.php +++ b/hwe/v_chiefCenter.php @@ -7,7 +7,7 @@ include "func.php"; //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); $userID = Session::getUserID(); -$generalObj = General::createGeneralObjFromDB($session->generalID); +$generalObj = General::createObjFromDB($session->generalID); ?> diff --git a/hwe/v_inheritPoint.php b/hwe/v_inheritPoint.php index 24eeccd7..5acdef88 100644 --- a/hwe/v_inheritPoint.php +++ b/hwe/v_inheritPoint.php @@ -14,7 +14,7 @@ $generalID = $session->generalID; $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$me = General::createGeneralObjFromDB($generalID); +$me = General::createObjFromDB($generalID); diff --git a/hwe/v_processing.php b/hwe/v_processing.php index 15914ac4..eda86878 100644 --- a/hwe/v_processing.php +++ b/hwe/v_processing.php @@ -42,7 +42,7 @@ if ($isChiefTurn && !in_array($commandType, Util::array_flatten(GameConst::$avai $gameStor = KVStorage::getStorage($db, 'game_env')->turnOnCache(); $env = $gameStor->getAll(); -$general = General::createGeneralObjFromDB($session->generalID); +$general = General::createObjFromDB($session->generalID); if (!$isChiefTurn) { $commandObj = buildGeneralCommandClass($commandType, $general, $env);