diff --git a/hwe/sammo/API/InheritAction/CalcResetTurnTimeRange.php b/hwe/sammo/API/InheritAction/CalcResetTurnTimeRange.php new file mode 100644 index 00000000..7a11804c --- /dev/null +++ b/hwe/sammo/API/InheritAction/CalcResetTurnTimeRange.php @@ -0,0 +1,68 @@ +userID; + $generalID = $session->generalID; + + $general = General::createObjFromDB($generalID); + if ($userID != $general->getVar('owner')) { + return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; + } + + $db = DB::db(); + + $gameStor = KVStorage::getStorage($db, 'game_env'); + [$turnTerm, $serverTurnTime] = $gameStor->getValuesAsArray(['turnterm', 'turntime']); + + $currTurnTime = new DateTimeImmutable($general->getTurnTime()); + $serverTurnTimeObj = new DateTimeImmutable($serverTurnTime); + + $minTurnTime = $currTurnTime->add(TimeUtil::secondsToDateInterval($turnTerm * -30)); + $maxTurnTime = $currTurnTime->add(TimeUtil::secondsToDateInterval($turnTerm * 30)); + + $timeDiff = $serverTurnTimeObj->diff($minTurnTime); + $timeDiffSec = TimeUtil::DateIntervalToSeconds($timeDiff); + if($timeDiffSec > 0){ + $minTurnTime = $minTurnTime->add(TimeUtil::secondsToDateInterval($timeDiffSec)); + $maxTurnTime = $maxTurnTime->add(TimeUtil::secondsToDateInterval($timeDiffSec)); + } + + return [ + 'result' => true, + 'timeDiffSec' => $timeDiffSec, + 'minTurnTime' => TimeUtil::format($minTurnTime, false), + 'maxTurnTime' => TimeUtil::format($maxTurnTime, false), + ]; + } +} diff --git a/hwe/ts/PageInheritPoint.vue b/hwe/ts/PageInheritPoint.vue index 1090432f..ec51f208 100644 --- a/hwe/ts/PageInheritPoint.vue +++ b/hwe/ts/PageInheritPoint.vue @@ -107,11 +107,11 @@
랜덤 턴 초기화
- 구입 + 구입
다음 턴이 랜덤으로 바뀝니다. (필요 포인트가 피보나치식으로 증가합니다)
다음 턴 시간이 앞, 뒤 랜덤하게 바뀝니다. (필요 포인트가 피보나치식으로 증가합니다)
필요 포인트: {{ inheritActionCost.resetTurnTime }}
@@ -234,6 +234,8 @@ declare const staticValues: { }; resetTurnTimeLevel: number; resetSpecialWarLevel: number; + ternTurm: number; + turnTime: string; availableSpecialWar: Record< string, @@ -263,6 +265,7 @@ import type { inheritBuffType, InheritPointLogItem } from "./defs/API/InheritAct import * as JosaUtil from "@/util/JosaUtil"; import { BButton } from "bootstrap-vue-next"; import { unwrap } from "./util/unwrap"; +import { add as dateAdd } from 'date-fns'; const inheritanceViewText: Record = { sum: { @@ -446,9 +449,42 @@ async function buyInheritBuff(buffKey: inheritBuffType) { //TODO: 페이지 새로고침 필요없이 하도록 location.reload(); } -async function buySimple(type: "ResetTurnTime" | "BuyRandomUnique" | "ResetSpecialWar") { + +async function tryResestTurnTime(){ + const cost = inheritActionCost.resetTurnTime; + + if (items.value.previous < cost) { + alert("유산 포인트가 부족합니다."); + return; + } + + + const { minTurnTime, maxTurnTime } = await SammoAPI.InheritAction.CalcResetTurnTimeRange(); + + //YYYY-MM-DD hh:mm:ss 에서 hh:mm:ss 까지만 보여줄 예정 + const textMinTurnTime = minTurnTime.substring(11, 19); + const textMaxTurnTime = maxTurnTime.substring(11, 19); + + const msg = `${cost} 포인트로 턴을 초기화 하시겠습니까?\n${textMinTurnTime} ~ ${textMaxTurnTime} 사이의 시간으로 초기화 됩니다.`; + if (!confirm(msg)) { + return; + } + + try { + await SammoAPI.InheritAction.ResetTurnTime(); + } catch (e) { + console.error(e); + alert(`실패했습니다: ${e}`); + return; + } + + alert("성공했습니다."); + //TODO: 페이지 새로고침 필요없이 하도록 + location.reload(); +} + +async function buySimple(type: "BuyRandomUnique" | "ResetSpecialWar") { const costMap: Record = { - ResetTurnTime: inheritActionCost.resetTurnTime, ResetSpecialWar: inheritActionCost.resetSpecialWar, BuyRandomUnique: inheritActionCost.randomUnique, }; @@ -459,15 +495,16 @@ async function buySimple(type: "ResetTurnTime" | "BuyRandomUnique" | "ResetSpeci return; } - const messageMap: Record = { - ResetTurnTime: `${cost} 포인트로 턴을 초기화 하시겠습니까?`, - ResetSpecialWar: `${cost} 포인트로 전투 특기를 초기화 하시겠습니까?`, - BuyRandomUnique: `${cost} 포인트로 랜덤 유니크를 구입하시겠습니까?`, - }; if (items.value.previous < cost) { alert("유산 포인트가 부족합니다."); return; } + + const messageMap: Record = { + ResetSpecialWar: `${cost} 포인트로 전투 특기를 초기화 하시겠습니까?`, + BuyRandomUnique: `${cost} 포인트로 랜덤 유니크를 구입하시겠습니까?`, + }; + if (!confirm(messageMap[type])) { return; } diff --git a/hwe/ts/SammoAPI.ts b/hwe/ts/SammoAPI.ts index 626f36d9..834eee35 100644 --- a/hwe/ts/SammoAPI.ts +++ b/hwe/ts/SammoAPI.ts @@ -174,6 +174,11 @@ const apiRealPath = { BuyRandomUnique: PUT as APICallT, ResetSpecialWar: PUT as APICallT, ResetTurnTime: PUT as APICallT, + CalcResetTurnTimeRange: GET as APICallT, SetNextSpecialWar: PUT as APICallT<{ type: string; }>,