inheritPoint: 로그 기록

This commit is contained in:
2021-09-17 02:39:11 +09:00
parent 7535f8b34c
commit dd37ea1295
12 changed files with 206 additions and 19 deletions
+7 -3
View File
@@ -1636,16 +1636,20 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r
$trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}");
$ownTrial = $trialStor->getValue("u{$ownerID}"); $ownTrial = $trialStor->getValue("u{$ownerID}");
$itemObj = buildItemClass($itemKey);
$itemName = $itemObj->getName();
if ($ownTrial) { if ($ownTrial) {
//두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자 //두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자
[,, $amount] = $ownTrial; [,, $amount] = $ownTrial;
$trialStor->deleteValue("u{$ownerID}"); $trialStor->deleteValue("u{$ownerID}");
$general->increaseInheritancePoint('previous', $amount); $general->increaseInheritancePoint('previous', $amount);
LogText("선택유니크 롤백포인트:{$ownerID}", $amount); LogText("선택유니크 롤백포인트:{$ownerID}", $amount);
$userLogger = new UserLogger($ownerID);
$userLogger->push("{$itemName} 입찰에 사용한 {$amount} 포인트 반환", "inheritPoint");
} }
$itemObj = buildItemClass($itemKey);
$itemName = $itemObj->getName();
//메시지 //메시지
$staticNation = $general->getStaticNation(); $staticNation = $general->getStaticNation();
@@ -1664,8 +1668,8 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r
[] []
); );
$msg->send(true);
$general->applyDB($db); $general->applyDB($db);
$msg->send(true);
} }
function tryRollbackInheritUniqueItem(General $general): void function tryRollbackInheritUniqueItem(General $general): void
+10
View File
@@ -1166,13 +1166,23 @@ function resetInheritanceUser(int $userID, bool $isRebirth=false):float{
//이미 리셋되었으므로 리셋 안함 //이미 리셋되었으므로 리셋 안함
return $allPoints['previous'][0]; return $allPoints['previous'][0];
} }
$userLogger = new UserLogger($userID);
$previousPoint = ($allPoints['previous']??[0,0])[0];
foreach($allPoints as $key=>[$value,]){ foreach($allPoints as $key=>[$value,]){
if($isRebirth && key_exists($key, $rebirthDegraded)){ if($isRebirth && key_exists($key, $rebirthDegraded)){
$value *= $rebirthDegraded[$key]; $value *= $rebirthDegraded[$key];
} }
$keyText = General::INHERITANCE_KEY[$key][2];
$userLogger->push("{$keyText} 포인트 {$value} 증가", "inheritPoint");
$totalPoint += $value; $totalPoint += $value;
} }
$totalPoint = Util::toInt($totalPoint); $totalPoint = Util::toInt($totalPoint);
$userLogger->push("포인트 {$previousPoint} => {$totalPoint}", "inheritPoint");
$userLogger->flush();
$inheritStor->resetValues(); $inheritStor->resetValues();
$inheritStor->setValue('previous', [$totalPoint, null]); $inheritStor->setValue('previous', [$totalPoint, null]);
return $totalPoint; return $totalPoint;
+15 -2
View File
@@ -16,6 +16,7 @@ use sammo\Session;
use sammo\SpecialityHelper; use sammo\SpecialityHelper;
use sammo\StringUtil; use sammo\StringUtil;
use sammo\TimeUtil; use sammo\TimeUtil;
use sammo\UserLogger;
use sammo\Util; use sammo\Util;
use sammo\Validator; use sammo\Validator;
use sammo\WebUtil; use sammo\WebUtil;
@@ -152,11 +153,13 @@ class Join extends \sammo\BaseAPI
} }
} }
$admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year']); $admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year', 'month']);
$inheritTotalPoint = resetInheritanceUser($userID); $inheritTotalPoint = resetInheritanceUser($userID);
$inheritRequiredPoint = 0; $inheritRequiredPoint = 0;
$userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false);
if ($inheritCity !== null) { if ($inheritCity !== null) {
$inheritRequiredPoint += GameConst::$inheritBornCityPoint; $inheritRequiredPoint += GameConst::$inheritBornCityPoint;
} }
@@ -183,6 +186,8 @@ class Join extends \sammo\BaseAPI
} }
if ($inheritSpecial) { if ($inheritSpecial) {
$speicalText = getGeneralSpecialWarName($inheritSpecial);
$userLogger->push("{$speicalText} 전투 특기를 가진 천재 생성", "inheritPoint");
$genius = true; $genius = true;
} else { } else {
// 현재 1% // 현재 1%
@@ -196,6 +201,8 @@ class Join extends \sammo\BaseAPI
} }
if ($inheritCity !== null) { if ($inheritCity !== null) {
$cityname = CityConst::byID($inheritCity)->name;
$userLogger->push("{$cityname}에 장수 생성", "inheritPoint");
$city = $inheritCity; $city = $inheritCity;
} else { } else {
// 공백지에서만 태어나게 // 공백지에서만 태어나게
@@ -207,6 +214,7 @@ class Join extends \sammo\BaseAPI
if ($inheritBonusStat) { if ($inheritBonusStat) {
[$pleadership, $pstrength, $pintel] = $inheritBonusStat; [$pleadership, $pstrength, $pintel] = $inheritBonusStat;
$userLogger->push("{$pleadership}, {$pstrength}, {$pintel} 보너스 능력치로 생성", "inheritPoint");
} else { } else {
$pleadership = 0; $pleadership = 0;
$pstrength = 0; $pstrength = 0;
@@ -276,8 +284,10 @@ class Join extends \sammo\BaseAPI
} }
if ($inheritTurntime !== null) { if ($inheritTurntime !== null) {
//FIXME: 오동작함
$inheritTurntime = $inheritTurntime % ($admin['turnterm'] * 60); $inheritTurntime = $inheritTurntime % ($admin['turnterm'] * 60);
$userLogger->push(sprintf("턴 시간 %02d:%02d 로 지정", intdiv($inheritTurntime, 60), $inheritTurntime%60), "inheritPoint");
$inheritTurntime += Util::randRangeInt(0, 999999) / 1000000; $inheritTurntime += Util::randRangeInt(0, 999999) / 1000000;
$turntime = new \DateTimeImmutable(cutTurn($admin['turntime'], $admin['turnterm'])); $turntime = new \DateTimeImmutable(cutTurn($admin['turntime'], $admin['turnterm']));
$turntime = $turntime->add(TimeUtil::secondsToDateInterval($inheritTurntime)); $turntime = $turntime->add(TimeUtil::secondsToDateInterval($inheritTurntime));
@@ -372,9 +382,12 @@ class Join extends \sammo\BaseAPI
]); ]);
$cityname = CityConst::byID($city)->name; $cityname = CityConst::byID($city)->name;
if ($inheritRequiredPoint > 0) { if ($inheritRequiredPoint > 0) {
$userLogger->push("장수 생성으로 포인트 {$inheritRequiredPoint} 소모", "inheritPoint");
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}"); $inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}");
$inheritStor->setValue('previous', [$inheritTotalPoint - $inheritRequiredPoint, null]); $inheritStor->setValue('previous', [$inheritTotalPoint - $inheritRequiredPoint, null]);
$userLogger->flush();
} }
$me = [ $me = [
@@ -10,6 +10,7 @@ use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\TimeUtil; use sammo\TimeUtil;
use sammo\TriggerInheritBuff; use sammo\TriggerInheritBuff;
use sammo\UserLogger;
use sammo\Validator; use sammo\Validator;
class BuyHiddenBuff extends \sammo\BaseAPI class BuyHiddenBuff extends \sammo\BaseAPI
@@ -50,6 +51,7 @@ class BuyHiddenBuff extends \sammo\BaseAPI
if ($userID != $general->getVar('owner')) { if ($userID != $general->getVar('owner')) {
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
} }
$userLogger = new UserLogger($userID);
$inheritBuffList = $general->getAuxVar('inheritBuff') ?? []; $inheritBuffList = $general->getAuxVar('inheritBuff') ?? [];
$prevLevel = $inheritBuffList[$type] ?? 0; $prevLevel = $inheritBuffList[$type] ?? 0;
@@ -70,6 +72,11 @@ class BuyHiddenBuff extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
$buffTypeText = TriggerInheritBuff::BUFF_KEY_TEXT[$type];
$moreText = $prevLevel > 0 ? "추가":"";
$userLogger->push("{$reqAmount} 포인트로 {$buffTypeText} {$level} 단계 {$moreText}구입", "inheritPoint");
$userLogger->flush();
$inheritBuffList[$type] = $level; $inheritBuffList[$type] = $level;
$general->setAuxVar('inheritBuff', $inheritBuffList); $general->setAuxVar('inheritBuff', $inheritBuffList);
$inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
@@ -9,6 +9,7 @@ use sammo\GameConst;
use sammo\General; use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\TimeUtil; use sammo\TimeUtil;
use sammo\UserLogger;
class BuyRandomUnique extends \sammo\BaseAPI class BuyRandomUnique extends \sammo\BaseAPI
{ {
@@ -40,12 +41,17 @@ class BuyRandomUnique extends \sammo\BaseAPI
$db = DB::db(); $db = DB::db();
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
$previousPoint = ($inheritStor->getValue('previous')??[0, 0])[0]; $previousPoint = ($inheritStor->getValue('previous')??[0, 0])[0];
if($previousPoint < GameConst::$inheritItemRandomPoint){ $reqAmount = GameConst::$inheritItemRandomPoint;
if($previousPoint < $reqAmount){
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
$userLogger = new UserLogger($userID);
$userLogger->push("{$reqAmount} 포인트로 랜덤 유니크 구입", "inheritPoint");
$userLogger->flush();
$general->setAuxVar('inheritRandomUnique', TimeUtil::now()); $general->setAuxVar('inheritRandomUnique', TimeUtil::now());
$inheritStor->setValue('previous', [$previousPoint - GameConst::$inheritItemRandomPoint, null]); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
$general->applyDB($db); $general->applyDB($db);
return null; return null;
} }
@@ -8,8 +8,11 @@ use sammo\DB;
use sammo\GameConst; use sammo\GameConst;
use sammo\General; use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator; use sammo\Validator;
use function sammo\buildItemClass;
class BuySpecificUnique extends \sammo\BaseAPI class BuySpecificUnique extends \sammo\BaseAPI
{ {
public function validateArgs(): ?string public function validateArgs(): ?string
@@ -70,6 +73,11 @@ class BuySpecificUnique extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
$itemObj = buildItemClass($itemKey);
$userLogger = new UserLogger($userID);
$userLogger->push("{$amount} 포인트로 유니크 {$itemObj->getName()} 구입 시도", "inheritPoint");
$userLogger->flush();
$itemTrials[$itemKey] = $amount; $itemTrials[$itemKey] = $amount;
$general->setAuxVar('inheritUniqueTrial', $itemTrials); $general->setAuxVar('inheritUniqueTrial', $itemTrials);
$inheritStor->setValue('previous', [$previousPoint - $amount, null]); $inheritStor->setValue('previous', [$previousPoint - $amount, null]);
@@ -8,6 +8,7 @@ use sammo\DB;
use sammo\GameConst; use sammo\GameConst;
use sammo\General; use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator; use sammo\Validator;
class ResetSpecialWar extends \sammo\BaseAPI class ResetSpecialWar extends \sammo\BaseAPI
@@ -55,6 +56,10 @@ class ResetSpecialWar extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
$userLogger = new UserLogger($userID);
$userLogger->push("{$reqPoint} 포인트로 전투 특기 초기화", "inheritPoint");
$userLogger->flush();
$oldTypeKey = 'prev_types_special2'; $oldTypeKey = 'prev_types_special2';
$oldSpecialList = $general->getAuxVar($oldTypeKey) ?? []; $oldSpecialList = $general->getAuxVar($oldTypeKey) ?? [];
$oldSpecialList[] = $currentSpecialWar; $oldSpecialList[] = $currentSpecialWar;
@@ -10,6 +10,7 @@ use sammo\GameConst;
use sammo\General; use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\TimeUtil; use sammo\TimeUtil;
use sammo\UserLogger;
use sammo\Util; use sammo\Util;
class ResetTurnTime extends \sammo\BaseAPI class ResetTurnTime extends \sammo\BaseAPI
@@ -59,6 +60,15 @@ class ResetTurnTime extends \sammo\BaseAPI
$afterTurn = Util::randRange($turnTerm * -60 / 2, $turnTerm * 60 / 2); $afterTurn = Util::randRange($turnTerm * -60 / 2, $turnTerm * 60 / 2);
$userLogger = new UserLogger($userID);
if($afterTurn >= 0){
$userLogger->push(sprintf("{$reqPoint} 포인트로 턴 시간을 바꾼 결과 %02d:%02d 뒤로 밀림", intdiv($afterTurn, 60), $afterTurn%60), "inheritPoint");
}
else{
$userLogger->push(sprintf("{$reqPoint} 포인트로 턴 시간을 바꾼 결과 %02d:%02d 앞으로 당김", intdiv(-$afterTurn, 60), (-$afterTurn)%60), "inheritPoint");
}
$userLogger->flush();
$turnTime = $currTurnTime->add(TimeUtil::secondsToDateInterval($afterTurn)); $turnTime = $currTurnTime->add(TimeUtil::secondsToDateInterval($afterTurn));
if ($turnTime <= $serverTurnTimeObj && $serverTurnTimeObj <= $currTurnTime) { if ($turnTime <= $serverTurnTimeObj && $serverTurnTimeObj <= $currTurnTime) {
$turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 60)); $turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 60));
@@ -8,8 +8,11 @@ use sammo\DB;
use sammo\GameConst; use sammo\GameConst;
use sammo\General; use sammo\General;
use sammo\KVStorage; use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator; use sammo\Validator;
use function sammo\buildGeneralSpecialWarClass;
class SetNextSpecialWar extends \sammo\BaseAPI class SetNextSpecialWar extends \sammo\BaseAPI
{ {
public function validateArgs(): ?string public function validateArgs(): ?string
@@ -67,6 +70,11 @@ class SetNextSpecialWar extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
$userLogger = new UserLogger($userID);
$specialWarObj = buildGeneralSpecialWarClass($type);
$userLogger->push("{$reqAmount} 포인트로 다음 전투 특기로 {$specialWarObj->getName()} 지정", "inheritPoint");
$userLogger->flush();
$general->setAuxVar('inheritSpecificSpecialWar', $type); $general->setAuxVar('inheritSpecificSpecialWar', $type);
$inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]); $inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
$general->applyDB($db); $general->applyDB($db);
+89
View File
@@ -0,0 +1,89 @@
<?php
namespace sammo;
class UserLogger
{
protected $userID;
protected $year;
protected $month;
protected $autoFlush;
protected $log = [];
function __construct(int $userID, ?int $year = null, ?int $month = null, bool $autoFlush = true)
{
$this->userID = $userID;
if ($year === null || $month === null) {
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$gameStor->cacheValues(['year', 'month']);
if ($year === null) {
$year = $gameStor->year;
}
if ($month === null) {
$month = $gameStor->month;
}
}
$this->year = $year;
$this->month = $month;
$this->autoFlush = $autoFlush;
}
public function __destruct()
{
if ($this->autoFlush) {
$this->flush();
}
}
public function rollback()
{
$backup = $this->log;
$this->log = [];
return $backup;
}
public function flush()
{
if(!$this->log){
return;
}
if(!$this->userID){
return;
}
$db = DB::db();
$date = TimeUtil::now();
$serverID = UniqueConst::$serverID;
$request = array_map(function ($textAndType) use ($date, $serverID) {
[$text, $type] = $textAndType;
return [
'user_id' => $this->userID,
'server_id' => $serverID,
'log_type' => $type,
'year' => $this->year,
'month' => $this->month,
'date' => $date,
'text' => $text
];
}, array_values($this->log));
$db->insert('user_record', $request);
$this->log = [];
}
public function push($text, string $type)
{
if (!$text) {
return;
}
if (is_array($text)) {
foreach ($text as $textItem) {
$this->log[] = [$textItem, $type];
}
return;
}
$this->log[] = [$text, $type];
}
}
+30 -6
View File
@@ -3,7 +3,12 @@
<div <div
id="container" id="container"
class="bg0 px-2" class="bg0 px-2"
style="max-width: 1000px; margin: auto; border: solid 1px #888888; overflow:hidden;" style="
max-width: 1000px;
margin: auto;
border: solid 1px #888888;
overflow: hidden;
"
> >
<div id="inheritance_list" class="row"> <div id="inheritance_list" class="row">
<template v-for="(text, key) in inheritanceViewText" :key="key"> <template v-for="(text, key) in inheritanceViewText" :key="key">
@@ -235,6 +240,20 @@
</div> </div>
</div> </div>
</div> </div>
<div class="row">
<div class="col">
<div class="bg1 a-center">유산 포인트 변경 내역(최근 30)</div>
</div>
</div>
<div class="row" v-for="(log, idx) in lastInheritPointLogs" :key="idx">
<div class="col a-right" style="max-width:20ch">
<small class="text-muted">[{{log.date}}]</small>
</div>
<div class="col a-left">
{{log.text}}
</div>
</div>
</div> </div>
</template> </template>
@@ -263,6 +282,14 @@ type InheritanceType =
type InheritanceViewType = InheritanceType | "sum" | "new"; type InheritanceViewType = InheritanceType | "sum" | "new";
declare const lastInheritPointLogs: {
server_id: string,
year: number,
month: number,
date: string,
text: string,
}[];
declare const items: Record<InheritanceType, number>; declare const items: Record<InheritanceType, number>;
const inheritanceViewText: Record< const inheritanceViewText: Record<
@@ -442,6 +469,7 @@ export default defineComponent({
availableSpecialWar, availableSpecialWar,
availableUnique, availableUnique,
specificUniqueAmount: inheritActionCost.minSpecificUnique, specificUniqueAmount: inheritActionCost.minSpecificUnique,
lastInheritPointLogs,
}; };
}, },
methods: { methods: {
@@ -617,11 +645,7 @@ export default defineComponent({
return; return;
} }
//TODO: JosaUtil //TODO: JosaUtil
if ( if (!confirm(`${amount} 포인트로 ${uniqueName}(을)를 입찰하겠습니까?`)) {
!confirm(
`${amount} 포인트로 ${uniqueName}(을)를 입찰하겠습니까?`
)
) {
return; return;
} }
+9 -6
View File
@@ -17,7 +17,7 @@ $me = General::createGeneralObjFromDB($generalID);
$currentInheritBuff = []; $currentInheritBuff = [];
foreach ($me->getAuxVar('inheritBuff')??[] as $buff => $buffLevel) { foreach ($me->getAuxVar('inheritBuff') ?? [] as $buff => $buffLevel) {
if (!key_exists($buff, TriggerInheritBuff::BUFF_KEY_TEXT)) { if (!key_exists($buff, TriggerInheritBuff::BUFF_KEY_TEXT)) {
continue; continue;
} }
@@ -43,15 +43,15 @@ foreach (GameConst::$availableSpecialWar as $specialWarKey) {
} }
$availableUnique = []; $availableUnique = [];
foreach (GameConst::$allItems as $subItems){ foreach (GameConst::$allItems as $subItems) {
foreach($subItems as $itemKey=>$amount){ foreach ($subItems as $itemKey => $amount) {
if($amount == 0){ if ($amount == 0) {
continue; continue;
} }
$itemObj = buildItemClass($itemKey); $itemObj = buildItemClass($itemKey);
$availableUnique[$itemKey] = [ $availableUnique[$itemKey] = [
'title' => $itemObj->getName(), 'title' => $itemObj->getName(),
'info'=>$itemObj->getInfo(), 'info' => $itemObj->getInfo(),
]; ];
} }
} }
@@ -64,6 +64,8 @@ foreach (array_keys(General::INHERITANCE_KEY) as $key) {
$resetTurnTimeLevel = $me->getAuxVar('inheritResetTurnTime') ?? 0; $resetTurnTimeLevel = $me->getAuxVar('inheritResetTurnTime') ?? 0;
$resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar') ?? 0; $resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar') ?? 0;
$lastInheritPointLogs = $db->query('SELECT server_id, year, month, date, text FROM user_record WHERE log_type = %s AND user_id = %i ORDER BY id desc LIMIT 30', "inheritPoint", $userID);
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -91,10 +93,11 @@ $resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar') ?? 0;
'resetSpecialWar' => calcResetAttrPoint($resetSpecialWarLevel), 'resetSpecialWar' => calcResetAttrPoint($resetSpecialWarLevel),
'randomUnique' => GameConst::$inheritItemRandomPoint, 'randomUnique' => GameConst::$inheritItemRandomPoint,
'nextSpecial' => GameConst::$inheritSpecificSpecialPoint, 'nextSpecial' => GameConst::$inheritSpecificSpecialPoint,
'minSpecificUnique'=>GameConst::$inheritItemUniqueMinPoint, 'minSpecificUnique' => GameConst::$inheritItemUniqueMinPoint,
], ],
'availableSpecialWar' => $avilableSpecialWar, 'availableSpecialWar' => $avilableSpecialWar,
'availableUnique' => $availableUnique, 'availableUnique' => $availableUnique,
'lastInheritPointLogs' => $lastInheritPointLogs,
]) ?> ]) ?>
</head> </head>