diff --git a/hwe/func.php b/hwe/func.php index 79f88d20..050ab21e 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1622,6 +1622,7 @@ function giveRandomUniqueItem(General $general, string $acquireType): bool if ($general->getAuxVar('inheritRandomUnique')) { $general->setAuxVar('inheritRandomUnique', null); $general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -GameConst::$inheritItemRandomPoint); $userLogger = new UserLogger($general->getVar('owner')); $userLogger->push(sprintf("얻을 유니크가 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); } @@ -1692,6 +1693,7 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r [,, $amount] = $ownTrial; $trialStor->deleteValue("u{$ownerID}"); $general->increaseInheritancePoint(InheritanceKey::previous, $amount); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -$amount); LogText("선택유니크 롤백포인트:{$ownerID}", $amount); $userLogger = new UserLogger($ownerID); @@ -1907,6 +1909,7 @@ function tryUniqueItemLottery(General $general, string $acquireType = '아이템 if ($general->getAuxVar('inheritRandomUnique')) { $general->setAuxVar('inheritRandomUnique', null); $general->increaseInheritancePoint(InheritanceKey::previous, GameConst::$inheritItemRandomPoint); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -GameConst::$inheritItemRandomPoint); $userLogger = new UserLogger($general->getVar('owner')); $userLogger->push(sprintf("유니크를 얻을 공간이 없어 %d 포인트 반환", GameConst::$inheritItemRandomPoint), "inheritPoint"); } diff --git a/hwe/func_time_event.php b/hwe/func_time_event.php index d25c055d..5ed7e025 100644 --- a/hwe/func_time_event.php +++ b/hwe/func_time_event.php @@ -1,8 +1,9 @@ update( + $generals = General::createGeneralObjListFromDB(null, null, 2); + + $points = new Map(); + $points->allocate(count($generals)); + foreach($generals as $general){ + $generalID = $general->getID(); + $points[$generalID] = 0; + } + + foreach(InheritanceKey::cases() as $key){ + if($key === InheritanceKey::previous){ + continue; + } + $subPoints = InheritancePointManager::getInstance()->getInheritancePointFromAll($generals, $key); + foreach($generals as $general){ + $generalID = $general->getID(); + $points[$generalID] += $subPoints[$generalID] ?? 0; + } + } + + $pointsPairs = []; + foreach($points as $generalID => $point){ + $pointsPairs[] = [ + 'nation_id' => $generals[$generalID]->getNationID(), + 'general_id' => $generalID, + 'type' => RankColumn::inherit_point_earned_by_merge->value, + 'value' => $point, + ]; + } + //XXX: multiple batch update가 제공되지 않으므로.. + $db->delete('rank_data', '`type` = %s', RankColumn::inherit_point_earned_by_merge->value); + $db->insert('rank_data', $pointsPairs); + + $db->query( 'UPDATE `rank_data` D SET `value` = (SELECT SUM(`value`) FROM `rank_data` S WHERE S.general_id = D.general_id AND S.`type` IN %ls) WHERE D.`type` = %s', [RankColumn::inherit_point_earned_by_action->value, RankColumn::inherit_point_earned_by_merge->value], RankColumn::inherit_point_earned->value ); - $db->update( + $db->query( 'UPDATE `rank_data` D SET `value` = (SELECT `value` FROM `rank_data` S WHERE S.general_id = D.general_id AND S.`type` = %s) WHERE D.`type` = %s', RankColumn::inherit_point_spent_dynamic->value, RankColumn::inherit_point_spent->value diff --git a/hwe/sammo/API/General/Join.php b/hwe/sammo/API/General/Join.php index 2aad0242..ac07d253 100644 --- a/hwe/sammo/API/General/Join.php +++ b/hwe/sammo/API/General/Join.php @@ -387,6 +387,9 @@ class Join extends \sammo\BaseAPI $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); $inheritStor->setValue('previous', [$inheritTotalPoint - $inheritRequiredPoint, null]); $userLogger->flush(); + $db->update('rank_data', [ + 'value'=>$db->sqleval('value + %i', $inheritRequiredPoint) + ], 'general_id = %i AND type = %s', $generalID, RankColumn::inherit_point_spent_dynamic->value); } $me = [ diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php index adc9ece0..155a8057 100644 --- a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -5,6 +5,7 @@ namespace sammo\API\InheritAction; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -80,6 +81,7 @@ class BuyHiddenBuff extends \sammo\BaseAPI $inheritBuffList[$type] = $level; $general->setAuxVar('inheritBuff', $inheritBuffList); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqAmount); $general->applyDB($db); return null; } diff --git a/hwe/sammo/API/InheritAction/BuyRandomUnique.php b/hwe/sammo/API/InheritAction/BuyRandomUnique.php index 209f5dae..e8e77b66 100644 --- a/hwe/sammo/API/InheritAction/BuyRandomUnique.php +++ b/hwe/sammo/API/InheritAction/BuyRandomUnique.php @@ -5,6 +5,7 @@ namespace sammo\API\InheritAction; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -52,6 +53,7 @@ class BuyRandomUnique extends \sammo\BaseAPI $general->setAuxVar('inheritRandomUnique', TimeUtil::now()); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqAmount); $general->applyDB($db); return null; } diff --git a/hwe/sammo/API/InheritAction/BuySpecificUnique.php b/hwe/sammo/API/InheritAction/BuySpecificUnique.php index 16bc5806..d97da7c5 100644 --- a/hwe/sammo/API/InheritAction/BuySpecificUnique.php +++ b/hwe/sammo/API/InheritAction/BuySpecificUnique.php @@ -5,6 +5,7 @@ namespace sammo\API\InheritAction; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -82,6 +83,7 @@ class BuySpecificUnique extends \sammo\BaseAPI $itemTrials[$itemKey] = $amount; $general->setAuxVar('inheritUniqueTrial', $itemTrials); $inheritStor->setValue('previous', [$previousPoint - $amount, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $amount); $trialStor->setValue("u{$userID}", [$userID, $generalID, $amount]); $general->applyDB($db); return null; diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php index 35297fdf..62bb6025 100644 --- a/hwe/sammo/API/InheritAction/ResetSpecialWar.php +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -5,6 +5,7 @@ namespace sammo\API\InheritAction; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -68,6 +69,7 @@ class ResetSpecialWar extends \sammo\BaseAPI $general->setAuxVar('inheritResetSpecialWar', $nextLevel); $general->setVar('special2', 'None'); $inheritStor->setValue('previous', [$previousPoint - $reqPoint, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqPoint); $general->applyDB($db); return null; } diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php index 08e1d370..89a44e0f 100644 --- a/hwe/sammo/API/InheritAction/ResetTurnTime.php +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -6,6 +6,7 @@ use DateTimeImmutable; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -77,6 +78,7 @@ class ResetTurnTime extends \sammo\BaseAPI $general->setVar('turntime', TimeUtil::format($turnTime, true)); $general->setAuxVar('inheritResetTurnTime', $nextLevel); $inheritStor->setValue('previous', [$previousPoint - $reqPoint, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqPoint); $general->applyDB($db); return null; } diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php index c8bc189b..30a31e51 100644 --- a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -5,6 +5,7 @@ namespace sammo\API\InheritAction; use sammo\Session; use DateTimeInterface; use sammo\DB; +use sammo\Enums\RankColumn; use sammo\GameConst; use sammo\General; use sammo\KVStorage; @@ -77,6 +78,7 @@ class SetNextSpecialWar extends \sammo\BaseAPI $general->setAuxVar('inheritSpecificSpecialWar', $type); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); + $general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $reqAmount); $general->applyDB($db); return null; } diff --git a/hwe/sammo/Betting.php b/hwe/sammo/Betting.php index 0cf8c44a..28ae7877 100644 --- a/hwe/sammo/Betting.php +++ b/hwe/sammo/Betting.php @@ -166,6 +166,9 @@ class Betting $userLogger = new UserLogger($userID); $userLogger->push("{$amount} 포인트를 베팅에 사용", "inheritPoint"); $userLogger->flush(); + $db->update('rank_data', [ + 'value'=>$db->sqleval('value + %i', $amount) + ], 'general_id = %i AND type = %s', $generalID, RankColumn::inherit_point_spent_dynamic->value); } else { $db->update('general', [ 'gold' => $db->sqleval('gold - %i', $amount) @@ -363,6 +366,11 @@ class Betting $inheritStor->setValue('previous', [$nextPoint, 0]); $inheritStor->invalidateCacheValue('previous'); //XXX: 실제로는 previous 값을 사용할 수 없도록 락을 걸어야 한다. + $generalID = $rewardItem['generalID']; + $db->update('rank_data', [ + 'value'=>$db->sqleval('value + %i', $amount) + ], 'general_id = %i AND type = %s', $generalID, RankColumn::inherit_point_earned_by_action->value); + $amountText = number_format($amount); $previousPointText = number_format($previousPoint); $nextPointText = number_format($nextPoint); diff --git a/hwe/sammo/Enums/RankColumn.php b/hwe/sammo/Enums/RankColumn.php index b7ec7068..97110d3c 100644 --- a/hwe/sammo/Enums/RankColumn.php +++ b/hwe/sammo/Enums/RankColumn.php @@ -78,14 +78,14 @@ enum RankColumn: string case occupied = 'occupied'; /** 유산 포인트 획득(지연) */ - case inherit_point_earned = 'inherit_point_earned'; + case inherit_point_earned = 'inherit_earned'; /** 유산 포인트 소모(지연) */ - case inherit_point_spent = 'inherit_point_spent'; + case inherit_point_spent = 'inherit_spent'; /** 유산 포인트 획득량(merge 명령) */ - case inherit_point_earned_by_merge = 'inherit_point_earned_dynamic'; + case inherit_point_earned_by_merge = 'inherit_earned_dyn'; /** 유산 포인트 획득량(베팅 등 별도 명령) */ - case inherit_point_earned_by_action = 'inherit_point_earned_by_action'; + case inherit_point_earned_by_action = 'inherit_earned_act'; /** 유산 포인트 소모량(증감 있음) */ - case inherit_point_spent_dynamic = 'inherit_point_spent_dynamic'; + case inherit_point_spent_dynamic = 'inherit_spent_dyn'; } diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 91adbcdb..22021dfe 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -636,6 +636,7 @@ class General implements iAction if ($refundPoint > 0) { $this->increaseInheritancePoint(InheritanceKey::previous, $refundPoint); + $this->increaseRankVar(RankColumn::inherit_point_spent_dynamic, -$refundPoint); } $inheritPointManager = InheritancePointManager::getInstance(); diff --git a/hwe/sammo/InheritancePointManager.php b/hwe/sammo/InheritancePointManager.php index 541327b3..6c36fcdf 100644 --- a/hwe/sammo/InheritancePointManager.php +++ b/hwe/sammo/InheritancePointManager.php @@ -49,6 +49,59 @@ class InheritancePointManager return $value; } + /** + * @param array $generals + * @return Map + */ + public function getInheritancePointFromAll(array $generals, InheritanceKey $key, ?array &$aux = null, bool $forceCalc = false): Map + { + $inheritType = $this->getInheritancePointType($key); + + $storeType = $inheritType->storeType; + $multiplier = $inheritType->pointCoeff; + + $result = new Map(); + + $db = DB::db(); + + $gameStor = KVStorage::getStorage($db, 'game_env'); + if ($storeType === true || ($gameStor->isunited != 0 && !$forceCalc)) { + $ownerMap = []; + foreach ($generals as $general) { + $ownerMap[$general->getVar('owner')] = $general->getID(); + } + + (array_map(fn (General $gen) => $gen->getID(), $generals)); + $ownerMap = Util::convertPairArrayToDict($db->queryAllLists('SELECT `owner`, `no` FROM `general`')); + foreach (KVStorage::getValuesFromInterNamespace($db, "storage", $key) as $namespace => $value) { + if (!str_starts_with($namespace, 'inheritance_')) { + continue; + } + $userID = Util::toInt(substr($namespace, strlen('inheritance_'))); + if (!key_exists($userID, $ownerMap)) { + continue; + } + [$value,] = $value; + + $result[$ownerMap[$userID]] = $value; + } + + return $result; + } + + $auxTmp = []; + foreach ($generals as $general) { + $generalID = $general->getID(); + $auxSub = null; + $value = $this->getInheritancePoint($general, $key, $auxSub, $forceCalc); + $auxTmp[$generalID] = $auxSub; + $result[$generalID] = $value; + } + $aux = $auxTmp; + + return $result; + } + public function getInheritancePoint(General $general, InheritanceKey $key, &$aux = null, bool $forceCalc = false): int|float|null { $inheritType = $this->getInheritancePointType($key);