diff --git a/.phan/config.php b/.phan/config.php index 513c421a..b6a5feea 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -101,13 +101,11 @@ return [ 'hwe/j_export_simulator_object.php', 'hwe/j_general_log_old.php', 'hwe/j_general_set_permission.php', - 'hwe/j_general_turn.php', 'hwe/j_get_basic_general_list.php', 'hwe/j_getChiefTurn.php', 'hwe/j_get_city_list.php', 'hwe/j_get_general_list.php', 'hwe/j_get_nation_general_list.php', - 'hwe/j_get_reserved_command.php', 'hwe/j_get_select_npc_token.php', 'hwe/j_get_select_pool.php', 'hwe/j_image_upload.php', diff --git a/hwe/func.php b/hwe/func.php index d60d2654..c734626e 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -479,6 +479,7 @@ function getCommandTable(General $general){ 'compansation'=>$commandObj->getCompensationStyle(), 'possible'=>$commandObj->hasMinConditionMet(), 'title'=>$commandObj->getCommandDetailTitle(), + 'reqArg'=>$commandObj::$reqArg, ]; } diff --git a/hwe/func_command.php b/hwe/func_command.php index a42e78f3..22936254 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -63,7 +63,7 @@ function pullGeneralCommand(int $generalID, int $turnCnt=1){ if($turnCnt >= GameConst::$maxTurn){ return; } - + $db = DB::db(); $db->update('general_turn', [ @@ -96,7 +96,7 @@ function repeatGeneralCommand(int $generalId, int $turnCnt){ foreach($turnList as $turnItem){ $turnIdx = $turnItem['turn_idx']; $turnTarget = iterator_to_array(Util::range($turnIdx+$turnCnt, GameConst::$maxTurn, $turnCnt)); - + $db->update('general_turn', [ 'action'=>$turnItem['action'], 'arg'=>$turnItem['arg'], @@ -116,7 +116,7 @@ function pushNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){ return; } if($turnCnt < 0){ - pullNationCommand($nationID, $officerLevel, -$turnCnt); + pullNationCommand($nationID, $officerLevel, -$turnCnt); return; } if($turnCnt >= GameConst::$maxChiefTurn){ @@ -153,7 +153,7 @@ function pullNationCommand(int $nationID, int $officerLevel, int $turnCnt=1){ if($turnCnt >= GameConst::$maxChiefTurn){ return; } - + $db = DB::db(); $db->update('nation_turn', [ @@ -269,7 +269,7 @@ function checkCommandArg(?array $arg):?string{ } function setGeneralCommand(int $generalID, array $rawTurnList, string $command, ?array $arg = null):array{ - + $turnList = []; foreach($rawTurnList as $turnIdx){ if(!is_int($turnIdx) || $turnIdx < -3 || $turnIdx >= GameConst::$maxTurn){ diff --git a/hwe/j_general_turn.php b/hwe/j_general_turn.php deleted file mode 100644 index 358e00b9..00000000 --- a/hwe/j_general_turn.php +++ /dev/null @@ -1,42 +0,0 @@ -setReadOnly(); - -$generalID = $session->generalID; - -$turnAmount = Util::getPost('amount', 'int'); -$isRepeat = Util::getPost('is_repeat', 'bool', false); - -if($turnAmount == null){ - Json::die([ - 'result'=>false, - 'reason'=>'턴이 입력되지 않았습니다.', - ]); -} - -if(abs($turnAmount) >= GameConst::$maxTurn){ - Json::die([ - 'result'=>false, - 'reason'=>'턴 숫자가 올바르지 않습니다.', - ]); -} - -if($isRepeat){ - repeatGeneralCommand($generalID, $turnAmount); -} -else{ - pushGeneralCommand($generalID, $turnAmount); -} - -Json::die([ - 'result'=>true, - 'reason'=>'success', -]); \ No newline at end of file diff --git a/hwe/j_get_reserved_command.php b/hwe/j_get_reserved_command.php deleted file mode 100644 index 593508c9..00000000 --- a/hwe/j_get_reserved_command.php +++ /dev/null @@ -1,49 +0,0 @@ -setReadOnly(); - -$db = DB::db(); - -$commandList = []; -$gameStor = KVStorage::getStorage($db, 'game_env'); -$generalID = $session->generalID; - -$rawTurn = $db->queryAllLists('SELECT turn_idx, action, arg, brief FROM general_turn WHERE general_id = %i ORDER BY turn_idx ASC', $generalID); -foreach($rawTurn as [$turn_idx, $action, $arg, $brief]){ - $commandList[$turn_idx] = [ - 'action'=>$action, - 'brief'=>$brief, - 'arg'=>Json::decode($arg) - ]; -} - - -[$turnTerm, $year, $month, $lastExecute] = $gameStor->getValuesAsArray(['turnterm', 'year', 'month', 'turntime']); - -[$turnTime, $rawGeneralAux] = $db->queryFirstList('SELECT turntime, aux FROM general WHERE no=%i', $generalID); -$generalAux = Json::decode($rawGeneralAux??'{}'); - -if(cutTurn($turnTime, $turnTerm) > cutTurn($lastExecute, $turnTerm)){ - //이미 이번달에 실행된 턴이다. - $month++; - if($month >= 13){ - $month -= 12; - $year += 1; - } -} - - -Json::die([ - 'result'=>true, - 'turnTime'=>$turnTime, - 'turnTerm'=>$turnTerm, - 'year'=>$year, - 'month'=>$month, - 'date'=>TimeUtil::now(true), - 'turn'=>$commandList, - 'autorun_limit'=> $generalAux['autorun_limit']??null, -]); \ No newline at end of file diff --git a/hwe/sammo/API/Command/GetReservedCommand.php b/hwe/sammo/API/Command/GetReservedCommand.php new file mode 100644 index 00000000..5ed77069 --- /dev/null +++ b/hwe/sammo/API/Command/GetReservedCommand.php @@ -0,0 +1,69 @@ +generalID; + + $rawTurn = $db->queryAllLists('SELECT turn_idx, action, arg, brief FROM general_turn WHERE general_id = %i ORDER BY turn_idx ASC', $generalID); + foreach ($rawTurn as [$turn_idx, $action, $arg, $brief]) { + $commandList[$turn_idx] = [ + 'action' => $action, + 'brief' => $brief, + 'arg' => Json::decode($arg) + ]; + } + + + [$turnTerm, $year, $month, $lastExecute] = $gameStor->getValuesAsArray(['turnterm', 'year', 'month', 'turntime']); + + [$turnTime, $rawGeneralAux] = $db->queryFirstList('SELECT turntime, aux FROM general WHERE no=%i', $generalID); + $generalAux = Json::decode($rawGeneralAux ?? '{}'); + + if (cutTurn($turnTime, $turnTerm) > cutTurn($lastExecute, $turnTerm)) { + //이미 이번달에 실행된 턴이다. + $month++; + if ($month >= 13) { + $month -= 12; + $year += 1; + } + } + + return [ + 'result' => true, + 'turnTime' => $turnTime, + 'turnTerm' => $turnTerm, + 'year' => $year, + 'month' => $month, + 'date' => TimeUtil::now(true), + 'turn' => $commandList, + 'autorun_limit' => $generalAux['autorun_limit'] ?? null, + ]; + } +} diff --git a/hwe/sammo/API/Command/PushCommand.php b/hwe/sammo/API/Command/PushCommand.php new file mode 100644 index 00000000..dd3f8bf1 --- /dev/null +++ b/hwe/sammo/API/Command/PushCommand.php @@ -0,0 +1,47 @@ +args); + $v->rule('required', [ + 'amount', + ]) + ->rule('integer', 'amount') + ->rule('min', 'amount', -12) + ->rule('max', 'amount', 12); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $amount = $this->args['amount']; + if($amount == 0){ + return '0은 불가능합니다'; + } + pushGeneralCommand($session->generalID, $amount); + + return [ + 'result'=>true + ]; + } +} diff --git a/hwe/sammo/API/Command/RepeatCommand.php b/hwe/sammo/API/Command/RepeatCommand.php new file mode 100644 index 00000000..b48e571c --- /dev/null +++ b/hwe/sammo/API/Command/RepeatCommand.php @@ -0,0 +1,45 @@ +args); + $v->rule('required', [ + 'amount', + ]) + ->rule('integer', 'amount') + ->rule('min', 'amount', 1) + ->rule('max', 'amount', 12); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + + $amount = $this->args['amount']; + repeatGeneralCommand($session->generalID, $amount); + + return [ + 'result'=>true + ]; + } +} diff --git a/hwe/sammo/API/Command/ReserveCommand.php b/hwe/sammo/API/Command/ReserveCommand.php new file mode 100644 index 00000000..802c5dbd --- /dev/null +++ b/hwe/sammo/API/Command/ReserveCommand.php @@ -0,0 +1,56 @@ +args); + $v->rule('required', [ + 'action', + 'turnList' + ]) + ->rule('lengthMin', 'action', 1) + ->rule('integerArray', 'turnList'); + + if (!$v->validate()) { + return $v->errorStr(); + } + return null; + } + + public function getRequiredSessionMode(): int + { + return static::REQ_GAME_LOGIN | static::REQ_READ_ONLY; + } + + public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag) + { + $action = $this->args['action']; + $turnList = $this->args['turnList']; + $arg = $this->args['arg']??[]; + + if(!$turnList){ + return '턴이 입력되지 않았습니다'; + } + + if(!in_array($action, Util::array_flatten(GameConst::$availableGeneralCommand))){ + return '사용할 수 없는 커맨드입니다.'; + } + + if(!is_array($arg)){ + '올바른 arg 형태가 아닙니다.'; + } + + return setGeneralCommand($session->generalID, $turnList, $action, $arg); + } +} diff --git a/hwe/ts/ReservedCommand.vue b/hwe/ts/ReservedCommand.vue index a3655922..9b65415b 100644 --- a/hwe/ts/ReservedCommand.vue +++ b/hwe/ts/ReservedCommand.vue @@ -17,8 +17,16 @@
- - + {{ turnIdx }}턴 @@ -55,7 +63,10 @@
- {{ turnIdx }}턴 @@ -66,31 +77,59 @@ - + {{ turnIdx }}{{ turnIdx + 1 }} - - + {{ turnObj.year ? `${turnObj.year}年` : "" }} + {{ turnObj.month ? `${turnObj.month}月` : "" }} + + + > + {{ turnObj.time }} + - + @@ -99,54 +138,137 @@
- - + {{ turnIdx }}턴
-
{{flippedMaxTurn==viewMaxTurn?'펼치기':'접기'}}
+
+ {{ + flippedMaxTurn == viewMaxTurn ? "펼치기" : "접기" + }} +
-
- {{citem.title}}{{citem.possible?'':'(불가)'}} -
+
+ {{ citem.title + }}{{ citem.possible ? "" : "(불가)" }} + +
- 실행
+ 실행 +
\ No newline at end of file diff --git a/hwe/ts/main.ts b/hwe/ts/main.ts index 5e522a50..77c733db 100644 --- a/hwe/ts/main.ts +++ b/hwe/ts/main.ts @@ -2,211 +2,22 @@ import $ from 'jquery'; import Popper from 'popper.js'; exportWindow(Popper, 'Popper');//XXX: 왜 popper를 이렇게 불러야 하는가? import 'bootstrap'; -import { parseTime } from './util/parseTime'; -import { addMilliseconds, addMinutes, differenceInMilliseconds } from 'date-fns'; -import { formatTime } from './util/formatTime'; -import { unwrap_any } from './util/unwrap_any'; -import { activateFlip, errUnknown, initTooltip } from './common_legacy'; -import { unwrap } from './util/unwrap'; -import { setAxiosXMLHttpRequest } from './util/setAxiosXMLHttpRequest'; +import { activateFlip, initTooltip } from './common_legacy'; import './msg.ts'; import './map.ts'; import { exportWindow } from './util/exportWindow'; -import {stringifyUrl} from 'query-string'; -import { joinYearMonth } from './util/joinYearMonth'; -import { parseYearMonth } from './util/parseYearMonth'; - exportWindow($, '$'); import '../scss/main.scss'; -type TurnArg = { - //TODO: 채울것 -} - -type TurnItem = { - action: string, - brief: string, - arg: TurnArg, -} - -type ReservedTurnResponse = { - result: true, - turnTime: string, - turnTerm: number, - year: number, - month: number, - date: string, - turn: TurnItem[], - autorun_limit: number|null, -} - - $(function ($) { $('#refreshPage').click(function () { document.location.reload(); return false; }); - - function reloadCommandList() { - void $.get({ - url: 'j_get_reserved_command.php', - dataType: 'json', - cache: false, - }).then(function (data: ReservedTurnResponse) { - if (!data) { - return; - } - if (!data.result) { - return; - } - const game_clock = parseTime(data.date); - const now_clock = new Date(); - const $clock = $('#clock'); - $clock.data('time-diff', differenceInMilliseconds(game_clock, now_clock)); - $clock.val(formatTime(game_clock)); - - const turnTime = parseTime(data.turnTime); - let nextTurnTime = new Date(turnTime); - - let nowYearMonth = joinYearMonth(data.year, data.month); - const autorunLimitYearMonth = data.autorun_limit ?? nowYearMonth - 1; - const [autorunLimitYear, autorunLimitMonth] = parseYearMonth(autorunLimitYearMonth); - - for (const [turnIdx, turnInfo] of Object.entries(data.turn)) { - const [year, month] = parseYearMonth(nowYearMonth); - const $tr = $(`#command_${turnIdx}`); - - $tr.find('.time_pad').text(formatTime(nextTurnTime, 'HH:mm')); - $tr.find('.month_pad').text(`${year}年 ${month}月`); - const $turn_pad = $tr.find('.turn_pad'); - const $turn_text = $turn_pad.find('.turn_text'); - $turn_text.text(turnInfo.brief).css('font-size', '13px'); - if(nowYearMonth <= autorunLimitYearMonth){ - const brief = turnInfo.brief != '휴식'? turnInfo.brief :'휴식(자율 행동)'; - const autorunTooltip = `${brief}자율 행동 기간: ${autorunLimitYear}년 ${autorunLimitMonth}월까지`; - $turn_text.html(autorunTooltip); - initTooltip($turn_text); - } - - - const oWidth = unwrap($turn_pad.innerWidth()); - const iWidth = unwrap($turn_text.outerWidth()); - if (iWidth > oWidth * 0.95) { - const newFontSize = 13 * oWidth / iWidth * 0.9; - $turn_text.css('font-size', `${newFontSize}px`); - } - - nextTurnTime = addMinutes(nextTurnTime, data.turnTerm); - nowYearMonth += 1; - } - console.log(data); - - - }); - } - - function myclock() { - - const $clock = $('#clock'); - const now_clock = new Date(); - - const rawTimeDiff = $clock.data('time-diff'); - if (rawTimeDiff === null || rawTimeDiff === undefined) { - return; - } - const timeDiff = unwrap_any(rawTimeDiff); - - const gameClock = addMilliseconds(now_clock, timeDiff); - - $('#clock').val(formatTime(gameClock)); - } - - function pushTurn(pushAmount: number) { - $.post({ - url: 'j_general_turn.php', - dataType: 'json', - data: { - amount: pushAmount - } - }).then(function (data) { - if (!data.result) { - alert(data.reason); - } - reloadCommandList(); - }, errUnknown); - } - - function repeatTurn(repeatAmount: number) { - $.post({ - url: 'j_general_turn.php', - dataType: 'json', - data: { - amount: repeatAmount, - is_repeat: true - } - }).then(function (data) { - if (!data.result) { - alert(data.reason); - } - reloadCommandList(); - }, errUnknown); - } - - $('#pullTurn').click(function () { - pushTurn(-parseInt(unwrap_any($('#repeatAmount').val()))); - }); - - $('#pushTurn').click(function () { - pushTurn(parseInt(unwrap_any($('#repeatAmount').val()))); - }); - - $('#repeatTurn').click(function () { - repeatTurn(parseInt(unwrap_any($('#repeatAmount').val()))); - }); - - - function reserveTurn(turnList: number[], command: string) { - console.log(turnList, command); - $.post({ - url: 'j_set_general_command.php', - dataType: 'json', - data: { - action: command, - turnList: turnList - } - }).then(function (data) { - if (!data.result) { - alert(data.reason); - } - reloadCommandList(); - }, errUnknown); - } - - $('#reserveTurn').click(function () { - const turnList = unwrap_any($('#generalTurnSelector').val()).map(v => parseInt(v)); - const $command = $('#generalCommandList option:selected'); - if ($command.data('reqarg')) { - document.location.href = stringifyUrl({ - url: 'b_processing.php', - query: { - command: unwrap_any($command.val()), - turnList: turnList.join('_') - } - }); - } - else { - reserveTurn(turnList, unwrap_any($command.val())); - } - return false; - }) - $('.open-window').on('click', function(e){ e.preventDefault(); let target = $(e.target as HTMLAnchorElement); @@ -220,8 +31,6 @@ $(function ($) { window.open(href); }); - //setInterval(myclock, 500); - //reloadCommandList(); activateFlip(); initTooltip(); }); diff --git a/hwe/ts/util/sammoAPI.ts b/hwe/ts/util/sammoAPI.ts new file mode 100644 index 00000000..2897242e --- /dev/null +++ b/hwe/ts/util/sammoAPI.ts @@ -0,0 +1,28 @@ +import axios from "axios"; +import { isArray } from "lodash"; +import { InvalidResponse } from "../defs"; + +type ValidResponse = { + result: true +} + +export async function sammoAPI(path: string | string[], args?: Record): Promise { + if (isArray(path)) { + path = path.join('/'); + } + + const response = await axios({ + url: "api.php", + method: "post", + responseType: "json", + data: { + path, + args, + }, + }); + const result: InvalidResponse | ResultType = response.data; + if (!result.result) { + throw result.reason; + } + return result; +} \ No newline at end of file