From 50a75e4543ad3c9a25dcd3994fe5ce1143eb184d Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 2 Oct 2022 19:41:38 +0900 Subject: [PATCH] =?UTF-8?q?refac,=20game:=20=EC=9D=80=ED=87=B4=20=EC=8B=9C?= =?UTF-8?q?=20=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B0=98=EC=98=81=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD=20-=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=ED=95=98=EC=A7=80=20=EC=95=8A=EA=B3=A0=20=EC=9D=80=ED=87=B4=20?= =?UTF-8?q?=EC=9D=B4=ED=9B=84=EB=A1=9C=20=EB=84=98=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EC=B6=94=EA=B0=80=20-=20?= =?UTF-8?q?=EC=9D=80=ED=87=B4=EC=8B=9C=20=EA=B3=84=EC=88=98=EB=A5=BC=20Obj?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/_admin_force_rehall.php | 3 +- hwe/func_gamerule.php | 3 +- hwe/sammo/General.php | 8 ++-- hwe/sammo/InheritancePointManager.php | 63 ++++++++++++++++----------- hwe/sammo/VO/InheritancePointType.php | 1 + 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/hwe/_admin_force_rehall.php b/hwe/_admin_force_rehall.php index b62f6b28..b4bce2b8 100644 --- a/hwe/_admin_force_rehall.php +++ b/hwe/_admin_force_rehall.php @@ -27,7 +27,6 @@ foreach ($db->queryFirstColumn( $inheritPointManager = InheritancePointManager::getInstance(); foreach(General::createGeneralObjListFromDB($db->queryFirstColumn('SELECT `no` FROM general WHERE npc = 0')) as $genObj){ - $inheritPointManager->mergeTotalInheritancePoint($genObj, true); + $inheritPointManager->mergeTotalInheritancePoint($genObj); $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); - $inheritPointManager->clearInheritancePoint($genObj); } \ No newline at end of file diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 681ce19b..623f4b5a 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -1092,9 +1092,8 @@ function checkEmperior() } processSumInheritPointRank(); foreach ($allUserGenerals as $genObj) { - $inheritPointManager->mergeTotalInheritancePoint($genObj, true); + $inheritPointManager->mergeTotalInheritancePoint($genObj); $inheritPointManager->applyInheritanceUser($genObj->getVar('owner')); - $inheritPointManager->clearInheritancePoint($genObj); } $gameStor->isunited = 2; diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 6e05fdf0..041f58f1 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -626,7 +626,6 @@ class General implements iAction $inheritPointManager = InheritancePointManager::getInstance(); $inheritPointManager->mergeTotalInheritancePoint($this); $inheritPointManager->applyInheritanceUser($this->getVar('owner')); - $inheritPointManager->clearInheritancePoint($this); } @@ -686,9 +685,8 @@ class General implements iAction $ownerID = $this->getVar('owner'); if ($ownerID) { - $inheritPointManager->mergeTotalInheritancePoint($this); + $inheritPointManager->mergeTotalInheritancePoint($this, true); $inheritPointManager->applyInheritanceUser($ownerID, true); - $inheritPointManager->clearInheritancePoint($this); } $this->multiplyVarWithLimit('leadership', 0.85, 10); @@ -1331,8 +1329,8 @@ class General implements iAction return InheritancePointManager::getInstance()->increaseInheritancePoint($this, $key, $value, $aux); } - public function mergeTotalInheritancePoint(bool $isEnd = false) + public function mergeTotalInheritancePoint(bool $isRebirth = false) { - InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isEnd); + InheritancePointManager::getInstance()->mergeTotalInheritancePoint($this, $isRebirth); } } diff --git a/hwe/sammo/InheritancePointManager.php b/hwe/sammo/InheritancePointManager.php index 9a837988..7f9025e7 100644 --- a/hwe/sammo/InheritancePointManager.php +++ b/hwe/sammo/InheritancePointManager.php @@ -17,18 +17,18 @@ class InheritancePointManager private function __construct() { $inheritanceKey = new Map(); - $inheritanceKey->put(InheritanceKey::previous, new InheritancePointType(true, 1, '기존 포인트')); - $inheritanceKey->put(InheritanceKey::lived_month, new InheritancePointType(true, 1, '생존')); - $inheritanceKey->put(InheritanceKey::max_belong, new InheritancePointType(false, 10, '최대 임관년 수')); - $inheritanceKey->put(InheritanceKey::max_domestic_critical, new InheritancePointType(true, 1, '최대 연속 내정 성공')); - $inheritanceKey->put(InheritanceKey::active_action, new InheritancePointType(true, 3, '능동 행동 수')); + $inheritanceKey->put(InheritanceKey::previous, new InheritancePointType(true, 1, '기존 포인트', 1)); + $inheritanceKey->put(InheritanceKey::lived_month, new InheritancePointType(true, 1, '생존', 1)); + $inheritanceKey->put(InheritanceKey::max_belong, new InheritancePointType(false, 10, '최대 임관년 수', null)); + $inheritanceKey->put(InheritanceKey::max_domestic_critical, new InheritancePointType(true, 1, '최대 연속 내정 성공', null)); + $inheritanceKey->put(InheritanceKey::active_action, new InheritancePointType(true, 3, '능동 행동 수', 1)); //$inheritanceKey->put(InheritanceKey::snipe_combat, new InheritancePointType(true, 10, '병종 상성 우위 횟수')); - $inheritanceKey->put(InheritanceKey::combat, new InheritancePointType(['rank', RankColumn::warnum], 5, '전투 횟수')); - $inheritanceKey->put(InheritanceKey::sabotage, new InheritancePointType(['rank', RankColumn::firenum], 20, '계략 성공 횟수')); - $inheritanceKey->put(InheritanceKey::unifier, new InheritancePointType(true, 1, '천통 기여')); - $inheritanceKey->put(InheritanceKey::dex, new InheritancePointType(false, 0.001, '숙련도')); - $inheritanceKey->put(InheritanceKey::tournament, new InheritancePointType(true, 1, '토너먼트')); - $inheritanceKey->put(InheritanceKey::betting, new InheritancePointType(false, 10, '베팅 당첨')); + $inheritanceKey->put(InheritanceKey::combat, new InheritancePointType(['rank', RankColumn::warnum], 5, '전투 횟수', 1)); + $inheritanceKey->put(InheritanceKey::sabotage, new InheritancePointType(['rank', RankColumn::firenum], 20, '계략 성공 횟수', 1)); + $inheritanceKey->put(InheritanceKey::unifier, new InheritancePointType(true, 1, '천통 기여', null)); + $inheritanceKey->put(InheritanceKey::dex, new InheritancePointType(false, 0.001, '숙련도', 0.5)); + $inheritanceKey->put(InheritanceKey::tournament, new InheritancePointType(true, 1, '토너먼트', 0.5)); + $inheritanceKey->put(InheritanceKey::betting, new InheritancePointType(false, 10, '베팅 당첨', null)); $this->inheritanceKey = $inheritanceKey; } @@ -258,9 +258,8 @@ class InheritancePointManager $inheritStor->setValue($key->value, [$newValue, $aux]); } - public function clearInheritancePoint(General $general) + public function clearInheritancePoint(?int $ownerID) { - $ownerID = $general->getVar('owner'); if (!$ownerID) { return; } @@ -281,7 +280,7 @@ class InheritancePointManager $inheritStor->setValue(InheritanceKey::previous->value, $previousPointInfo); } - public function mergeTotalInheritancePoint(General $general, bool $isEnd = false) + public function mergeTotalInheritancePoint(General $general, bool $isRebirth = false) { $ownerID = $general->getVar('owner'); if (!$ownerID) { @@ -296,7 +295,7 @@ class InheritancePointManager $gameStor->cacheValues(['year', 'startyear', 'month']); if ($general->getVar('npc') == 1) { - if (!$isEnd) { + if ($isRebirth) { return; } @@ -331,18 +330,14 @@ class InheritancePointManager } - function applyInheritanceUser(int $userID, bool $isRebirth = false): float + function applyInheritanceUser(int $ownerID, bool $isRebirth = false): float { - if ($userID === 0) { + if ($ownerID === 0) { return 0; } //FIXME: 굳이 merge, apply, clean 3단계를 거쳐야 할 이유가 없음 - /** @var Map */ - $rebirthDegraded = new Map(); - $rebirthDegraded[InheritanceKey::dex] = 0.5; - - $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); + $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$ownerID}"); $totalPoint = 0; /** @var array */ $allPoints = $inheritStor->getAll(); @@ -355,15 +350,27 @@ class InheritancePointManager return $allPoints[InheritanceKey::previous->value][0]; } - $userLogger = new UserLogger($userID); + $userLogger = new UserLogger($ownerID); $previousPoint = ($allPoints[InheritanceKey::previous->value] ?? [0, 0])[0]; - foreach ($allPoints as $rKey => [$value,]) { + $keepValues = []; + + foreach ($allPoints as $rKey => [$value, $auxV]) { $key = InheritanceKey::from($rKey); - if ($isRebirth && $rebirthDegraded->hasKey($key)) { - $value *= $rebirthDegraded[$key]; + + /** @var InheritancePointType */ + $keyTypeObj = $this->inheritanceKey->get($key); + + if($isRebirth){ + if($keyTypeObj->rebirthStoreCoeff === null){ + $keepValues[$rKey] = [$value, $auxV]; + continue; + } + + $value *= $keyTypeObj->rebirthStoreCoeff; } + $keyText = $this->getInheritancePointType($key)->info; $userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint"); $totalPoint += $value; @@ -373,6 +380,10 @@ class InheritancePointManager $userLogger->flush(); $inheritStor->resetValues(); + + foreach($keepValues as $rKey => $pointPair){ + $inheritStor->setValue($rKey, $pointPair); + } $inheritStor->setValue(InheritanceKey::previous->value, [$totalPoint, null]); return $totalPoint; } diff --git a/hwe/sammo/VO/InheritancePointType.php b/hwe/sammo/VO/InheritancePointType.php index 9b526e3d..4ca6d410 100644 --- a/hwe/sammo/VO/InheritancePointType.php +++ b/hwe/sammo/VO/InheritancePointType.php @@ -5,6 +5,7 @@ class InheritancePointType{ public bool|array $storeType, public int|float $pointCoeff, public string $info, + public ?float $rebirthStoreCoeff, ) {