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}");
$ownTrial = $trialStor->getValue("u{$ownerID}");
$itemObj = buildItemClass($itemKey);
$itemName = $itemObj->getName();
if ($ownTrial) {
//두 값이 general, KVStorage 둘다 있고, 이중에선 KVStorage 값을 기준으로 하자 따르자
[,, $amount] = $ownTrial;
$trialStor->deleteValue("u{$ownerID}");
$general->increaseInheritancePoint('previous', $amount);
LogText("선택유니크 롤백포인트:{$ownerID}", $amount);
$userLogger = new UserLogger($ownerID);
$userLogger->push("{$itemName} 입찰에 사용한 {$amount} 포인트 반환", "inheritPoint");
}
$itemObj = buildItemClass($itemKey);
$itemName = $itemObj->getName();
//메시지
$staticNation = $general->getStaticNation();
@@ -1664,8 +1668,8 @@ function rollbackInheritUniqueTrial(General $general, string $itemKey, string $r
[]
);
$msg->send(true);
$general->applyDB($db);
$msg->send(true);
}
function tryRollbackInheritUniqueItem(General $general): void
+10
View File
@@ -1166,13 +1166,23 @@ function resetInheritanceUser(int $userID, bool $isRebirth=false):float{
//이미 리셋되었으므로 리셋 안함
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;
+15 -2
View File
@@ -16,6 +16,7 @@ use sammo\Session;
use sammo\SpecialityHelper;
use sammo\StringUtil;
use sammo\TimeUtil;
use sammo\UserLogger;
use sammo\Util;
use sammo\Validator;
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);
$inheritRequiredPoint = 0;
$userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false);
if ($inheritCity !== null) {
$inheritRequiredPoint += GameConst::$inheritBornCityPoint;
}
@@ -183,6 +186,8 @@ class Join extends \sammo\BaseAPI
}
if ($inheritSpecial) {
$speicalText = getGeneralSpecialWarName($inheritSpecial);
$userLogger->push("{$speicalText} 전투 특기를 가진 천재 생성", "inheritPoint");
$genius = true;
} else {
// 현재 1%
@@ -196,6 +201,8 @@ class Join extends \sammo\BaseAPI
}
if ($inheritCity !== null) {
$cityname = CityConst::byID($inheritCity)->name;
$userLogger->push("{$cityname}에 장수 생성", "inheritPoint");
$city = $inheritCity;
} else {
// 공백지에서만 태어나게
@@ -207,6 +214,7 @@ class Join extends \sammo\BaseAPI
if ($inheritBonusStat) {
[$pleadership, $pstrength, $pintel] = $inheritBonusStat;
$userLogger->push("{$pleadership}, {$pstrength}, {$pintel} 보너스 능력치로 생성", "inheritPoint");
} else {
$pleadership = 0;
$pstrength = 0;
@@ -276,8 +284,10 @@ class Join extends \sammo\BaseAPI
}
if ($inheritTurntime !== null) {
//FIXME: 오동작함
$inheritTurntime = $inheritTurntime % ($admin['turnterm'] * 60);
$userLogger->push(sprintf("턴 시간 %02d:%02d 로 지정", intdiv($inheritTurntime, 60), $inheritTurntime%60), "inheritPoint");
$inheritTurntime += Util::randRangeInt(0, 999999) / 1000000;
$turntime = new \DateTimeImmutable(cutTurn($admin['turntime'], $admin['turnterm']));
$turntime = $turntime->add(TimeUtil::secondsToDateInterval($inheritTurntime));
@@ -372,9 +382,12 @@ class Join extends \sammo\BaseAPI
]);
$cityname = CityConst::byID($city)->name;
if ($inheritRequiredPoint > 0) {
$userLogger->push("장수 생성으로 포인트 {$inheritRequiredPoint} 소모", "inheritPoint");
$inheritStor = KVStorage::getStorage(DB::db(), "inheritance_{$userID}");
$inheritStor->setValue('previous', [$inheritTotalPoint - $inheritRequiredPoint, null]);
$userLogger->flush();
}
$me = [
@@ -10,6 +10,7 @@ use sammo\General;
use sammo\KVStorage;
use sammo\TimeUtil;
use sammo\TriggerInheritBuff;
use sammo\UserLogger;
use sammo\Validator;
class BuyHiddenBuff extends \sammo\BaseAPI
@@ -50,6 +51,7 @@ class BuyHiddenBuff extends \sammo\BaseAPI
if ($userID != $general->getVar('owner')) {
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
}
$userLogger = new UserLogger($userID);
$inheritBuffList = $general->getAuxVar('inheritBuff') ?? [];
$prevLevel = $inheritBuffList[$type] ?? 0;
@@ -70,6 +72,11 @@ class BuyHiddenBuff extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.';
}
$buffTypeText = TriggerInheritBuff::BUFF_KEY_TEXT[$type];
$moreText = $prevLevel > 0 ? "추가":"";
$userLogger->push("{$reqAmount} 포인트로 {$buffTypeText} {$level} 단계 {$moreText}구입", "inheritPoint");
$userLogger->flush();
$inheritBuffList[$type] = $level;
$general->setAuxVar('inheritBuff', $inheritBuffList);
$inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
@@ -9,6 +9,7 @@ use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\TimeUtil;
use sammo\UserLogger;
class BuyRandomUnique extends \sammo\BaseAPI
{
@@ -40,12 +41,17 @@ class BuyRandomUnique extends \sammo\BaseAPI
$db = DB::db();
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
$previousPoint = ($inheritStor->getValue('previous')??[0, 0])[0];
if($previousPoint < GameConst::$inheritItemRandomPoint){
$reqAmount = GameConst::$inheritItemRandomPoint;
if($previousPoint < $reqAmount){
return '충분한 유산 포인트를 가지고 있지 않습니다.';
}
$userLogger = new UserLogger($userID);
$userLogger->push("{$reqAmount} 포인트로 랜덤 유니크 구입", "inheritPoint");
$userLogger->flush();
$general->setAuxVar('inheritRandomUnique', TimeUtil::now());
$inheritStor->setValue('previous', [$previousPoint - GameConst::$inheritItemRandomPoint, null]);
$inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
$general->applyDB($db);
return null;
}
@@ -8,8 +8,11 @@ use sammo\DB;
use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator;
use function sammo\buildItemClass;
class BuySpecificUnique extends \sammo\BaseAPI
{
public function validateArgs(): ?string
@@ -70,6 +73,11 @@ class BuySpecificUnique extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.';
}
$itemObj = buildItemClass($itemKey);
$userLogger = new UserLogger($userID);
$userLogger->push("{$amount} 포인트로 유니크 {$itemObj->getName()} 구입 시도", "inheritPoint");
$userLogger->flush();
$itemTrials[$itemKey] = $amount;
$general->setAuxVar('inheritUniqueTrial', $itemTrials);
$inheritStor->setValue('previous', [$previousPoint - $amount, null]);
@@ -8,6 +8,7 @@ use sammo\DB;
use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator;
class ResetSpecialWar extends \sammo\BaseAPI
@@ -55,6 +56,10 @@ class ResetSpecialWar extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.';
}
$userLogger = new UserLogger($userID);
$userLogger->push("{$reqPoint} 포인트로 전투 특기 초기화", "inheritPoint");
$userLogger->flush();
$oldTypeKey = 'prev_types_special2';
$oldSpecialList = $general->getAuxVar($oldTypeKey) ?? [];
$oldSpecialList[] = $currentSpecialWar;
@@ -10,6 +10,7 @@ use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\TimeUtil;
use sammo\UserLogger;
use sammo\Util;
class ResetTurnTime extends \sammo\BaseAPI
@@ -59,6 +60,15 @@ class ResetTurnTime extends \sammo\BaseAPI
$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));
if ($turnTime <= $serverTurnTimeObj && $serverTurnTimeObj <= $currTurnTime) {
$turnTime = $turnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 60));
@@ -8,8 +8,11 @@ use sammo\DB;
use sammo\GameConst;
use sammo\General;
use sammo\KVStorage;
use sammo\UserLogger;
use sammo\Validator;
use function sammo\buildGeneralSpecialWarClass;
class SetNextSpecialWar extends \sammo\BaseAPI
{
public function validateArgs(): ?string
@@ -67,6 +70,11 @@ class SetNextSpecialWar extends \sammo\BaseAPI
return '충분한 유산 포인트를 가지고 있지 않습니다.';
}
$userLogger = new UserLogger($userID);
$specialWarObj = buildGeneralSpecialWarClass($type);
$userLogger->push("{$reqAmount} 포인트로 다음 전투 특기로 {$specialWarObj->getName()} 지정", "inheritPoint");
$userLogger->flush();
$general->setAuxVar('inheritSpecificSpecialWar', $type);
$inheritStor->setValue('previous', [$previousPoint - $reqAmount, null]);
$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
id="container"
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">
<template v-for="(text, key) in inheritanceViewText" :key="key">
@@ -235,6 +240,20 @@
</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>
</template>
@@ -263,6 +282,14 @@ type InheritanceType =
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>;
const inheritanceViewText: Record<
@@ -442,6 +469,7 @@ export default defineComponent({
availableSpecialWar,
availableUnique,
specificUniqueAmount: inheritActionCost.minSpecificUnique,
lastInheritPointLogs,
};
},
methods: {
@@ -617,11 +645,7 @@ export default defineComponent({
return;
}
//TODO: JosaUtil
if (
!confirm(
`${amount} 포인트로 ${uniqueName}(을)를 입찰하겠습니까?`
)
) {
if (!confirm(`${amount} 포인트로 ${uniqueName}(을)를 입찰하겠습니까?`)) {
return;
}
+9 -6
View File
@@ -17,7 +17,7 @@ $me = General::createGeneralObjFromDB($generalID);
$currentInheritBuff = [];
foreach ($me->getAuxVar('inheritBuff')??[] as $buff => $buffLevel) {
foreach ($me->getAuxVar('inheritBuff') ?? [] as $buff => $buffLevel) {
if (!key_exists($buff, TriggerInheritBuff::BUFF_KEY_TEXT)) {
continue;
}
@@ -43,15 +43,15 @@ foreach (GameConst::$availableSpecialWar as $specialWarKey) {
}
$availableUnique = [];
foreach (GameConst::$allItems as $subItems){
foreach($subItems as $itemKey=>$amount){
if($amount == 0){
foreach (GameConst::$allItems as $subItems) {
foreach ($subItems as $itemKey => $amount) {
if ($amount == 0) {
continue;
}
$itemObj = buildItemClass($itemKey);
$availableUnique[$itemKey] = [
'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;
$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>
<html>
@@ -91,10 +93,11 @@ $resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar') ?? 0;
'resetSpecialWar' => calcResetAttrPoint($resetSpecialWarLevel),
'randomUnique' => GameConst::$inheritItemRandomPoint,
'nextSpecial' => GameConst::$inheritSpecificSpecialPoint,
'minSpecificUnique'=>GameConst::$inheritItemUniqueMinPoint,
'minSpecificUnique' => GameConst::$inheritItemUniqueMinPoint,
],
'availableSpecialWar' => $avilableSpecialWar,
'availableUnique' => $availableUnique,
'lastInheritPointLogs' => $lastInheritPointLogs,
]) ?>
</head>