From dd37ea12951f0d52edd6c15ee68aedaa626dc4bc Mon Sep 17 00:00:00 2001 From: hide_d Date: Fri, 17 Sep 2021 02:39:11 +0900 Subject: [PATCH] =?UTF-8?q?inheritPoint:=20=EB=A1=9C=EA=B7=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 10 ++- hwe/func_gamerule.php | 10 +++ hwe/sammo/API/General/Join.php | 17 +++- hwe/sammo/API/InheritAction/BuyHiddenBuff.php | 7 ++ .../API/InheritAction/BuyRandomUnique.php | 10 ++- .../API/InheritAction/BuySpecificUnique.php | 8 ++ .../API/InheritAction/ResetSpecialWar.php | 5 ++ hwe/sammo/API/InheritAction/ResetTurnTime.php | 10 +++ .../API/InheritAction/SetNextSpecialWar.php | 8 ++ hwe/sammo/UserLogger.php | 89 +++++++++++++++++++ hwe/ts/inheritPoint.vue | 36 ++++++-- hwe/v_inheritPoint.php | 15 ++-- 12 files changed, 206 insertions(+), 19 deletions(-) create mode 100644 hwe/sammo/UserLogger.php diff --git a/hwe/func.php b/hwe/func.php index 3553b651..eb93bb5a 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -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 diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index a4d9b355..c9a817ec 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -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; diff --git a/hwe/sammo/API/General/Join.php b/hwe/sammo/API/General/Join.php index a467c605..f4243490 100644 --- a/hwe/sammo/API/General/Join.php +++ b/hwe/sammo/API/General/Join.php @@ -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 = [ diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php index 964a9010..adc9ece0 100644 --- a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -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]); diff --git a/hwe/sammo/API/InheritAction/BuyRandomUnique.php b/hwe/sammo/API/InheritAction/BuyRandomUnique.php index a0e56e97..209f5dae 100644 --- a/hwe/sammo/API/InheritAction/BuyRandomUnique.php +++ b/hwe/sammo/API/InheritAction/BuyRandomUnique.php @@ -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; } diff --git a/hwe/sammo/API/InheritAction/BuySpecificUnique.php b/hwe/sammo/API/InheritAction/BuySpecificUnique.php index f833b010..21d65be9 100644 --- a/hwe/sammo/API/InheritAction/BuySpecificUnique.php +++ b/hwe/sammo/API/InheritAction/BuySpecificUnique.php @@ -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]); diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php index 4d833694..35297fdf 100644 --- a/hwe/sammo/API/InheritAction/ResetSpecialWar.php +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -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; diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php index 8cb2f692..5dda2595 100644 --- a/hwe/sammo/API/InheritAction/ResetTurnTime.php +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -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)); diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php index f21f36c5..c8bc189b 100644 --- a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -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); diff --git a/hwe/sammo/UserLogger.php b/hwe/sammo/UserLogger.php new file mode 100644 index 00000000..0ce91599 --- /dev/null +++ b/hwe/sammo/UserLogger.php @@ -0,0 +1,89 @@ +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]; + } +} diff --git a/hwe/ts/inheritPoint.vue b/hwe/ts/inheritPoint.vue index 53c50a2c..56585323 100644 --- a/hwe/ts/inheritPoint.vue +++ b/hwe/ts/inheritPoint.vue @@ -3,7 +3,12 @@
@@ -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; 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; } diff --git a/hwe/v_inheritPoint.php b/hwe/v_inheritPoint.php index 3f40e938..533fc939 100644 --- a/hwe/v_inheritPoint.php +++ b/hwe/v_inheritPoint.php @@ -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); ?> @@ -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, ]) ?>