feat: 유산 목록에서 로그를 더 가져올 수 있음

This commit is contained in:
2022-06-25 12:22:25 +09:00
parent da2a6f347a
commit 647c2439e3
5 changed files with 325 additions and 255 deletions
@@ -0,0 +1,40 @@
<?php
namespace sammo\API\InheritAction;
use DateTimeInterface;
use sammo\DB;
use sammo\Session;
use sammo\Validator;
use sammo\Util;
class GetMoreLog extends \sammo\BaseAPI
{
public function validateArgs(): ?string
{
$v = new Validator($this->args);
$v->rule('integer', 'lastID');
if (!$v->validate()) {
return $v->errorStr();
}
$this->args['lastID'] = Util::toInt($this->args['lastID']);
return null;
}
function getRequiredSessionMode(): int
{
return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY;
}
function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
{
$userID = $session->userID;
$lastID = $this->args['lastID'];
$db = DB::db();
$lastInheritPointLogs = $db->query('SELECT id, server_id, year, month, date, text FROM user_record WHERE log_type = %s AND `user_id` = %i AND id < %i ORDER BY id desc LIMIT 30', "inheritPoint", $userID, $lastID);
return [
'result'=> true,
'log' => $lastInheritPointLogs,
];
}
}
+124 -114
View File
@@ -185,10 +185,10 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div class="bg1 a-center">유산 포인트 변경 내역(최근 30)</div> <div class="bg1 a-center">유산 포인트 변경 내역</div>
</div> </div>
</div> </div>
<div v-for="(log, idx) in lastInheritPointLogs" :key="idx" class="row"> <div v-for="[idx, log] of inheritPointLogs" :key="idx" class="row">
<div class="col a-right" style="max-width: 20ch"> <div class="col a-right" style="max-width: 20ch">
<small class="text-muted tnum">[{{ log.date }}]</small> <small class="text-muted tnum">[{{ log.date }}]</small>
</div> </div>
@@ -196,21 +196,11 @@
{{ log.text }} {{ log.text }}
</div> </div>
</div> </div>
<div class="d-grid"><BButton @click="getMoreLog()"> 가져오기</BButton></div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent } from "vue";
import "@scss/common/bootstrap5.scss";
import "@scss/game_bg.scss";
import TopBackBar from "@/components/TopBackBar.vue";
import _ from "lodash";
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
import { SammoAPI } from "./SammoAPI";
import type { inheritBuffType } from "./defs/API/InheritAction";
import * as JosaUtil from '@/util/JosaUtil';
import { BButton } from "bootstrap-vue-3";
type InheritanceType = type InheritanceType =
| "previous" | "previous"
| "lived_month" | "lived_month"
@@ -227,15 +217,53 @@ type InheritanceType =
type InheritanceViewType = InheritanceType | "sum" | "new"; type InheritanceViewType = InheritanceType | "sum" | "new";
declare const lastInheritPointLogs: { declare const staticValues: {
server_id: string; lastInheritPointLogs: InheritPointLogItem[];
year: number; items: Record<InheritanceType, number>;
month: number; currentInheritBuff: {
date: string; [v in inheritBuffType]: number | undefined;
text: string; };
}[]; maxInheritBuff: number;
inheritActionCost: {
buff: number[];
resetTurnTime: number;
resetSpecialWar: number;
randomUnique: number;
nextSpecial: number;
minSpecificUnique: number;
};
resetTurnTimeLevel: number;
resetSpecialWarLevel: number;
declare const items: Record<InheritanceType, number>; availableSpecialWar: Record<
string,
{
title: string;
info: string;
}
>;
availableUnique: Record<
string,
{
title: string;
rawName: string;
info: string;
}
>;
};
</script>
<script lang="ts" setup>
import { reactive, ref } from "vue";
import "@scss/common/bootstrap5.scss";
import "@scss/game_bg.scss";
import TopBackBar from "@/components/TopBackBar.vue";
import _ from "lodash";
import NumberInputWithInfo from "@/components/NumberInputWithInfo.vue";
import { SammoAPI } from "./SammoAPI";
import type { inheritBuffType, InheritPointLogItem } from "./defs/API/InheritAction";
import * as JosaUtil from "@/util/JosaUtil";
import { BButton } from "bootstrap-vue-3";
import { unwrap } from "./util/unwrap";
const inheritanceViewText: Record<InheritanceViewType, { title: string; info: string }> = { const inheritanceViewText: Record<InheritanceViewType, { title: string; info: string }> = {
sum: { sum: {
@@ -296,11 +324,6 @@ const inheritanceViewText: Record<InheritanceViewType, { title: string; info: st
}, },
}; };
declare const currentInheritBuff: {
[v in inheritBuffType]: number | undefined;
};
const inheritBuffHelpText: Record< const inheritBuffHelpText: Record<
inheritBuffType, inheritBuffType,
{ {
@@ -342,81 +365,54 @@ const inheritBuffHelpText: Record<
}, },
}; };
declare const maxInheritBuff: number; const inheritBuff = reactive({} as Record<inheritBuffType, number>);
declare const inheritActionCost: {
buff: number[];
resetTurnTime: number;
resetSpecialWar: number;
randomUnique: number;
nextSpecial: number;
minSpecificUnique: number;
};
declare const resetTurnTimeLevel: number;
declare const resetSpecialWarLevel: number;
declare const availableSpecialWar: Record<
string,
{
title: string;
info: string;
}
>;
declare const availableUnique: Record<
string,
{
title: string;
rawName: string;
info: string;
}
>;
export default defineComponent({
name: "PageInheritPoint",
components: {
TopBackBar,
NumberInputWithInfo,
BButton,
},
data() {
const inheritBuff = {} as Record<inheritBuffType, number>;
for (const buffKey of Object.keys(inheritBuffHelpText) as inheritBuffType[]) { for (const buffKey of Object.keys(inheritBuffHelpText) as inheritBuffType[]) {
inheritBuff[buffKey] = currentInheritBuff[buffKey] ?? 0; inheritBuff[buffKey] = staticValues.currentInheritBuff[buffKey] ?? 0;
} }
return {
title: "유산 관리", const title = "유산 관리";
inheritanceViewText,
items: (() => { const items = ref(
const totalPoint = Math.floor(_.sum(Object.values(items))); (() => {
const previousPoint = Math.floor(items["previous"]); const totalPoint = Math.floor(_.sum(Object.values(staticValues.items)));
const previousPoint = Math.floor(staticValues.items["previous"]);
const newPoint = Math.floor(totalPoint - previousPoint); const newPoint = Math.floor(totalPoint - previousPoint);
const result: Record<InheritanceViewType, number> = { const result: Record<InheritanceViewType, number> = {
...items, ...staticValues.items,
sum: totalPoint, sum: totalPoint,
new: newPoint, new: newPoint,
}; };
return result; return result;
})(), })()
inheritBuffHelpText, );
inheritBuff,
prevInheritBuff: currentInheritBuff, const {
maxInheritBuff, maxInheritBuff,
inheritActionCost, inheritActionCost,
resetTurnTimeLevel, currentInheritBuff: prevInheritBuff,
resetSpecialWarLevel,
nextSpecialWar: Object.keys(availableSpecialWar)[0],
specificUnique: null,
availableSpecialWar, availableSpecialWar,
availableUnique, availableUnique,
specificUniqueAmount: inheritActionCost.minSpecificUnique, } = staticValues;
lastInheritPointLogs,
}; const nextSpecialWar = ref(Object.keys(availableSpecialWar)[0]);
}, const specificUnique = ref<string | null>(null);
methods: { const specificUniqueAmount = ref(inheritActionCost.minSpecificUnique);
async buyInheritBuff(buffKey: inheritBuffType) {
const level = Math.floor(this.inheritBuff[buffKey]); const lastLogID = ref(Math.min(...staticValues.lastInheritPointLogs.map((v) => v.id)));
const prevLevel = this.prevInheritBuff[buffKey] ?? 0; const inheritPointLogs = ref(
(() => {
const logs = new Map<number, InheritPointLogItem>();
for (const log of staticValues.lastInheritPointLogs) {
logs.set(log.id, log);
}
return logs;
})()
);
staticValues.lastInheritPointLogs;
async function buyInheritBuff(buffKey: inheritBuffType) {
const level = Math.floor(unwrap(inheritBuff[buffKey]));
const prevLevel = prevInheritBuff[buffKey] ?? 0;
if (level == prevLevel) { if (level == prevLevel) {
return; return;
} }
@@ -424,14 +420,14 @@ export default defineComponent({
alert("낮출 수 없습니다."); alert("낮출 수 없습니다.");
return; return;
} }
const cost = this.inheritActionCost.buff[level] - this.inheritActionCost.buff[prevLevel]; const cost = inheritActionCost.buff[level] - inheritActionCost.buff[prevLevel];
if (this.items.previous < cost) { if (items.value.previous < cost) {
alert("유산 포인트가 부족합니다."); alert("유산 포인트가 부족합니다.");
return; return;
} }
const name = inheritBuffHelpText[buffKey].title; const name = inheritBuffHelpText[buffKey].title;
const josaUl = JosaUtil.pick(name, '을'); const josaUl = JosaUtil.pick(name, "을");
if (!confirm(`${name}${josaUl} ${level}등급으로 올릴까요? ${cost} 포인트가 소모됩니다.`)) { if (!confirm(`${name}${josaUl} ${level}등급으로 올릴까요? ${cost} 포인트가 소모됩니다.`)) {
return; return;
} }
@@ -450,8 +446,8 @@ export default defineComponent({
alert("성공했습니다."); alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록 //TODO: 페이지 새로고침 필요없이 하도록
location.reload(); location.reload();
}, }
async buySimple(type: "ResetTurnTime" | "BuyRandomUnique" | "ResetSpecialWar") { async function buySimple(type: "ResetTurnTime" | "BuyRandomUnique" | "ResetSpecialWar") {
const costMap: Record<typeof type, number> = { const costMap: Record<typeof type, number> = {
ResetTurnTime: inheritActionCost.resetTurnTime, ResetTurnTime: inheritActionCost.resetTurnTime,
ResetSpecialWar: inheritActionCost.resetSpecialWar, ResetSpecialWar: inheritActionCost.resetSpecialWar,
@@ -469,7 +465,7 @@ export default defineComponent({
ResetSpecialWar: `${cost} 포인트로 전투 특기를 초기화 하시겠습니까?`, ResetSpecialWar: `${cost} 포인트로 전투 특기를 초기화 하시겠습니까?`,
BuyRandomUnique: `${cost} 포인트로 랜덤 유니크를 구입하시겠습니까?`, BuyRandomUnique: `${cost} 포인트로 랜덤 유니크를 구입하시겠습니까?`,
}; };
if (this.items.previous < cost) { if (items.value.previous < cost) {
alert("유산 포인트가 부족합니다."); alert("유산 포인트가 부족합니다.");
return; return;
} }
@@ -488,28 +484,28 @@ export default defineComponent({
alert("성공했습니다."); alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록 //TODO: 페이지 새로고침 필요없이 하도록
location.reload(); location.reload();
}, }
async setNextSpecialWar() { async function setNextSpecialWar() {
const specialWarName = this.availableSpecialWar[this.nextSpecialWar].title ?? undefined; const specialWarName = availableSpecialWar[nextSpecialWar.value].title ?? undefined;
if (specialWarName === undefined) { if (specialWarName === undefined) {
alert(`잘못된 타입: ${this.nextSpecialWar}`); alert(`잘못된 타입: ${nextSpecialWar.value}`);
return; return;
} }
const cost = inheritActionCost.nextSpecial; const cost = inheritActionCost.nextSpecial;
if (this.items.previous < cost) { if (items.value.previous < cost) {
alert("유산 포인트가 부족합니다."); alert("유산 포인트가 부족합니다.");
return; return;
} }
const josaRo = JosaUtil.pick(specialWarName, '로'); const josaRo = JosaUtil.pick(specialWarName, "로");
if (!confirm(`${cost} 포인트로 다음 전특을 ${specialWarName}${josaRo} 고정하겠습니까?`)) { if (!confirm(`${cost} 포인트로 다음 전특을 ${specialWarName}${josaRo} 고정하겠습니까?`)) {
return; return;
} }
try { try {
await SammoAPI.InheritAction.SetNextSpecialWar({ await SammoAPI.InheritAction.SetNextSpecialWar({
type: this.nextSpecialWar, type: nextSpecialWar.value,
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@@ -520,34 +516,34 @@ export default defineComponent({
alert("성공했습니다."); alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록 //TODO: 페이지 새로고침 필요없이 하도록
location.reload(); location.reload();
}, }
async openUniqueItemAuction() { async function openUniqueItemAuction() {
if(this.specificUnique === null){ if (specificUnique.value === null) {
alert("유니크를 선택해주세요."); alert("유니크를 선택해주세요.");
return; return;
} }
const uniqueName = this.availableUnique[this.specificUnique].title ?? undefined; const uniqueName = availableUnique[specificUnique.value].title ?? undefined;
if (uniqueName === undefined) { if (uniqueName === undefined) {
alert(`잘못된 타입: ${this.specificUnique}`); alert(`잘못된 타입: ${specificUnique.value}`);
return; return;
} }
const uniqueRawName = this.availableUnique[this.specificUnique].rawName ?? undefined; const uniqueRawName = availableUnique[specificUnique.value].rawName ?? undefined;
const amount = this.specificUniqueAmount; const amount = specificUniqueAmount.value;
if (this.items.previous < amount) { if (items.value.previous < amount) {
alert("유산 포인트가 부족합니다."); alert("유산 포인트가 부족합니다.");
return; return;
} }
const josaUl = JosaUtil.pick(uniqueRawName, '을'); const josaUl = JosaUtil.pick(uniqueRawName, "을");
if (!confirm(`${amount} 포인트로 ${uniqueName}${josaUl} 입찰하겠습니까?`)) { if (!confirm(`${amount} 포인트로 ${uniqueName}${josaUl} 입찰하겠습니까?`)) {
return; return;
} }
try { try {
await SammoAPI.Auction.OpenUniqueAuction({ await SammoAPI.Auction.OpenUniqueAuction({
itemID: this.specificUnique, itemID: specificUnique.value,
amount, amount,
}); });
} catch (e) { } catch (e) {
@@ -559,9 +555,23 @@ export default defineComponent({
alert("성공했습니다. 경매장을 확인해주세요."); alert("성공했습니다. 경매장을 확인해주세요.");
//TODO: 페이지 새로고침 필요없이 하도록 //TODO: 페이지 새로고침 필요없이 하도록
location.reload(); location.reload();
}, }
},
async function getMoreLog(): Promise<void>{
try{
const result = await SammoAPI.InheritAction.GetMoreLog({
lastID: lastLogID.value
}); });
for(const log of result.log){
inheritPointLogs.value.set(log.id, log);
lastLogID.value = Math.min(lastLogID.value, log.id);
}
}catch(e){
console.error(e);
alert(`실패했습니다: ${e}`);
return;
}
}
</script> </script>
<style> <style>
+4 -1
View File
@@ -17,7 +17,7 @@ import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js";
import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting"; import type { BettingDetailResponse, BettingListResponse } from "./defs/API/Betting";
import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command"; import type { ReserveBulkCommandResponse, ReserveCommandResponse, ReservedCommandResponse } from "./defs/API/Command";
import type { ChiefResponse } from "./defs/API/NationCommand"; import type { ChiefResponse } from "./defs/API/NationCommand";
import type { inheritBuffType } from "./defs/API/InheritAction"; import type { inheritBuffType, InheritLogResponse } from "./defs/API/InheritAction";
import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation"; import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListResponse } from "./defs/API/Nation";
import type { UploadImageResponse } from "./defs/API/Misc"; import type { UploadImageResponse } from "./defs/API/Misc";
import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General"; import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General";
@@ -154,6 +154,9 @@ const apiRealPath = {
SetNextSpecialWar: PUT as APICallT<{ SetNextSpecialWar: PUT as APICallT<{
type: string; type: string;
}>, }>,
GetMoreLog: GET as APICallT<{
lastID: number
}, InheritLogResponse>
}, },
Misc: { Misc: {
UploadImage: POST as APICallT< UploadImage: POST as APICallT<
+15
View File
@@ -1,3 +1,5 @@
import type { ValidResponse } from "@/util/callSammoAPI";
export type inheritBuffType = export type inheritBuffType =
| "warAvoidRatio" | "warAvoidRatio"
| "warCriticalRatio" | "warCriticalRatio"
@@ -7,3 +9,16 @@ export type inheritBuffType =
| "warAvoidRatioOppose" | "warAvoidRatioOppose"
| "warCriticalRatioOppose" | "warCriticalRatioOppose"
| "warMagicTrialProbOppose"; | "warMagicTrialProbOppose";
export type InheritPointLogItem = {
id: number;
server_id: string;
year: number;
month: number;
date: string;
text: string;
};
export type InheritLogResponse = ValidResponse & {
log: InheritPointLogItem[];
};
+3 -1
View File
@@ -68,7 +68,7 @@ foreach (InheritanceKey::cases() as $key) {
$resetTurnTimeLevel = ($me->getAuxVar('inheritResetTurnTime') ?? -1) + 1; $resetTurnTimeLevel = ($me->getAuxVar('inheritResetTurnTime') ?? -1) + 1;
$resetSpecialWarLevel = ($me->getAuxVar('inheritResetSpecialWar') ?? -1) + 1; $resetSpecialWarLevel = ($me->getAuxVar('inheritResetSpecialWar') ?? -1) + 1;
$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); $lastInheritPointLogs = $db->query('SELECT id, 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>
@@ -81,6 +81,7 @@ $lastInheritPointLogs = $db->query('SELECT server_id, year, month, date, text FR
<?= WebUtil::printJS('../d_shared/common_path.js', true) ?> <?= WebUtil::printJS('../d_shared/common_path.js', true) ?>
<?= WebUtil::printDist('vue', 'v_inheritPoint', true) ?> <?= WebUtil::printDist('vue', 'v_inheritPoint', true) ?>
<?= WebUtil::printStaticValues([ <?= WebUtil::printStaticValues([
'staticValues' => [
'items' => $items, 'items' => $items,
'currentInheritBuff' => $currentInheritBuff, 'currentInheritBuff' => $currentInheritBuff,
'maxInheritBuff' => TriggerInheritBuff::MAX_STEP, 'maxInheritBuff' => TriggerInheritBuff::MAX_STEP,
@@ -97,6 +98,7 @@ $lastInheritPointLogs = $db->query('SELECT server_id, year, month, date, text FR
'availableSpecialWar' => $avilableSpecialWar, 'availableSpecialWar' => $avilableSpecialWar,
'availableUnique' => $availableUnique, 'availableUnique' => $availableUnique,
'lastInheritPointLogs' => $lastInheritPointLogs, 'lastInheritPointLogs' => $lastInheritPointLogs,
]
]) ?> ]) ?>
</head> </head>