inheritAction: UI 1차 완성

This commit is contained in:
2021-09-15 19:06:15 +00:00
committed by Gitea
parent 51d4c4cdc9
commit 603f93025f
5 changed files with 308 additions and 89 deletions
@@ -14,9 +14,9 @@ class BuySpecificUnique extends \sammo\BaseAPI
{ {
public function validateArgs(): ?string public function validateArgs(): ?string
{ {
foreach(GameConst::$allItems as $items){ foreach (GameConst::$allItems as $items) {
foreach($items as $itemKey=>$amount){ foreach ($items as $itemKey => $amount) {
if($amount == 0){ if ($amount == 0) {
continue; continue;
} }
$availableItems[$itemKey] = $amount; $availableItems[$itemKey] = $amount;
@@ -29,7 +29,7 @@ class BuySpecificUnique extends \sammo\BaseAPI
'amount', 'amount',
]) ])
->rule('integer', 'amount') ->rule('integer', 'amount')
->rule('min', GameConst::$inheritItemUniqueMinPoint) ->rule('min', 'amount', GameConst::$inheritItemUniqueMinPoint)
->rule('keyExists', 'item', $availableItems); ->rule('keyExists', 'item', $availableItems);
if (!$v->validate()) { if (!$v->validate()) {
@@ -53,20 +53,20 @@ class BuySpecificUnique extends \sammo\BaseAPI
$generalID = $session->generalID; $generalID = $session->generalID;
$general = General::createGeneralObjFromDB($generalID); $general = General::createGeneralObjFromDB($generalID);
if($userID != $general->getVar('owner')){ if ($userID != $general->getVar('owner')) {
return '로그인 상태가 이상합니다. 다시 로그인해 주세요.'; return '로그인 상태가 이상합니다. 다시 로그인해 주세요.';
} }
$itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? []; $itemTrials = $general->getAuxVar('inheritUniqueTrial') ?? [];
if(key_exists($itemKey, $itemTrials)){ if (key_exists($itemKey, $itemTrials)) {
return '이미 입찰한 아이템입니다. 다음 턴에 시도해 주세요.'; return '이미 입찰한 아이템입니다. 다음 턴에 시도해 주세요.';
} }
$db = DB::db(); $db = DB::db();
$inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}"); $inheritStor = KVStorage::getStorage($db, "inheritance_{$userID}");
$trialStor = KVStorage::getStorage($db, "ut_{$itemKey}"); $trialStor = KVStorage::getStorage($db, "ut_{$itemKey}");
$previousPoint = $inheritStor->getValue('previous')??0; $previousPoint = ($inheritStor->getValue('previous') ?? [0, 0])[0];
if($previousPoint < $amount){ if ($previousPoint < $amount) {
return '충분한 유산 포인트를 가지고 있지 않습니다.'; return '충분한 유산 포인트를 가지고 있지 않습니다.';
} }
-23
View File
@@ -1,23 +0,0 @@
#inheritance_list{
display: flex;
flex-wrap: wrap;
}
.inherit_padding{
width: 33%;
padding: 10px 2px;
}
.inherit_item{
width: 33%;
padding: 10px 2px;
}
.col-form-label{
text-align:right;
padding-right:2ch;
}
.inherit_value{
text-align: right;
}
-1
View File
@@ -61,7 +61,6 @@
<script lang="ts"> <script lang="ts">
import "../scss/bootstrap5.scss"; import "../scss/bootstrap5.scss";
import "../scss/inheritPoint.scss";
import "../scss/game_bg.scss"; import "../scss/game_bg.scss";
import "../../css/config.css"; import "../../css/config.css";
+265 -50
View File
@@ -5,16 +5,19 @@
class="tb_layout bg0" class="tb_layout bg0"
style="max-width: 1000px; margin: auto; border: solid 1px #888888" style="max-width: 1000px; margin: auto; border: solid 1px #888888"
> >
<div id="inheritance_list"> <div id="inheritance_list" class="row">
<template v-for="(text, key) in inheritanceViewText" :key="key"> <template v-for="(text, key) in inheritanceViewText" :key="key">
<div :id="`inherit_${key}`" class="inherit_item inherit_template_item"> <div
:id="`inherit_${key}`"
class="col col-sm-4 col-12 inherit_item inherit_template_item"
>
<div class="row"> <div class="row">
<label <label
:id="`inherit_${key}_head`" :id="`inherit_${key}_head`"
class="inherit_head col-sm-6 col-form-label" class="inherit_head col col-md-6 col-sm-12 col-6 col-form-label"
>{{ text.title }}</label >{{ text.title }}</label
> >
<div class="col-sm-6"> <div class="col col-md-6 col-sm-12 col-6">
<input <input
type="text" type="text"
class="form-control inherit_value" class="form-control inherit_value"
@@ -38,56 +41,94 @@
<div class="row"> <div class="row">
<div class="col"><div class="bg1 a-center">유산 포인트 상점</div></div> <div class="col"><div class="bg1 a-center">유산 포인트 상점</div></div>
</div> </div>
<div class="row"> <div class="row">
<div <div class="col offset-md-4 col-md-4 col-sm-6 col-12 py-2">
class="col col-md-4 col-6" <div class="row px-4">
v-for="(info, buffKey) in inheritBuffHelpText" <div class="a-right col-6 align-self-center">
:key="buffKey" 다음 전투 특기 선택
> </div>
<div class="row"> <div class="col-6">
<label <select class="form-select col-6" v-model="nextSpecialWar">
class="col col-sm-6 col-form-label" <option
:for="`buff-${buffKey}`" v-for="(info, key) in availableSpecialWar"
>{{ info.title }}</label :key="key"
> :value="key"
<div class="col col-sm-6"> >
<b-form-input {{ info.title }}
:id="`buff-${buffKey}`" </option>
type="number" </select>
v-model="inheritBuff[buffKey]"
:min="prevInheritBuff[buffKey] ?? 0"
:max="maxInheritBuff"
></b-form-input>
</div> </div>
</div> </div>
<div style="text-align: right"> <div class="a-right">
<small class="form-text text-muted" <small class="form-text text-muted"
>{{ info.info }}<br /><span style="color: white" ><span
>필요 포인트: style="color: white"
{{ v-html="availableSpecialWar[nextSpecialWar].info"
inheritActionCost.buff[inheritBuff[buffKey]] - /><br />다음에 얻을 전투 특기를 정합니다.<br /><span
inheritActionCost.buff[prevInheritBuff[buffKey] ?? 0] style="color: white"
}}</span >필요 포인트: {{ inheritActionCost.nextSpecial }}</span
></small ></small
> >
</div> </div>
<div class="row px-4" style="margin-bottom: 1em"> <div class="row px-4">
<b-button <b-button
variant="secondary" class="col-6 offset-6"
@click="inheritBuff[buffKey] = prevInheritBuff[buffKey] ?? 0"
class="col col-md-6 col-4 offset-md-0 offset-4"
>리셋</b-button
><b-button
variant="primary" variant="primary"
class="col col-md-6 col-4" @click="setNextSpecialWar"
@click="buyInheritBuff(buffKey)" >구입</b-button
>
</div>
</div>
<div class="col col-md-4 col-sm-6 col-12 py-2">
<div class="row px-4">
<div class="a-right col-6 align-self-center">유니크 입찰</div>
<div class="col-6">
<select class="form-select col-6" v-model="specificUnique">
<option
v-for="(info, key) in availableUnique"
:key="key"
:value="key"
>
{{ info.title }}
</option>
</select>
</div>
</div>
<div class="row px-4">
<div class="col">
<NumberInputWithInfo
title="입찰 포인트"
:min="inheritActionCost.minSpecificUnique"
:max="this.items.previous"
v-model="specificUniqueAmount"
/>
</div>
</div>
<div class="a-right">
<small class="form-text text-muted"
>얻고자 하는 유니크 아이템을 포인트를 걸어 입찰합니다. 최고
포인트인 경우 다음 턴에 유니크를 얻습니다.<br /><span
style="color: white"
v-html="availableUnique[specificUnique].info"
/></small>
</div>
<div class="row px-4">
<b-button
class="col-6 offset-6"
variant="primary"
@click="buySpecificUnique"
>구입</b-button >구입</b-button
> >
</div> </div>
</div> </div>
</div> </div>
<div class="row py-2" style="margin-top: 2em"> <div style="width: 100%; padding: 0 10px">
<div class="col col-md-4 col-sm-6"> <hr :style="{ opacity: 0.5 }" />
</div>
<div class="row py-sm-2">
<div class="col col-md-4 col-sm-6 col-12 py-2">
<div class="row px-4"> <div class="row px-4">
<div class="a-right col-6 align-self-center">랜덤 초기화</div> <div class="a-right col-6 align-self-center">랜덤 초기화</div>
<b-button <b-button
@@ -105,7 +146,7 @@
> >
</div> </div>
</div> </div>
<div class="col col-md-4 col-sm-6"> <div class="col col-md-4 col-sm-6 col-12 py-2">
<div class="row px-4"> <div class="row px-4">
<div class="a-right col-6 align-self-center">랜덤 유니크 획득</div> <div class="a-right col-6 align-self-center">랜덤 유니크 획득</div>
<b-button <b-button
@@ -123,7 +164,7 @@
> >
</div> </div>
</div> </div>
<div class="col col-md-4 col-sm-6"> <div class="col col-md-4 col-sm-6 col-12 py-2">
<div class="row px-4"> <div class="row px-4">
<div class="a-right col-6 align-self-center"> <div class="a-right col-6 align-self-center">
즉시 전투 특기 초기화 즉시 전투 특기 초기화
@@ -144,25 +185,68 @@
</div> </div>
</div> </div>
</div> </div>
<!-- ResetTurnTime --> </div>
<!-- BuyRandomUnique --> <div style="width: 100%; padding: 0 10px">
<!-- ResetSpecialWar --> <hr :style="{ opacity: 0.5 }" />
<!-- SetNextSpecialWar, type --> </div>
<!-- BuySpecificUnique, item, amount --> <div class="row">
<div
class="col col-md-4 col-sm-6 col-12"
v-for="(info, buffKey) in inheritBuffHelpText"
:key="buffKey"
>
<div class="row">
<label class="col col-sm-6 col-form-label" :for="`buff-${buffKey}`">{{
info.title
}}</label>
<div class="col col-sm-6">
<b-form-input
:id="`buff-${buffKey}`"
type="number"
v-model="inheritBuff[buffKey]"
:min="prevInheritBuff[buffKey] ?? 0"
:max="maxInheritBuff"
></b-form-input>
</div>
</div>
<div style="text-align: right">
<small class="form-text text-muted"
>{{ info.info }}<br /><span style="color: white"
>필요 포인트:
{{
inheritActionCost.buff[inheritBuff[buffKey]] -
inheritActionCost.buff[prevInheritBuff[buffKey] ?? 0]
}}</span
></small
>
</div>
<div class="row px-4" style="margin-bottom: 1em">
<b-button
variant="secondary"
@click="inheritBuff[buffKey] = prevInheritBuff[buffKey] ?? 0"
class="col col-md-6 col-4 offset-md-0 offset-4"
>리셋</b-button
><b-button
variant="primary"
class="col col-md-6 col-4"
@click="buyInheritBuff(buffKey)"
>구입</b-button
>
</div>
</div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType } from "vue"; import { defineComponent } from "vue";
import "../scss/bootstrap5.scss"; import "../scss/bootstrap5.scss";
import "../scss/inheritPoint.scss";
import "../scss/game_bg.scss"; import "../scss/game_bg.scss";
import TopBackBar from "./components/TopBackBar.vue"; import TopBackBar from "./components/TopBackBar.vue";
import { sum } from "lodash";
import _ from "lodash"; import _ from "lodash";
import { InvalidResponse } from "./defs"; import { InvalidResponse } from "./defs";
import axios from "axios"; import axios from "axios";
import NumberInputWithInfo from "./components/NumberInputWithInfo.vue";
type InheritanceType = type InheritanceType =
| "previous" | "previous"
@@ -300,11 +384,29 @@ declare const inheritActionCost: {
resetTurnTime: number; resetTurnTime: number;
resetSpecialWar: number; resetSpecialWar: number;
randomUnique: number; randomUnique: number;
nextSpecial: number;
minSpecificUnique: number;
}; };
declare const resetTurnTimeLevel: number; declare const resetTurnTimeLevel: number;
declare const resetSpecialWarLevel: number; declare const resetSpecialWarLevel: number;
declare const availableSpecialWar: Record<
string,
{
title: string;
info: string;
}
>;
declare const availableUnique: Record<
string,
{
title: string;
info: string;
}
>;
export default defineComponent({ export default defineComponent({
name: "InheritPoint", name: "InheritPoint",
data() { data() {
@@ -335,6 +437,11 @@ export default defineComponent({
inheritActionCost, inheritActionCost,
resetTurnTimeLevel, resetTurnTimeLevel,
resetSpecialWarLevel, resetSpecialWarLevel,
nextSpecialWar: Object.keys(availableSpecialWar)[0],
specificUnique: Object.keys(availableUnique)[0],
availableSpecialWar,
availableUnique,
specificUniqueAmount: inheritActionCost.minSpecificUnique,
}; };
}, },
methods: { methods: {
@@ -443,6 +550,105 @@ export default defineComponent({
return; return;
} }
alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록
location.reload();
},
async setNextSpecialWar() {
const specialWarName =
this.availableSpecialWar[this.nextSpecialWar].title ?? undefined;
if (specialWarName === undefined) {
alert(`잘못된 타입: ${this.nextSpecialWar}`);
return;
}
const cost = inheritActionCost.nextSpecial;
if (this.items.previous < cost) {
alert("유산 포인트가 부족합니다.");
return;
}
//TODO: JosaUtil
if (
!confirm(
`${cost} 포인트로 다음 전특을 ${specialWarName}(으)로 고정하겠습니까?`
)
) {
return;
}
let result: InvalidResponse;
try {
const response = await axios({
url: "api.php",
method: "post",
responseType: "json",
data: {
path: `InheritAction/SetNextSpecialWar`,
args: {
type: this.nextSpecialWar,
},
},
});
result = response.data;
if (!result.result) {
throw result.reason;
}
} catch (e) {
console.error(e);
alert(`실패했습니다: ${e}`);
return;
}
alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록
location.reload();
},
async buySpecificUnique() {
const uniqueName =
this.availableUnique[this.specificUnique].title ?? undefined;
if (uniqueName === undefined) {
alert(`잘못된 타입: ${this.specificUnique}`);
return;
}
const amount = this.specificUniqueAmount;
if (this.items.previous < amount) {
alert("유산 포인트가 부족합니다.");
return;
}
//TODO: JosaUtil
if (
!confirm(
`${amount} 포인트로 ${uniqueName}(을)를 입찰하겠습니까?`
)
) {
return;
}
let result: InvalidResponse;
try {
const response = await axios({
url: "api.php",
method: "post",
responseType: "json",
data: {
path: `InheritAction/BuySpecificUnique`,
args: {
item: this.specificUnique,
amount,
},
},
});
result = response.data;
if (!result.result) {
throw result.reason;
}
} catch (e) {
console.error(e);
alert(`실패했습니다: ${e}`);
return;
}
alert("성공했습니다."); alert("성공했습니다.");
//TODO: 페이지 새로고침 필요없이 하도록 //TODO: 페이지 새로고침 필요없이 하도록
location.reload(); location.reload();
@@ -450,10 +656,19 @@ export default defineComponent({
}, },
components: { components: {
TopBackBar, TopBackBar,
NumberInputWithInfo,
}, },
}); });
</script> </script>
<style> <style>
.col-form-label {
text-align: right;
padding-right: 2ch;
}
.inherit_value {
text-align: right;
}
</style> </style>
+35 -7
View File
@@ -15,10 +15,6 @@ $gameStor = KVStorage::getStorage($db, 'game_env');
$me = General::createGeneralObjFromDB($generalID); $me = General::createGeneralObjFromDB($generalID);
$items = [];
foreach (array_keys(General::INHERITANCE_KEY) as $key) {
$items[$key] = $me->getInheritancePoint($key) ?? 0;
}
$currentInheritBuff = []; $currentInheritBuff = [];
foreach ($me->getAuxVar('inheritBuff') as $buff => $buffLevel) { foreach ($me->getAuxVar('inheritBuff') as $buff => $buffLevel) {
@@ -37,9 +33,37 @@ function calcResetAttrPoint($level)
return GameConst::$inheritResetAttrPointBase[$level]; return GameConst::$inheritResetAttrPointBase[$level];
} }
$avilableSpecialWar = [];
foreach (GameConst::$availableSpecialWar as $specialWarKey) {
$specialWarObj = buildGeneralSpecialWarClass($specialWarKey);
$avilableSpecialWar[$specialWarKey] = [
'title' => $specialWarObj->getName(),
'info' => $specialWarObj->getInfo(),
];
}
$resetTurnTimeLevel = $me->getAuxVar('inheritResetTurnTime')??0; $availableUnique = [];
$resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar')??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(),
];
}
}
$items = [];
foreach (array_keys(General::INHERITANCE_KEY) as $key) {
$items[$key] = $me->getInheritancePoint($key) ?? 0;
}
$resetTurnTimeLevel = $me->getAuxVar('inheritResetTurnTime') ?? 0;
$resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar') ?? 0;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@@ -48,7 +72,7 @@ $resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar')??0;
<title><?= UniqueConst::$serverName ?>: 유산 관리</title> <title><?= UniqueConst::$serverName ?>: 유산 관리</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=1024" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<?= WebUtil::printCSS('dist_css/common_vue.css') ?> <?= WebUtil::printCSS('dist_css/common_vue.css') ?>
<?= WebUtil::printCSS('dist_css/v_inheritPoint.css') ?> <?= WebUtil::printCSS('dist_css/v_inheritPoint.css') ?>
<?= WebUtil::printJS('../d_shared/common_path.js', true) ?> <?= WebUtil::printJS('../d_shared/common_path.js', true) ?>
@@ -66,7 +90,11 @@ $resetSpecialWarLevel = $me->getAuxVar('inheritResetSpecialWar')??0;
'resetTurnTime' => calcResetAttrPoint($resetTurnTimeLevel), 'resetTurnTime' => calcResetAttrPoint($resetTurnTimeLevel),
'resetSpecialWar' => calcResetAttrPoint($resetSpecialWarLevel), 'resetSpecialWar' => calcResetAttrPoint($resetSpecialWarLevel),
'randomUnique' => GameConst::$inheritItemRandomPoint, 'randomUnique' => GameConst::$inheritItemRandomPoint,
'nextSpecial' => GameConst::$inheritSpecificSpecialPoint,
'minSpecificUnique'=>GameConst::$inheritItemUniqueMinPoint,
], ],
'availableSpecialWar' => $avilableSpecialWar,
'availableUnique' => $availableUnique,
]) ?> ]) ?>
</head> </head>