diff --git a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php index 74468fb1..f3aa517f 100644 --- a/hwe/sammo/API/InheritAction/BuyHiddenBuff.php +++ b/hwe/sammo/API/InheritAction/BuyHiddenBuff.php @@ -65,15 +65,15 @@ class BuyHiddenBuff extends \sammo\BaseAPI $db = DB::db(); $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); - $previousPoint = $inheritStor->getValue('previous') ?? 0; + $previousPoint = ($inheritStor->getValue('previous') ?? [0,0])[0]; if ($previousPoint < $reqAmount) { return '충분한 유산 포인트를 가지고 있지 않습니다.'; } $inheritBuffList[$type] = $level; $general->setAuxVar('inheritBuff', $inheritBuffList); - $inheritStor->setValue('previous', $previousPoint - $reqAmount); - $general->flushUpdateValues(); + $inheritStor->setValue('previous', [$previousPoint - $reqAmount, [$type, $level]]); + $general->applyDB($db); return null; } } diff --git a/hwe/sammo/API/InheritAction/BuyRandomUnique.php b/hwe/sammo/API/InheritAction/BuyRandomUnique.php index dc94af23..4f707346 100644 --- a/hwe/sammo/API/InheritAction/BuyRandomUnique.php +++ b/hwe/sammo/API/InheritAction/BuyRandomUnique.php @@ -46,7 +46,7 @@ class BuyRandomUnique extends \sammo\BaseAPI $general->setAuxVar('inheritRandomUnique', TimeUtil::now()); $inheritStor->setValue('previous', $previousPoint - GameConst::$inheritItemRandomPoint); - $general->flushUpdateValues(); + $general->applyDB($db); return null; } } diff --git a/hwe/sammo/API/InheritAction/BuySpecificUnique.php b/hwe/sammo/API/InheritAction/BuySpecificUnique.php index a5f5b76d..a91d24bb 100644 --- a/hwe/sammo/API/InheritAction/BuySpecificUnique.php +++ b/hwe/sammo/API/InheritAction/BuySpecificUnique.php @@ -74,7 +74,7 @@ class BuySpecificUnique extends \sammo\BaseAPI $general->setAuxVar('inheritUniqueTrial', $itemTrials); $inheritStor->setValue('previous', $previousPoint - $amount); $trialStor->setValue("u{$userID}", [$userID, $generalID, $amount]); - $general->flushUpdateValues(); + $general->applyDB($db); return null; } } diff --git a/hwe/sammo/API/InheritAction/ResetSpecialWar.php b/hwe/sammo/API/InheritAction/ResetSpecialWar.php index 3b2a8869..d2f2ef18 100644 --- a/hwe/sammo/API/InheritAction/ResetSpecialWar.php +++ b/hwe/sammo/API/InheritAction/ResetSpecialWar.php @@ -63,7 +63,7 @@ class ResetSpecialWar extends \sammo\BaseAPI $general->setAuxVar('inheritResetSpecialWar', $nextLevel); $general->setVar('special2', 'None'); $inheritStor->setValue('previous', $previousPoint - $reqPoint); - $general->flushUpdateValues(); + $general->applyDB($db); return null; } } diff --git a/hwe/sammo/API/InheritAction/ResetTurnTime.php b/hwe/sammo/API/InheritAction/ResetTurnTime.php index 2b1226b3..6c813b0d 100644 --- a/hwe/sammo/API/InheritAction/ResetTurnTime.php +++ b/hwe/sammo/API/InheritAction/ResetTurnTime.php @@ -67,7 +67,7 @@ class ResetTurnTime extends \sammo\BaseAPI $general->setVar('turntime', TimeUtil::format($turnTime, true)); $general->setAuxVar('inheritResetTurnTime', $nextLevel); $inheritStor->setValue('previous', $previousPoint - $reqPoint); - $general->flushUpdateValues(); + $general->applyDB($db); return null; } } diff --git a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php index 8f837353..9bd458de 100644 --- a/hwe/sammo/API/InheritAction/SetNextSpecialWar.php +++ b/hwe/sammo/API/InheritAction/SetNextSpecialWar.php @@ -69,7 +69,7 @@ class SetNextSpecialWar extends \sammo\BaseAPI $general->setAuxVar('inheritSpecificSpecialWar', $type); $inheritStor->setValue('previous', $previousPoint - $reqAmount); - $general->flushUpdateValues(); + $general->applyDB($db); return null; } } diff --git a/hwe/ts/inheritPoint.vue b/hwe/ts/inheritPoint.vue index 093bd39b..ea5ff200 100644 --- a/hwe/ts/inheritPoint.vue +++ b/hwe/ts/inheritPoint.vue @@ -3,7 +3,7 @@
+
+
+
유산 포인트 상점
+
+
+
+
+ +
+ +
+
+
+ {{ info.info }}
필요 포인트: + {{ + inheritBuffCost[inheritBuff[buffKey]] - + inheritBuffCost[prevInheritBuff[buffKey] ?? 0] + }}
+
+
+ 리셋구입 +
+
+
+
+
@@ -45,6 +97,8 @@ import "../scss/game_bg.scss"; import TopBackBar from "./components/TopBackBar.vue"; import { sum } from "lodash"; import _ from "lodash"; +import { InvalidResponse } from "./defs"; +import axios from "axios"; type InheritanceType = | "previous" @@ -121,9 +175,73 @@ const inheritanceViewText: Record< }, }; +type inheritBuffType = + | "warAvoidRatio" + | "warCriticalRatio" + | "warMagicTrialProb" + | "domesticSuccessProb" + | "domesticFailProb" + | "warAvoidRatioOppose" + | "warCriticalRatioOppose" + | "warMagicTrialProbOppose"; + +declare const currentInheritBuff: { + [v in inheritBuffType]: number | undefined; +}; + +const inheritBuffHelpText: Record< + inheritBuffType, + { + title: string; + info: string; + } +> = { + warAvoidRatio: { + title: "회피 확률 증가", + info: "전투 시 회피 확률이 1%p ~ 5%p 증가합니다.", + }, + warCriticalRatio: { + title: "필살 확률 증가", + info: "전투 시 필살 확률이 1%p ~ 5%p 증가합니다.", + }, + warMagicTrialProb: { + title: "계략 시도 확률 증가", + info: "전투 시 계략을 시도할 확률이 1%p ~ 5%p 증가합니다. 무장도 계략을 시도합니다.", + }, + warAvoidRatioOppose: { + title: "상대 회피 확률 감소", + info: "전투 시 상대의 회피 확률이 1%p ~ 5%p 감소합니다.", + }, + warCriticalRatioOppose: { + title: "상대 필살 확률 감소", + info: "전투 시 상대의 필살 확률이 1%p ~ 5%p 감소합니다.", + }, + warMagicTrialProbOppose: { + title: "상대 계략 시도 확률 감소", + info: "전투 시 상대의 계략 시도 확률이 1%p ~ 5%p 감소합니다.", + }, + domesticSuccessProb: { + title: "내정 성공 확률 증가", + info: "민심, 인구, 농업, 상업, 치안, 수비, 성벽, 기술 내정의 성공 확률이 1%p ~ 5%p 증가합니다.", + }, + domesticFailProb: { + title: "내정 실패 확률 감소", + info: "민심, 인구, 농업, 상업, 치안, 수비, 성벽, 기술 내정의 실패 확률이 1%p ~ 5%p 감소합니다.", + }, +}; + +declare const maxInheritBuff: number; +declare const inheritBuffCost: number[]; + export default defineComponent({ name: "InheritPoint", data() { + const inheritBuff = {} as Record; + for (const buffKey of Object.keys( + inheritBuffHelpText + ) as inheritBuffType[]) { + inheritBuff[buffKey] = currentInheritBuff[buffKey] ?? 0; + } return { title: "유산 관리", inheritanceViewText, @@ -138,8 +256,70 @@ export default defineComponent({ }; return result; })(), + inheritBuffHelpText, + inheritBuff, + prevInheritBuff: currentInheritBuff, + maxInheritBuff, + inheritBuffCost, }; }, + methods: { + async buyInheritBuff(buffKey: inheritBuffType) { + const level = this.inheritBuff[buffKey]; + const prevLevel = this.prevInheritBuff[buffKey] ?? 0; + if (level == prevLevel) { + return; + } + if (level < prevLevel) { + alert("낮출 수 없습니다."); + return; + } + const cost = + this.inheritBuffCost[level] - this.inheritBuffCost[prevLevel]; + if (this.items.previous < cost) { + alert("유산 포인트가 부족합니다."); + return; + } + + const name = inheritBuffHelpText[buffKey].title; + + if ( + !confirm( + `${name}를 ${level}등급으로 올릴까요? ${cost} 포인트가 소모됩니다.` + ) + ) { + return; + } + + let result: InvalidResponse; + try { + const response = await axios({ + url: "api.php", + method: "post", + responseType: "json", + data: { + path: 'InheritAction/BuyHiddenBuff', + args: { + type: buffKey, + level, + } + }, + }); + result = response.data; + if (!result.result) { + throw result.reason; + } + } catch (e) { + console.error(e); + alert(`실패했습니다: ${e}`); + return; + } + + alert('성공했습니다.'); + //TODO: 페이지 새로고침 필요없이 하도록 + location.reload(); + }, + }, components: { TopBackBar, }, diff --git a/hwe/v_inheritPoint.php b/hwe/v_inheritPoint.php index e2b6800f..27a6da92 100644 --- a/hwe/v_inheritPoint.php +++ b/hwe/v_inheritPoint.php @@ -19,6 +19,14 @@ $items = []; foreach (array_keys(General::INHERITANCE_KEY) as $key) { $items[$key] = $me->getInheritancePoint($key) ?? 0; } + +$currentInheritBuff = []; +foreach ($me->getAuxVar('inheritBuff') as $buff=>$buffLevel){ + if(!key_exists($buff,TriggerInheritBuff::BUFF_KEY_TEXT)){ + continue; + } + $currentInheritBuff[$buff] = $buffLevel; +} ?> @@ -35,7 +43,10 @@ foreach (array_keys(General::INHERITANCE_KEY) as $key) { $items + 'items' => $items, + 'currentInheritBuff' => $currentInheritBuff, + 'maxInheritBuff' => TriggerInheritBuff::MAX_STEP, + 'inheritBuffCost' => GameConst::$inheritBuffPoints, ]) ?> diff --git a/src/sammo/APIHelper.php b/src/sammo/APIHelper.php index c1cb0435..e06d5665 100644 --- a/src/sammo/APIHelper.php +++ b/src/sammo/APIHelper.php @@ -11,6 +11,7 @@ class APIHelper public static function launch(string $rootPath) { + //TODO: path를 php://input에서 받는게 아니라 api.php?~~~~~ 로 받아오는것이 etag 캐시 측면에서 훨씬 나을 듯! try { $rawInput = file_get_contents('php://input'); $input = Json::decode($rawInput);