From eff79c47784b6731fbf1f582d6b470df275d1a8c Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 8 May 2022 04:40:36 +0900 Subject: [PATCH] =?UTF-8?q?refac:=20=EC=9C=A0=EC=82=B0=20=ED=8F=AC?= =?UTF-8?q?=EC=9D=B8=ED=8A=B8=20=ED=8C=8C=ED=8A=B8=EB=A5=BC=20=EB=B3=84?= =?UTF-8?q?=EB=8F=84=EC=9D=98=20Manager=EB=A1=9C=20=EB=B6=84=EB=A6=AC,=20e?= =?UTF-8?q?num=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phan/config.php | 2 +- hwe/_admin_force_rehall.php | 7 +- hwe/func.php | 7 +- hwe/func_gamerule.php | 61 +--- hwe/func_tournament.php | 5 +- hwe/process_war.php | 4 +- hwe/sammo/API/General/Join.php | 5 +- hwe/sammo/Command/General/che_거병.php | 4 +- hwe/sammo/Command/General/che_건국.php | 4 +- hwe/sammo/Command/General/che_등용수락.php | 4 +- hwe/sammo/Command/General/che_랜덤임관.php | 3 +- hwe/sammo/Command/General/che_모반시도.php | 3 +- hwe/sammo/Command/General/che_방랑.php | 4 +- hwe/sammo/Command/General/che_선양.php | 3 +- hwe/sammo/Command/General/che_인재탐색.php | 4 +- hwe/sammo/Command/General/che_임관.php | 5 +- .../Command/General/che_장수대상임관.php | 3 +- hwe/sammo/Command/General/che_첩보.php | 5 +- hwe/sammo/Command/General/che_출병.php | 3 +- hwe/sammo/Command/General/che_하야.php | 3 +- hwe/sammo/Command/Nation/che_감축.php | 3 +- hwe/sammo/Command/Nation/che_국기변경.php | 3 +- hwe/sammo/Command/Nation/che_국호변경.php | 3 +- hwe/sammo/Command/Nation/che_증축.php | 3 +- hwe/sammo/Command/Nation/che_천도.php | 3 +- hwe/sammo/Command/Nation/che_초토화.php | 3 +- hwe/sammo/DefaultAction.php | 1 - hwe/sammo/DummyGeneral.php | 13 +- hwe/sammo/Enums/InherianceKey.php | 20 ++ hwe/sammo/General.php | 262 +------------- hwe/sammo/InheritancePointManager.php | 326 ++++++++++++++++++ hwe/sammo/TurnExecutionHelper.php | 3 +- hwe/sammo/VO/InheritancePointType.php | 13 + hwe/v_inheritPoint.php | 4 +- hwe/v_join.php | 9 +- 35 files changed, 463 insertions(+), 345 deletions(-) create mode 100644 hwe/sammo/Enums/InherianceKey.php create mode 100644 hwe/sammo/InheritancePointManager.php create mode 100644 hwe/sammo/VO/InheritancePointType.php diff --git a/.phan/config.php b/.phan/config.php index 0d09cd0c..bd733e7a 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -15,7 +15,7 @@ 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.0', + "target_php_version" => '8.1', 'backward_compatibility_checks ' => true, 'minimum_severity' => \Phan\Issue::SEVERITY_NORMAL, diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index 386f7c55..b62f6b28 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -25,8 +25,9 @@ foreach ($db->queryFirstColumn( CheckHall($generalNo); } +$inheritPointManager = InheritancePointManager::getInstance(); foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ - $genObj->mergeTotalInheritancePoint(true); - applyInheritanceUser($genObj->getVar('owner')); - $genObj->clearInheritancePoint(); + $inheritPointManager->mergeTotalInheritancePoint($genObj, true); + $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); + $inheritPointManager->clearInheritancePoint($genObj); } \ No newline at end of file diff --git a/hwe/func.php b/hwe/func.php index d6ca6911..522b9516 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -3,6 +3,7 @@ namespace sammo; use DateTime; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; require_once 'process_war.php'; @@ -1617,7 +1618,7 @@ function giveRandomUniqueItem(General $general, string $acquireType): bool if (!$availableUnique) { if ($general->getAuxVar('inheritRandomUnique')) { $general->setAuxVar('inheritRandomUnique', null); - $general->increaseInheritancePoint('previous', GameConst::$inheritItemRandomPoint); + $general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint); $userLogger = new UserLogger($general->getVar('owner')); $userLogger->push(sprintf("얻을 유니크가 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); } @@ -1687,7 +1688,7 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r //두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자 [,, $amount] = $ownTrial; $trialStor->deleteValue("u{$ownerID}"); - $general->increaseInheritancePoint('previous', $amount); + $general->increaseInheritancePoint(InheritanceKey::previous, $amount); LogText("선택유니크 롤백포인트:{$ownerID}", $amount); $userLogger = new UserLogger($ownerID); @@ -1902,7 +1903,7 @@ function tryUniqueItemLottery(General $general, string $acquireType = '아이템 LogText("{$general->getName()}, {$general->getID()} 모든 아이템", $trialCnt); if ($general->getAuxVar('inheritRandomUnique')) { $general->setAuxVar('inheritRandomUnique', null); - $general->increaseInheritancePoint('previous', GameConst::$inheritItemRandomPoint); + $general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint); $userLogger = new UserLogger($general->getVar('owner')); $userLogger->push(sprintf("유니크를 얻을 공간이 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); } diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 7269e2bb..0752b30b 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -3,6 +3,7 @@ namespace sammo; use Monolog\Logger; +use sammo\Enums\InheritanceKey; /** * 게임 룰에 해당하는 함수 모음 @@ -702,7 +703,7 @@ function updateNationState() if ($chiefID) { $chiefObj = General::createGeneralObjFromDB($chiefID, ['belong', 'npc', 'aux'], 2); - $chiefObj->increaseInheritancePoint('unifier', 250 * $levelDiff); + $chiefObj->increaseInheritancePoint(InheritanceKey::unifier, 250 * $levelDiff); $chiefObj->applyDB($db); } } @@ -1022,15 +1023,16 @@ function checkEmperior() $nationLogger = new ActionLogger(0, $nationID, $admin['year'], $admin['month']); $nationLogger->pushNationalHistoryLog("{$nationName}{$josaYi} 전토를 통일"); + $inheritPointManager = InheritancePointManager::getInstance(); foreach (General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc < 2')) as $genObj) { if ($genObj->getNationID() == $nationID) { if ($genObj->getVar('officer_level') > 4) { - $genObj->increaseInheritancePoint('unifier', 2000); + $genObj->increaseInheritancePoint(InheritanceKey::unifier, 2000); }; } - $genObj->mergeTotalInheritancePoint(true); - applyInheritanceUser($genObj->getVar('owner')); - $genObj->clearInheritancePoint(); + $inheritPointManager->mergeTotalInheritancePoint($genObj, true); + $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); + $inheritPointManager->clearInheritancePoint($genObj); } $gameStor->isunited = 2; @@ -1184,55 +1186,14 @@ function checkEmperior() LogHistory(); } -function applyInheritanceUser(int $userID, bool $isRebirth = false): float -{ - //FIXME: 은퇴, 사망, 천통 시점에 바로 반영한다면 여기가 아니라 general class로 이동하는 것이 옳음 - //또한 굳이 merge, apply, clean 3단계를 거쳐야 할 이유도 없음 - $rebirthDegraded = [ - 'dex' => 0.5, - ]; - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); - $totalPoint = 0; - $allPoints = $inheritStor->getAll(); - if (!$allPoints || count($allPoints) == 0) { - //비었으므로 리셋 안함 - return 0; - } - if (count($allPoints) == 1 && key_exists('previous', $allPoints)) { - //이미 리셋되었으므로 리셋 안함 - return $allPoints['previous'][0]; - } - - $userLogger = new UserLogger($userID); - - $previousPoint = ($allPoints['previous'] ?? [0, 0])[0]; - - foreach ($allPoints as $key => [$value,]) { - if ($isRebirth && key_exists($key, $rebirthDegraded)) { - $value *= $rebirthDegraded[$key]; - } - $keyText = General::INHERITANCE_KEY[$key][2]; - $userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint"); - $totalPoint += $value; - } - $totalPoint = Util::toInt($totalPoint); - $userLogger->push("포인트 {$previousPoint} => {$totalPoint}", "inheritPoint"); - $userLogger->flush(); - - $inheritStor->resetValues(); - $inheritStor->setValue('previous', [$totalPoint, null]); - return $totalPoint; -} - function updateMaxDomesticCritical(General $general, $score) { - $maxDomesticCritical = $general->getAuxVar('max_domestic_critical') ?? 0; + $maxDomesticCritical = $general->getAuxVar(InheritanceKey::max_domestic_critical->value) ?? 0; $maxDomesticCritical += $score / 2; - $general->setAuxVar('max_domestic_critical', $maxDomesticCritical); + $general->setAuxVar(InheritanceKey::max_domestic_critical->value, $maxDomesticCritical); - $oldMaxDomesticCritical = $general->getInheritancePoint('max_domestic_critical'); + $oldMaxDomesticCritical = $general->getInheritancePoint(InheritanceKey::max_domestic_critical); if ($maxDomesticCritical > $oldMaxDomesticCritical) { - $general->setInheritancePoint('max_domestic_critical', $maxDomesticCritical); + $general->setInheritancePoint(InheritanceKey::max_domestic_critical, $maxDomesticCritical); } } diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index d6a229c0..a7afea52 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -3,6 +3,7 @@ namespace sammo; use sammo\DTO\BettingInfo; +use sammo\Enums\InheritanceKey; function processTournament() { @@ -920,7 +921,7 @@ function setGift($tnmt_type, $tnmt, $phase) //포상 장수 이름, 금액 $resultHelper[$generalID]['reward'] += $cost; $resultHelper[$generalID]['msg'] = "4강 진출"; - General::createGeneralObjFromDB($generalID)->increaseInheritancePoint('tournament', 10); + General::createGeneralObjFromDB($generalID)->increaseInheritancePoint(InheritanceKey::tournament, 10); } //결승자 명성 돈 $cost = $admin['develcost'] * 6; @@ -992,7 +993,7 @@ function setGift($tnmt_type, $tnmt, $phase) $logger = $general['logger']; $logger->pushGeneralActionLog("{$tp} 대회의 {$general['msg']}로 {$rewardText}의 상금, 약간의 명성 획득!", ActionLogger::EVENT_PLAIN); //TODO: 토너먼트의 다른 값이 모두 sql에 직접 입력하므로 기반을 바꿔야함. - $generalObjList[$generalID]->increaseInheritancePoint('tournament', $general['inheritance_point']); + $generalObjList[$generalID]->increaseInheritancePoint(InheritanceKey::tournament, $general['inheritance_point']); } //당첨칸에 베팅한 사람들만 diff --git a/hwe/process_war.php b/hwe/process_war.php index a39633cd..4c600456 100644 --- a/hwe/process_war.php +++ b/hwe/process_war.php @@ -269,10 +269,10 @@ function processWar_NG( $defenderCrewTypeCoef = $defender->getCrewType()->getAttackCoef($attacker->getCrewType()) * $attacker->getCrewType()->getDefenceCoef($defender->getCrewType()); /* if($attackerCrewTypeCoef > $defenderCrewTypeCoef && $attacker instanceof WarUnitGeneral){ - $attacker->getGeneral()->increaseInheritancePoint('snipe_combat', 1); + $attacker->getGeneral()->increaseInheritancePoint(InheritanceKey::snipe_combat, 1); } if($defenderCrewTypeCoef > $attackerCrewTypeCoef && $defender instanceof WarUnitGeneral){ - $defender->getGeneral()->increaseInheritancePoint('snipe_combat', 1); + $defender->getGeneral()->increaseInheritancePoint(InheritanceKey::snipe_combat, 1); } */ diff --git a/hwe/sammo/API/General/Join.php b/hwe/sammo/API/General/Join.php index d2d804e4..5af127a9 100644 --- a/hwe/sammo/API/General/Join.php +++ b/hwe/sammo/API/General/Join.php @@ -8,6 +8,7 @@ use sammo\DB; use sammo\GameConst; use sammo\GameUnitConst; use sammo\General; +use sammo\InheritancePointManager; use sammo\JosaUtil; use sammo\Json; use sammo\KVStorage; @@ -26,7 +27,6 @@ use function sammo\cutTurn; use function sammo\getGeneralSpecialWarName; use function sammo\getRandTurn; use function sammo\pushAdminLog; -use function sammo\applyInheritanceUser; class Join extends \sammo\BaseAPI { @@ -155,7 +155,8 @@ class Join extends \sammo\BaseAPI $admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year', 'month']); - $inheritTotalPoint = applyInheritanceUser($userID); + $inheritPointManager = InheritancePointManager::getInstance(); + $inheritTotalPoint = $inheritPointManager->applyInheritanceUser($userID); $inheritRequiredPoint = 0; $userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false); diff --git a/hwe/sammo/Command/General/che_거병.php b/hwe/sammo/Command/General/che_거병.php index 20fbbbb4..2fd6a285 100644 --- a/hwe/sammo/Command/General/che_거병.php +++ b/hwe/sammo/Command/General/che_거병.php @@ -14,6 +14,8 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; + use function sammo\refreshNationStaticInfo; use function sammo\getAllNationStaticInfo; use function sammo\tryUniqueItemLottery; @@ -162,7 +164,7 @@ class che_거병 extends Command\GeneralCommand{ $exp = 100; $ded = 100; - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->addExperience($exp); $general->addDedication($ded); $general->setVar('belong', 1); diff --git a/hwe/sammo/Command/General/che_건국.php b/hwe/sammo/Command/General/che_건국.php index 2dd98482..6f3a190a 100644 --- a/hwe/sammo/Command/General/che_건국.php +++ b/hwe/sammo/Command/General/che_건국.php @@ -19,6 +19,8 @@ use function \sammo\getAllNationStaticInfo; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; + use function sammo\buildNationTypeClass; use function sammo\refreshNationStaticInfo; use function sammo\GetNationColors; @@ -188,7 +190,7 @@ class che_건국 extends Command\GeneralCommand refreshNationStaticInfo(); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); tryUniqueItemLottery($general, '건국'); diff --git a/hwe/sammo/Command/General/che_등용수락.php b/hwe/sammo/Command/General/che_등용수락.php index c58bc406..e060ffcf 100644 --- a/hwe/sammo/Command/General/che_등용수락.php +++ b/hwe/sammo/Command/General/che_등용수락.php @@ -18,7 +18,7 @@ use function \sammo\getNationStaticInfo; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; - +use sammo\Enums\InheritanceKey; class che_등용수락 extends Command\GeneralCommand{ static protected $actionName = '등용 수락'; @@ -194,7 +194,7 @@ class che_등용수락 extends Command\GeneralCommand{ } $db->update('nation', $setScoutNationValues, 'nation=%i', $destNationID); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->setVar('permission', 'normal'); $general->setVar('belong', 1); $general->setVar('officer_level', 1); diff --git a/hwe/sammo/Command/General/che_랜덤임관.php b/hwe/sammo/Command/General/che_랜덤임관.php index 96dcf4ee..6e6ca261 100644 --- a/hwe/sammo/Command/General/che_랜덤임관.php +++ b/hwe/sammo/Command/General/che_랜덤임관.php @@ -19,6 +19,7 @@ use function \sammo\tryUniqueItemLottery; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; use sammo\MustNotBeReachedException; @@ -285,7 +286,7 @@ class che_랜덤임관 extends Command\GeneralCommand $general->setAuxVar('joinedNations', $joinedNations); } - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->addExperience($exp); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); diff --git a/hwe/sammo/Command/General/che_모반시도.php b/hwe/sammo/Command/General/che_모반시도.php index 375be4fe..2e11afda 100644 --- a/hwe/sammo/Command/General/che_모반시도.php +++ b/hwe/sammo/Command/General/che_모반시도.php @@ -13,6 +13,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use function sammo\tryRollbackInheritUniqueItem; @@ -96,7 +97,7 @@ class che_모반시도 extends Command\GeneralCommand{ $lordLogger->pushGeneralHistoryLog("{$generalName}의 모반으로 인해 {$nationName}의 군주자리를 박탈당함"); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->checkStatChange(); tryRollbackInheritUniqueItem($general); $general->applyDB($db); diff --git a/hwe/sammo/Command/General/che_방랑.php b/hwe/sammo/Command/General/che_방랑.php index 5e21e42a..0daf2e2a 100644 --- a/hwe/sammo/Command/General/che_방랑.php +++ b/hwe/sammo/Command/General/che_방랑.php @@ -13,6 +13,8 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; + use function sammo\DeleteConflict; use function sammo\refreshNationStaticInfo; use function sammo\tryRollbackInheritUniqueItem; @@ -121,7 +123,7 @@ class che_방랑 extends Command\GeneralCommand{ ], 'me=%i OR you=%i', $nationID, $nationID); refreshNationStaticInfo(); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); tryRollbackInheritUniqueItem($general); $general->applyDB($db); diff --git a/hwe/sammo/Command/General/che_선양.php b/hwe/sammo/Command/General/che_선양.php index 14a18434..7c4d8239 100644 --- a/hwe/sammo/Command/General/che_선양.php +++ b/hwe/sammo/Command/General/che_선양.php @@ -19,6 +19,7 @@ use function\sammo\tryUniqueItemLottery; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use function sammo\tryRollbackInheritUniqueItem; @@ -135,7 +136,7 @@ class che_선양 extends Command\GeneralCommand $logger->pushGeneralHistoryLog("{$nationName}의 군주자리를 {$destGeneralName}에게 선양"); $destLogger->pushGeneralHistoryLog("{$nationName}의 군주자리를 물려 받음"); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); tryRollbackInheritUniqueItem($general); diff --git a/hwe/sammo/Command/General/che_인재탐색.php b/hwe/sammo/Command/General/che_인재탐색.php index a34c6f35..a1507c19 100644 --- a/hwe/sammo/Command/General/che_인재탐색.php +++ b/hwe/sammo/Command/General/che_인재탐색.php @@ -17,7 +17,7 @@ use function \sammo\pickGeneralFromPool; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; - +use sammo\Enums\InheritanceKey; class che_인재탐색 extends Command\GeneralCommand { @@ -210,7 +210,7 @@ class che_인재탐색 extends Command\GeneralCommand $exp = 200; $ded = 300; - $general->increaseInheritancePoint('active_action', Util::valueFit(sqrt(1 / $foundProp), 1)); + $general->increaseInheritancePoint(InheritanceKey::active_action, Util::valueFit(sqrt(1 / $foundProp), 1)); $general->increaseVarWithLimit('gold', -$reqGold, 0); $general->increaseVarWithLimit('rice', -$reqRice, 0); $general->addExperience($exp); diff --git a/hwe/sammo/Command/General/che_임관.php b/hwe/sammo/Command/General/che_임관.php index b07c5398..823172e9 100644 --- a/hwe/sammo/Command/General/che_임관.php +++ b/hwe/sammo/Command/General/che_임관.php @@ -23,8 +23,7 @@ use function \sammo\getNationStaticInfo; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; - - +use sammo\Enums\InheritanceKey; class che_임관 extends Command\GeneralCommand { @@ -183,7 +182,7 @@ class che_임관 extends Command\GeneralCommand $general->setAuxVar('joinedNations', $joinedNations); } - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->addExperience($exp); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); diff --git a/hwe/sammo/Command/General/che_장수대상임관.php b/hwe/sammo/Command/General/che_장수대상임관.php index 5b21478e..2688e81d 100644 --- a/hwe/sammo/Command/General/che_장수대상임관.php +++ b/hwe/sammo/Command/General/che_장수대상임관.php @@ -21,6 +21,7 @@ use function \sammo\getNationStaticInfo; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; class che_장수대상임관 extends Command\GeneralCommand{ static protected $actionName = '장수를 따라 임관'; @@ -175,7 +176,7 @@ class che_장수대상임관 extends Command\GeneralCommand{ $general->setAuxVar('joinedNations', $joinedNations); } - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $general->addExperience($exp); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); diff --git a/hwe/sammo/Command/General/che_첩보.php b/hwe/sammo/Command/General/che_첩보.php index 4f00f04c..36090efb 100644 --- a/hwe/sammo/Command/General/che_첩보.php +++ b/hwe/sammo/Command/General/che_첩보.php @@ -20,8 +20,7 @@ use function sammo\tryRollbackInheritUniqueItem; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; - - +use sammo\Enums\InheritanceKey; class che_첩보 extends Command\GeneralCommand { @@ -211,7 +210,7 @@ class che_첩보 extends Command\GeneralCommand $ded = Util::randRangeInt(1, 70); [$reqGold, $reqRice] = $this->getCost(); - $general->increaseInheritancePoint('active_action', 0.5);//NOTE: 첩보만 예외! + $general->increaseInheritancePoint(InheritanceKey::active_action, 0.5);//NOTE: 첩보만 예외! $general->increaseVarWithLimit('gold', -$reqGold, 0); $general->increaseVarWithLimit('rice', -$reqRice, 0); $general->addExperience($exp); diff --git a/hwe/sammo/Command/General/che_출병.php b/hwe/sammo/Command/General/che_출병.php index 75709497..ed11f24f 100644 --- a/hwe/sammo/Command/General/che_출병.php +++ b/hwe/sammo/Command/General/che_출병.php @@ -19,6 +19,7 @@ use function \sammo\processWar; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; class che_출병 extends Command\GeneralCommand { @@ -226,7 +227,7 @@ class che_출병 extends Command\GeneralCommand $general->addDex($general->getCrewTypeObj(), $general->getVar('crew') / 100); if($general->getVar('crew') > 500 && $general->getVar('train') * $general->getVar('atmos') > 70 * 70){ //500명 이상, 모훈출, 모사출 - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); } $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); diff --git a/hwe/sammo/Command/General/che_하야.php b/hwe/sammo/Command/General/che_하야.php index 8da1abf9..8658dc19 100644 --- a/hwe/sammo/Command/General/che_하야.php +++ b/hwe/sammo/Command/General/che_하야.php @@ -13,6 +13,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; use sammo\CityConst; +use sammo\Enums\InheritanceKey; use function sammo\tryRollbackInheritUniqueItem; @@ -113,7 +114,7 @@ class che_하야 extends Command\GeneralCommand{ } $general->setVar('troop', 0); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn(static::getName(), $this->arg)); $general->checkStatChange(); diff --git a/hwe/sammo/Command/Nation/che_감축.php b/hwe/sammo/Command/Nation/che_감축.php index 9e13975c..575f7d4e 100644 --- a/hwe/sammo/Command/Nation/che_감축.php +++ b/hwe/sammo/Command/Nation/che_감축.php @@ -17,6 +17,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_감축 extends Command\NationCommand{ @@ -199,7 +200,7 @@ class che_감축 extends Command\NationCommand{ $logger->pushGlobalActionLog("{$generalName}{$josaYi} {$destCityName}{$josaUl} 감축하였습니다."); $logger->pushGlobalHistoryLog("【감축】{$nationName}{$josaYiNation} {$destCityName}{$josaUl} 감축하였습니다."); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); $general->applyDB($db); diff --git a/hwe/sammo/Command/Nation/che_국기변경.php b/hwe/sammo/Command/Nation/che_국기변경.php index 50d045ac..cbcb5875 100644 --- a/hwe/sammo/Command/Nation/che_국기변경.php +++ b/hwe/sammo/Command/Nation/che_국기변경.php @@ -22,6 +22,7 @@ use function \sammo\newColor; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_국기변경 extends Command\NationCommand @@ -146,7 +147,7 @@ class che_국기변경 extends Command\NationCommand $logger->pushGlobalActionLog("{$generalName}{$josaYi} 국기를 변경하였습니다"); $logger->pushGlobalHistoryLog("【국기변경】{$nationName}{$josaYiNation} 국기를 변경하였습니다."); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); $general->applyDB($db); return true; diff --git a/hwe/sammo/Command/Nation/che_국호변경.php b/hwe/sammo/Command/Nation/che_국호변경.php index fd7b36de..68e53db8 100644 --- a/hwe/sammo/Command/Nation/che_국호변경.php +++ b/hwe/sammo/Command/Nation/che_국호변경.php @@ -19,6 +19,7 @@ use \sammo\CityConst; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_국호변경 extends Command\NationCommand @@ -152,7 +153,7 @@ class che_국호변경 extends Command\NationCommand $logger->pushGlobalActionLog("{$generalName}{$josaYi} 국호를 {$newNationName}{$josaRo} 변경합니다."); $logger->pushGlobalHistoryLog("【국호변경】{$nationName}{$josaYiNation} 국호를 {$newNationName}{$josaRo} 변경합니다."); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $this->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); $general->applyDB($db); return true; diff --git a/hwe/sammo/Command/Nation/che_증축.php b/hwe/sammo/Command/Nation/che_증축.php index a55b914b..b1ce0487 100644 --- a/hwe/sammo/Command/Nation/che_증축.php +++ b/hwe/sammo/Command/Nation/che_증축.php @@ -16,6 +16,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_증축 extends Command\NationCommand{ @@ -162,7 +163,7 @@ class che_증축 extends Command\NationCommand{ $general->addExperience(5 * ($this->getPreReqTurn() + 1)); $general->addDedication(5 * ($this->getPreReqTurn() + 1)); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $josaUl = JosaUtil::pick($destCityName, '을'); $josaYi = JosaUtil::pick($generalName, '이'); diff --git a/hwe/sammo/Command/Nation/che_천도.php b/hwe/sammo/Command/Nation/che_천도.php index 40e13a45..ec6738bd 100644 --- a/hwe/sammo/Command/Nation/che_천도.php +++ b/hwe/sammo/Command/Nation/che_천도.php @@ -17,6 +17,7 @@ use \sammo\Message; use \sammo\CityConst; use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_천도 extends Command\NationCommand @@ -219,7 +220,7 @@ class che_천도 extends Command\NationCommand ], 'nation=%i', $nationID); \sammo\refreshNationStaticInfo(); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $logger->pushGeneralActionLog("{$destCityName}{$josaRo} 천도했습니다. <1>$date"); $logger->pushGeneralHistoryLog("{$destCityName}{$josaRo} 천도명령"); $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$destCityName}{$josaRo} 천도 명령"); diff --git a/hwe/sammo/Command/Nation/che_초토화.php b/hwe/sammo/Command/Nation/che_초토화.php index 91d5b61c..5cb63e07 100644 --- a/hwe/sammo/Command/Nation/che_초토화.php +++ b/hwe/sammo/Command/Nation/che_초토화.php @@ -17,6 +17,7 @@ use \sammo\{ use \sammo\Constraint\Constraint; use \sammo\Constraint\ConstraintHelper; +use sammo\Enums\InheritanceKey; use sammo\Event\Action; class che_초토화 extends Command\NationCommand{ @@ -184,7 +185,7 @@ class che_초토화 extends Command\NationCommand{ \sammo\refreshNationStaticInfo(); \sammo\SetNationFront($nationID); - $general->increaseInheritancePoint('active_action', 1); + $general->increaseInheritancePoint(InheritanceKey::active_action, 1); $logger->pushGeneralActionLog("{$destCityName}{$josaUl} 초토화했습니다. <1>$date"); $logger->pushGeneralHistoryLog("{$destCityName}{$josaUl} 초토화 명령"); $logger->pushNationalHistoryLog("{$generalName}{$josaYi} {$destCityName}{$josaUl} 초토화 명령"); diff --git a/hwe/sammo/DefaultAction.php b/hwe/sammo/DefaultAction.php index 6b77c848..7b9cb9e0 100644 --- a/hwe/sammo/DefaultAction.php +++ b/hwe/sammo/DefaultAction.php @@ -2,7 +2,6 @@ namespace sammo; trait DefaultAction{ - public function getName():string{ return $this->name; } diff --git a/hwe/sammo/DummyGeneral.php b/hwe/sammo/DummyGeneral.php index 4470b2ea..29a20d8b 100644 --- a/hwe/sammo/DummyGeneral.php +++ b/hwe/sammo/DummyGeneral.php @@ -1,6 +1,9 @@ 1, ]; - const INHERITANCE_KEY = [ - 'previous' => [true, 1, '기존 포인트'], - 'lived_month' => [true, 1, '생존'], - 'max_belong' => [false, 10, '최대 임관년 수'], - 'max_domestic_critical' => [true, 1, '최대 연속 내정 성공'], - 'active_action' => [true, 3, '능동 행동 수'], - //'snipe_combat' => [true, 10, '병종 상성 우위 횟수'], - 'combat' => [['rank', 'warnum'], 5, '전투 횟수'], - 'sabotage' => [['rank', 'firenum'], 20, '계략 성공 횟수'], - 'unifier' => [true, 1, '천통 기여'], - 'dex' => [false, 0.001, '숙련도'], - 'tournament' => [true, 1, '토너먼트'], - 'betting' => [false, 10, '베팅 당첨'], - ]; - const TURNTIME_FULL_MS = -1; const TURNTIME_FULL = 0; const TURNTIME_HMS = 1; @@ -650,12 +637,13 @@ class General implements iAction } if ($refundPoint > 0) { - $this->increaseInheritancePoint('previous', $refundPoint); + $this->increaseInheritancePoint(InheritanceKey::previous, $refundPoint); } - $this->mergeTotalInheritancePoint(); - applyInheritanceUser($this->getVar('owner')); - $this->clearInheritancePoint(); + $inheritPointManager = InheritancePointManager::getInstance(); + $inheritPointManager->mergeTotalInheritancePoint($this); + $inheritPointManager->applyInheritanceUser($this->getVar('owner')); + $inheritPointManager->clearInheritancePoint($this); } @@ -712,11 +700,13 @@ class General implements iAction $generalName = $this->getName(); + $inheritPointManager = InheritancePointManager::getInstance(); + $ownerID = $this->getVar('owner'); if ($ownerID) { - $this->mergeTotalInheritancePoint(); - applyInheritanceUser($ownerID, true); - $this->clearInheritancePoint(); + $inheritPointManager->mergeTotalInheritancePoint($this); + $inheritPointManager->applyInheritanceUser($ownerID, true); + $inheritPointManager->clearInheritancePoint($this); } $this->multiplyVarWithLimit('leadership', 0.85, 10); @@ -1332,237 +1322,23 @@ class General implements iAction return $result; } - /** - * @return int|float - */ - public function getInheritancePoint(string $key, &$aux = null, bool $forceCalc = false) + public function getInheritancePoint(InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float { - $inheritType = static::INHERITANCE_KEY[$key] ?? null; - if ($inheritType === null) { - throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); - } - - $ownerID = $this->getVar('owner'); - if (!$ownerID) { - return 0; - } - - if ($this->getVar('npc') >= 2) { - return 0; - } - - [$storeType, $multiplier,] = $inheritType; - - $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - if ($storeType === true || ($gameStor->isunited != 0 && !$forceCalc)) { - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); - [$value, $aux] = $inheritStor->getValue($key); - return $value; - } - - if (is_array($storeType)) { - [$storSubType, $storSubKey] = $storeType; - if ($storSubType === 'rank') { - return $this->getRankVar($storSubKey) * $multiplier; - } - if ($storSubType === 'raw') { - return $this->getVar($storSubKey) * $multiplier; - } - if ($storSubType === 'aux') { - return ($this->getAuxVar($storSubKey) ?? 0) * $multiplier; - } - throw new \InvalidArgumentException("{$storSubType}은 참조 할 수 없는 유산 세부키임"); - } - - if ($storeType !== false) { - throw new \InvalidArgumentException("{$storeType}은 올바르지 않은 유산 키임"); - } - - $extractFn = function () { - return [0, null]; - }; - switch ($key) { - case 'dex': - $extractFn = function () use ($multiplier) { - $dexLimit = Util::array_last(getDexLevelList())[0]; - $totalDex = 0; - foreach (array_keys(GameUnitConst::allType()) as $armType) { - $subDex = $this->getVar("dex{$armType}"); - if($subDex > $dexLimit){ - $totalDex += ($subDex - $dexLimit) / 3; - $subDex = $dexLimit; - } - $totalDex += $subDex; - } - return [$totalDex * $multiplier, null]; - }; - break; - case 'betting': - $extractFn = function () use ($multiplier) { - $betWin = $this->getRankVar('betwin'); - $betWinRate = $this->getRankVar('betwingold') / max(1, $this->getRankVar('betgold')); - - return [$betWin * $multiplier * pow($betWinRate, 2), null]; - }; - break; - case 'max_belong': - $extractFn = function () use ($multiplier) { - $maxBelong = max($this->getVar('belong'), $this->getAuxVar('max_belong') ?? 0); - return [$maxBelong * $multiplier, null]; - }; - break; - default: - throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음"); - } - - [$value, $aux] = ($extractFn)(); - return $value; + return InheritancePointManager::getInstance()->getInheritancePoint($this, $key, $aux, $forceCalc); } - public function setInheritancePoint(string $key, $value, $aux = null) + public function setInheritancePoint(InheritanceKey $key, $value, $aux = null) { - if (!is_int($value) && !is_float($value)) { - throw new \InvalidArgumentException("{$value}는 숫자가 아님"); - } - $inheritType = static::INHERITANCE_KEY[$key] ?? null; - if ($inheritType === null) { - throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); - } - - [$storeType, $multiplier,] = $inheritType; - if ($storeType !== true) { - throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); - } - if ($multiplier != 1 && $value != 0) { - throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님"); - } - - $ownerID = $this->getVar('owner'); - if (!$ownerID) { - return; - } - - if ($this->getVar('npc') >= 2) { - return; - } - - $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - if ($gameStor->isunited != 0) { - return; - } - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); - $inheritStor->setValue($key, [$value, $aux]); + return InheritancePointManager::getInstance()->setInheritancePoint($this, $key, $value, $aux); } - public function increaseInheritancePoint(string $key, $value, $aux = null) + public function increaseInheritancePoint(InheritanceKey $key, $value, $aux = null) { - if (!is_int($value) && !is_float($value)) { - throw new \InvalidArgumentException("{$value}는 숫자가 아님"); - } - - $inheritType = static::INHERITANCE_KEY[$key] ?? null; - if ($inheritType === null) { - throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); - } - - [$storeType, $multiplier,] = $inheritType; - if ($storeType !== true) { - throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); - } - - $ownerID = $this->getVar('owner'); - if (!$ownerID) { - return; - } - - if ($this->getVar('npc') >= 2) { - return; - } - - $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - if ($gameStor->isunited != 0) { - return; - } - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); - [$oldValue, $oldAux] = $inheritStor->getValue($key) ?? [0, null]; - - if ($oldAux !== $aux) { - $oldValue = 0; - } - - $newValue = $oldValue + $value * $multiplier; - $inheritStor->setValue($key, [$newValue, $aux]); - } - - public function clearInheritancePoint(){ - $ownerID = $this->getVar('owner'); - if(!$ownerID){ - return; - } - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); - $allPoints = $inheritStor->getAll(); - if (!$allPoints || count($allPoints) == 0) { - //비었으므로 리셋 안함 - return; - } - if (count($allPoints) == 1 && key_exists('previous', $allPoints)) { - //이미 리셋되었으므로 리셋 안함 - return; - } - - $previousPointInfo = $allPoints['previous']; - $inheritStor->resetValues(); - $inheritStor->setValue('previous', $previousPointInfo); + return InheritancePointManager::getInstance()->increaseInheritancePoint($this, $key, $value, $aux); } public function mergeTotalInheritancePoint(bool $isEnd=false) { - $ownerID = $this->getVar('owner'); - if (!$ownerID) { - return; - } - - if ($this->getVar('npc') > 1){ - return; - } - - $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); - $gameStor->cacheValues(['year', 'startyear', 'month']); - - if ($this->getVar('npc') == 1) { - if(!$isEnd){ - return; - } - - $pickYearMonth = $this->getAuxVar('pickYearMonth'); - if($pickYearMonth === null){ - return; - } - [$startYear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']); - - if(($year - $pickYearMonth) * 2 <= ($year - $startYear)){ - return; - } - } - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); - $inheritStor->cacheAll(); - foreach (static::INHERITANCE_KEY as $key => [$storType,,]) { - $aux = null; - $point = $this->getInheritancePoint($key, $aux, true); - if ($storType === true) { - continue; - } - $inheritStor->setValue($key, [$point, $aux]); - } - - $oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result"); - $serverID = UniqueConst::$serverID; - $year = $gameStor->year; - $month = $gameStor->month; - $oldInheritStor->setValue("{$serverID}_{$ownerID}_{$this->getID()}_{$year}_{$month}", $inheritStor->getAll(true)); + InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isEnd); } } diff --git a/hwe/sammo/InheritancePointManager.php b/hwe/sammo/InheritancePointManager.php new file mode 100644 index 00000000..0ef90a29 --- /dev/null +++ b/hwe/sammo/InheritancePointManager.php @@ -0,0 +1,326 @@ +inheritanceKey = [ + InheritanceKey::previous->value => new InheritancePointType(true, 1, '기존 포인트'), + InheritanceKey::lived_month->value => new InheritancePointType(true, 1, '생존'), + InheritanceKey::max_belong->value => new InheritancePointType(false, 10, '최대 임관년 수'), + InheritanceKey::max_domestic_critical->value => new InheritancePointType(true, 1, '최대 연속 내정 성공'), + InheritanceKey::active_action->value => new InheritancePointType(true, 3, '능동 행동 수'), + //InheritanceKey::snipe_combat->value => new InheritancePointType(true, 10, '병종 상성 우위 횟수'), + InheritanceKey::combat->value => new InheritancePointType(['rank', 'warnum'], 5, '전투 횟수'), + InheritanceKey::sabotage->value => new InheritancePointType(['rank', 'firenum'], 20, '계략 성공 횟수'), + InheritanceKey::unifier->value => new InheritancePointType(true, 1, '천통 기여'), + InheritanceKey::dex->value => new InheritancePointType(false, 0.001, '숙련도'), + InheritanceKey::tournament->value => new InheritancePointType(true, 1, '토너먼트'), + InheritanceKey::betting->value => new InheritancePointType(false, 10, '베팅 당첨'), + ]; + } + + public static function getInstance(): self + { + if (!self::$instance) { + self::$instance = new self(); + } + return self::$instance; + } + + public function getInheritancePointType(InheritanceKey $key): InheritancePointType + { + if (!key_exists($key->value, $this->inheritanceKey)) { + throw new \OutOfRangeException("{$key}는 유산 타입이 아님"); + } + return $this->inheritanceKey[$key->value]; + } + + public function getInheritancePoint(General $general, InheritanceKey $key, &$aux = null, bool $forceCalc = false) + { + $inheritType = $this->getInheritancePointType($key); + + $ownerID = $general->getVar('owner'); + if (!$ownerID) { + return 0; + } + + if ($general->getVar('npc') >= 2) { + return 0; + } + + $storeType = $inheritType->storeType; + $multiplier = $inheritType->pointCoeff; + + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + if ($storeType === true || ($gameStor->isunited != 0 && !$forceCalc)) { + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + [$value, $aux] = $inheritStor->getValue($key); + return $value; + } + + if (is_array($storeType)) { + [$storSubType, $storSubKey] = $storeType; + if ($storSubType === 'rank') { + return $general->getRankVar($storSubKey) * $multiplier; + } + if ($storSubType === 'raw') { + return $general->getVar($storSubKey) * $multiplier; + } + if ($storSubType === 'aux') { + return ($general->getAuxVar($storSubKey) ?? 0) * $multiplier; + } + throw new \InvalidArgumentException("{$storSubType}은 참조 할 수 없는 유산 세부키임"); + } + + if ($storeType !== false) { + throw new \InvalidArgumentException("{$storeType}은 올바르지 않은 유산 키임"); + } + + $extractFn = function () { + return [0, null]; + }; + switch ($key) { + case 'dex': + $extractFn = function () use ($general, $multiplier) { + $dexLimit = Util::array_last(getDexLevelList())[0]; + $totalDex = 0; + foreach (array_keys(GameUnitConst::allType()) as $armType) { + $subDex = $general->getVar("dex{$armType}"); + if ($subDex > $dexLimit) { + $totalDex += ($subDex - $dexLimit) / 3; + $subDex = $dexLimit; + } + $totalDex += $subDex; + } + return [$totalDex * $multiplier, null]; + }; + break; + case 'betting': + $extractFn = function () use ($general, $multiplier) { + $betWin = $general->getRankVar('betwin'); + $betWinRate = $general->getRankVar('betwingold') / max(1, $general->getRankVar('betgold')); + + return [$betWin * $multiplier * pow($betWinRate, 2), null]; + }; + break; + case 'max_belong': + $extractFn = function () use ($general, $multiplier) { + $maxBelong = max($general->getVar('belong'), $general->getAuxVar('max_belong') ?? 0); + return [$maxBelong * $multiplier, null]; + }; + break; + default: + throw new \InvalidArgumentException("{$key}는 유산 추출기를 보유하고 있지 않음"); + } + + [$value, $aux] = ($extractFn)(); + return $value; + } + + + public function setInheritancePoint(General $general, InheritanceKey $key, $value, $aux = null) + { + if (!is_int($value) && !is_float($value)) { + throw new \InvalidArgumentException("{$value}는 숫자가 아님"); + } + $inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key); + + $storeType = $inheritType->storeType; + $multiplier = $inheritType->pointCoeff; + if ($storeType !== true) { + throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); + } + if ($multiplier != 1 && $value != 0) { + throw new \InvalidArgumentException("{$key}는 1:1 유산 포인트가 아님"); + } + + $ownerID = $general->getVar('owner'); + if (!$ownerID) { + return; + } + + if ($general->getVar('npc') >= 2) { + return; + } + + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + if ($gameStor->isunited != 0) { + return; + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + $inheritStor->setValue($key, [$value, $aux]); + } + + public function increaseInheritancePoint(General $general, InheritanceKey $key, $value, $aux = null) + { + if (!is_int($value) && !is_float($value)) { + throw new \InvalidArgumentException("{$value}는 숫자가 아님"); + } + + $inheritType = InheritancePointManager::getInstance()->getInheritancePointType($key); + + $storeType = $inheritType->storeType; + $multiplier = $inheritType->pointCoeff; + if ($storeType !== true) { + throw new \InvalidArgumentException("{$key}는 직접 저장형 유산 포인트가 아님"); + } + + $ownerID = $general->getVar('owner'); + if (!$ownerID) { + return; + } + + if ($general->getVar('npc') >= 2) { + return; + } + + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + if ($gameStor->isunited != 0) { + return; + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + [$oldValue, $oldAux] = $inheritStor->getValue($key->value) ?? [0, null]; + + if ($oldAux !== $aux) { + $oldValue = 0; + } + + $newValue = $oldValue + $value * $multiplier; + $inheritStor->setValue($key->value, [$newValue, $aux]); + } + + public function clearInheritancePoint(General $general){ + $ownerID = $general->getVar('owner'); + if(!$ownerID){ + return; + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + $allPoints = $inheritStor->getAll(); + if (!$allPoints || count($allPoints) == 0) { + //비었으므로 리셋 안함 + return; + } + if (count($allPoints) == 1 && key_exists(InheritanceKey::previous->value, $allPoints)) { + //이미 리셋되었으므로 리셋 안함 + return; + } + + $previousPointInfo = $allPoints[InheritanceKey::previous->value]; + $inheritStor->resetValues(); + $inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo); +} + + public function mergeTotalInheritancePoint(General $general, bool $isEnd = false) + { + $ownerID = $general->getVar('owner'); + if (!$ownerID) { + return; + } + + if ($general->getVar('npc') > 1) { + return; + } + + $gameStor = KVStorage::getStorage(DB::db(), 'game_env'); + $gameStor->cacheValues(['year', 'startyear', 'month']); + + if ($general->getVar('npc') == 1) { + if (!$isEnd) { + return; + } + + $pickYearMonth = $general->getAuxVar('pickYearMonth'); + if ($pickYearMonth === null) { + return; + } + [$startYear, $year] = $gameStor->getValuesAsArray(['startyear', 'year']); + + if (($year - $pickYearMonth) * 2 <= ($year - $startYear)) { + return; + } + } + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); + $inheritStor->cacheAll(); + foreach ($this->inheritanceKey as $rKey => $keyObj) { + $key = InheritanceKey::from($rKey); + $storeType = $keyObj->storeType; + $aux = null; + $point = $general->getInheritancePoint($key, $aux, true); + if ($storeType === true) { + continue; + } + $inheritStor->setValue($key, [$point, $aux]); + } + + $oldInheritStor = KVStorage::getStorage(DB::db(), "inheritance_result"); + $serverID = UniqueConst::$serverID; + $year = $gameStor->year; + $month = $gameStor->month; + $oldInheritStor->setValue("{$serverID}_{$ownerID}_{$general->getID()}_{$year}_{$month}", $inheritStor->getAll(true)); + } + + + function applyInheritanceUser(int $userID, bool $isRebirth = false): float + { + if ($userID === 0) { + return 0; + } + + //FIXME: 굳이 merge, apply, clean 3단계를 거쳐야 할 이유가 없음 + /** @var array[InheritanceKey]float */ + $rebirthDegraded = [ + InheritanceKey::dex => 0.5, + ]; + + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); + $totalPoint = 0; + /** @var array[InheritanceKey][float, string|float] */ + $allPoints = $inheritStor->getAll(); + if (!$allPoints || count($allPoints) == 0) { + //비었으므로 리셋 안함 + return 0; + } + if (count($allPoints) == 1 && key_exists(InheritanceKey::previous->value, $allPoints)) { + //이미 리셋되었으므로 리셋 안함 + return $allPoints[InheritanceKey::previous->value][0]; + } + + $userLogger = new UserLogger($userID); + + $previousPoint = ($allPoints[InheritanceKey::previous->value] ?? [0, 0])[0]; + + foreach ($allPoints as $rKey => [$value,]) { + $key = InheritanceKey::from($rKey); + if ($isRebirth && key_exists($key, $rebirthDegraded)) { + $value *= $rebirthDegraded[$key]; + } + $keyText = $this->getInheritancePointType($key)->info; + $userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint"); + $totalPoint += $value; + } + $totalPoint = Util::toInt($totalPoint); + $userLogger->push("포인트 {$previousPoint} => {$totalPoint}", "inheritPoint"); + $userLogger->flush(); + + $inheritStor->resetValues(); + $inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]); + return $totalPoint; + } + + +} diff --git a/hwe/sammo/TurnExecutionHelper.php b/hwe/sammo/TurnExecutionHelper.php index fcd34031..d6029d83 100644 --- a/hwe/sammo/TurnExecutionHelper.php +++ b/hwe/sammo/TurnExecutionHelper.php @@ -2,6 +2,7 @@ namespace sammo; +use sammo\Enums\InheritanceKey; use \Symfony\Component\Lock; class TurnExecutionHelper @@ -260,7 +261,7 @@ class TurnExecutionHelper $autorunMode = false; $ai = null; - $general->increaseInheritancePoint('lived_month', 1); + $general->increaseInheritancePoint(InheritanceKey::lived_month, 1); $turnObj->preprocessCommand($env); diff --git a/hwe/sammo/VO/InheritancePointType.php b/hwe/sammo/VO/InheritancePointType.php new file mode 100644 index 00000000..9b526e3d --- /dev/null +++ b/hwe/sammo/VO/InheritancePointType.php @@ -0,0 +1,13 @@ +getInheritancePoint($key) ?? 0; } diff --git a/hwe/v_join.php b/hwe/v_join.php index a639ce1e..a059ab82 100644 --- a/hwe/v_join.php +++ b/hwe/v_join.php @@ -38,7 +38,8 @@ if ($gencount >= $admin['maxgeneral']) { die(WebUtil::errorBackMsg("더 이상 등록할 수 없습니다.")); } -$inheritTotalPoint = applyInheritanceUser($userID); +$inheritPointManager = InheritancePointManager::getInstance(); +$inheritTotalPoint = $inheritPointManager->applyInheritanceUser($userID); $nationList = $db->query('SELECT nation,`name`,color,scout FROM nation'); $nationList = Util::convertArrayToDict($nationList, 'nation'); @@ -60,7 +61,7 @@ foreach ($scoutMsgs as $destNationID => $scoutMsg) { [ + 'staticValues' => [ 'serverID' => UniqueConst::$serverID, 'nationList' => array_values($nationList), 'config' => [ @@ -72,8 +73,8 @@ foreach ($scoutMsgs as $destNationID => $scoutMsg) { 'picture' => $member['picture'], 'imgsvr' => $member['imgsvr'], ], - 'inheritTotalPoint'=>$inheritTotalPoint, - 'turnterm'=>$gameStor->turnterm, + 'inheritTotalPoint' => $inheritTotalPoint, + 'turnterm' => $gameStor->turnterm, ] ]) ?>