feat: 유산 포인트 획득, 소모 정도를 동적으로 명장 일람 항목으로 기록

- 1월, 7월
- 베팅, 베팅 당첨을 소모/획득으로 분리
- 일단 유산 포인트 획득은 별도 분리
This commit is contained in:
2022-05-10 03:26:34 +09:00
parent 16906e960e
commit b2e297bbb3
13 changed files with 122 additions and 8 deletions
+3
View File
@@ -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");
}
+37 -3
View File
@@ -1,8 +1,9 @@
<?php
namespace sammo;
use sammo\Enums\InheritanceKey;
use sammo\Enums\RankColumn;
use Ds\Map;
/**
* 시간 단위로 일어나는 이벤트들에 대한 함수 모음
*/
@@ -11,13 +12,46 @@ use sammo\Enums\RankColumn;
function processSumInheritPointRank(){
$db = DB::db();
$db->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
+3
View File
@@ -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 = [
@@ -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;
}
@@ -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;
}
@@ -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;
@@ -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;
}
@@ -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;
}
@@ -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;
}
+8
View File
@@ -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);
+5 -5
View File
@@ -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';
}
+1
View File
@@ -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();
+53
View File
@@ -49,6 +49,59 @@ class InheritancePointManager
return $value;
}
/**
* @param array<General> $generals
* @return Map<int, int|float>
*/
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);