feat: 아이템 파기 추가

This commit is contained in:
2022-05-10 23:46:39 +09:00
parent 46a94b7816
commit 443543d70f
4 changed files with 151 additions and 14 deletions
+28 -7
View File
@@ -50,9 +50,18 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=500" />
<title><?= UniqueConst::$serverName ?>: 내정보</title>
<script>
var availableDieImmediately = <?= $availableDieImmediately ? 'true' : 'false' ?>;
</script>
<?= WebUtil::printStaticValues([
'availableDieImmediately' => $availableDieImmediately,
'staticValues' => [
'items' => Util::mapWithKey(fn (string $key, BaseItem $item) => [
'name' => $item->getName(),
'rawName' => $item->getRawName(),
'className' => $item->getRawClassName(),
'cost' => $item->getCost(),
'isBuyable' => $item->isBuyable(),
], $me->getItems())
]
]) ?>
<?= WebUtil::printCSS('../d_shared/common.css') ?>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/orioncactus/pretendard/dist/web/static/pretendard.css" />
<?= WebUtil::printJS('../d_shared/common_path.js') ?>
@@ -72,8 +81,8 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
</div>
<div class="col col-12 col-md-6">
<div class="row">
<div class="col" style='padding-left:4ch;'>
<div class="row mx-0 gx-0">
<div class="col" style='padding-left:2ch;'>
토너먼트 【
<input type=radio class='tnmt' name=tnmt value=0 <?= $me->getVar('tnmt') == 0 ? "checked" : ""; ?>>수동참여
<input type=radio class='tnmt' name=tnmt value=1 <?= $me->getVar('tnmt') == 1 ? "checked" : ""; ?>>자동참여
@@ -94,8 +103,8 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
<option value=0 <?= (!$use_auto_nation_turn) ? "selected" : ""; ?>>허용 안함</option>
</select>】<br>
∞<span style='color:orange'>수뇌가 되었을 때 휴식 턴이어도 적당한 턴을 알아서 넣는 것을 허용합니다.</span><br><br>
<?php else: ?>
<input type="hidden" id='use_auto_nation_turn' name='use_auto_nation_turn' value="1"/>
<?php else : ?>
<input type="hidden" id='use_auto_nation_turn' name='use_auto_nation_turn' value="1" />
<?php endif; ?>
수비 【<select id='defence_train' name='defence_train'>
<?php foreach ([90, 80, 60, 40] as $targetDefenceTrain) : ?>
@@ -138,6 +147,18 @@ $use_auto_nation_turn = $me->getAuxVar('use_auto_nation_turn') ?? 1;
</div>
</div>
</div>
<div class="row">
<div class="col">아이템 파기</div>
</div>
<div class="row mx-1">
<div class="btn-group" role="group">
<?php foreach ($me->getItems() as $itemKey => $item) : ?>
<button type="button" data-item-type='<?=$itemKey?>' class="drop-item-btn btn btn-primary <?= $item->getName() == '-' ? 'disabled' : '' ?>"><?= $item->getName() ?></button>
<?php endforeach; ?>
</div>
</div>
<br>
개인용 CSS<br>
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace sammo\API\General;
use sammo\DB;
use sammo\Validator;
use sammo\Session;
use sammo\GameConst;
use sammo\General;
use sammo\JosaUtil;
class DropItem extends \sammo\BaseAPI
{
public function validateArgs(): ?string
{
$v = new Validator($this->args);
$v->rule('required', [
'itemType',
])
->rule('in', 'itemType', array_keys(GameConst::$allItems));
if (!$v->validate()) {
return "{$v->errorStr()}";
}
return null;
}
public function getRequiredSessionMode(): int
{
return static::REQ_GAME_LOGIN;
}
public function launch(Session $session, ?\DateTimeInterface $modifiedSince, ?string $reqEtag)
{
$generalID = $session->generalID;
$me = General::createGeneralObjFromDB($generalID);
$itemType = $this->args['itemType'];
$item = $me->getItem($itemType);
if ($item->getRawClassName() === 'None') {
return '아이템을 가지고 있지 않습니다.';
}
$me->setItem($itemType, 'None');
$logger = $me->getLogger();
$generalName = $me->getName();
$josaYi = JosaUtil::pick($generalName, '이');
$itemName = $item->getName();
$josaUl = JosaUtil::pick($itemName, '을');
$logger->pushGeneralActionLog("<C>{$itemName}</>{$josaUl} 버렸습니다.");
$nationName = $me->getStaticNation()['name'];
if (!$item->isBuyable()) {
$logger->pushGlobalActionLog("<Y>{$generalName}</>{$josaYi} <C>{$itemName}</>{$josaUl} 잃었습니다!");
$logger->pushGlobalHistoryLog("<R><b>【망실】</b></><D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} <C>{$itemName}</>{$josaUl} 잃었습니다!");
}
$me->applyDB(DB::db());
return null;
}
}
+5 -2
View File
@@ -13,7 +13,7 @@ import type { SetBlockWarResponse, GeneralListResponse as NationGeneralListRespo
import type { UploadImageResponse } from "./defs/API/Misc";
import type { GeneralLogType, GetGeneralLogResponse, JoinArgs } from "./defs/API/General";
import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse } from "./defs/API/Global";
import type { CachedMapResult, GeneralListResponse, MapResult } from "./defs";
import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs";
const apiRealPath = {
Betting: {
@@ -53,7 +53,10 @@ const apiRealPath = {
GetGeneralLog: GET as APICallT<{
reqType: GeneralLogType,
reqTo?: number
}, GetGeneralLogResponse>
}, GetGeneralLogResponse>,
DropItem: PUT as APICallT<{
itemType: ItemTypeKey
}>
},
Global: {
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
+52 -5
View File
@@ -2,7 +2,7 @@ import "@scss/myPage.scss";
import axios from 'axios';
import $ from 'jquery';
import { type InvalidResponse, keyScreenMode, type ScreenModeType } from '@/defs';
import { type InvalidResponse, keyScreenMode, type ScreenModeType, type ItemTypeKey } from '@/defs';
import { convertFormData } from '@util/convertFormData';
import { setAxiosXMLHttpRequest } from '@util/setAxiosXMLHttpRequest';
import { unwrap } from '@util/unwrap';
@@ -10,13 +10,24 @@ import { unwrap_any } from '@util/unwrap_any';
import { auto500px } from './util/auto500px';
import { initTooltip } from "./legacy/initTooltip";
import { insertCustomCSS } from "./util/customCSS";
import * as JosaUtil from '@util/JosaUtil';
import { SammoAPI } from "./SammoAPI";
type LogResponse = {
result: true;
log: Record<string, string>;
};
declare const staticValues: {
items: Record<ItemTypeKey, {
name: string;
rawName: string;
className: string;
cost: number;
isBuyable: boolean;
}>
}
$(function ($) {
setAxiosXMLHttpRequest();
@@ -111,8 +122,8 @@ $(function ($) {
const $screenModeRadios = $('input:radio[name=screenMode]');
$screenModeRadios.prop('checked', false).filter(`[value="${localStorage.getItem(keyScreenMode)??'auto'}"]`).prop('checked', true);
$screenModeRadios.on('click', function(e){
$screenModeRadios.prop('checked', false).filter(`[value="${localStorage.getItem(keyScreenMode) ?? 'auto'}"]`).prop('checked', true);
$screenModeRadios.on('click', function (e) {
const mode = (e.target as HTMLInputElement).value as ScreenModeType;
localStorage.setItem(keyScreenMode, mode);
document.dispatchEvent(new CustomEvent('tryChangeScreenMode'));
@@ -201,7 +212,7 @@ $(function ($) {
})
});
result = response.data;
if(!result.result){
if (!result.result) {
throw result.reason;
}
}
@@ -216,6 +227,42 @@ $(function ($) {
});
$('.drop-item-btn').on('click', async function (e) {
e.preventDefault();
const $this = $(this);
const type = $this.data('item-type') as ItemTypeKey | undefined;
if (!type) {
return;
}
console.log(`${type} 판매 시도`);
const item = staticValues.items[type];
console.log(item);
const josaUl = JosaUtil.pick(item.rawName, '을');
if (!confirm(`${item.name}${josaUl} 버리시겠습니까? (판매시 가치: ${item.cost})`)) {
return;
}
if(!item.isBuyable && !confirm(`이 아이템은 유니크 아이템입니다. 진짜로 ${item.name}${josaUl} 버리시겠습니까?`)){
return;
}
try{
await SammoAPI.General.DropItem({
itemType: type,
});
alert(`${item.name}${josaUl} 버렸습니다.`);
location.reload();
}
catch(e){
console.error(e);
alert(e);
}
});
initTooltip();
insertCustomCSS();
});