diff --git a/hwe/sammo/API/Command/GetReservedUserAction.php b/hwe/sammo/API/Command/GetReservedUserAction.php new file mode 100644 index 00000000..9b31837c --- /dev/null +++ b/hwe/sammo/API/Command/GetReservedUserAction.php @@ -0,0 +1,47 @@ +generalID; + + $userActionKey = 'user_action'; + + $rawUserActions = $db->queryFirstField('SELECT JSON_QUERY(`aux`, %s) FROM general WHERE no=%i', "$.{$userActionKey}", $generalID); + if($rawUserActions === null){ + $rawUserActions = '{}'; + } + + $userActions = UserAction::fromArray(Json::decode($rawUserActions)); + + return [ + 'result' => true, + 'userActions' => $userActions->toArray(), + ]; + } +} diff --git a/hwe/sammo/API/Command/ReserveUserAction.php b/hwe/sammo/API/Command/ReserveUserAction.php new file mode 100644 index 00000000..20824ceb --- /dev/null +++ b/hwe/sammo/API/Command/ReserveUserAction.php @@ -0,0 +1,90 @@ +args); + $v->rule('required', [ + 'turnIdx', + 'action' + ]) + ->rule('int', 'turnIdx') + ->rule('max', 'turnIdx', GameConst::$maxTurn) + ->rule('min', 'turnIdx', 0) + ->rule('lengthMin', 'action', 1); + 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): null | string | array | APIRecoveryType + { + $turnIdx = $this->args['turnIdx']; + $action = $this->args['action']; + + $userActionKey = 'user_action'; + + if($turnIdx < 0 || $turnIdx >= GameConst::$maxTurn){ + return '올바르지 않은 턴입니다.'; + } + + if(!in_array($action, Util::array_flatten(GameConst::$availableUserActionCommand))){ + return '사용할 수 없는 커맨드입니다.'; + } + + $db = DB::db(); + $generalID = $session->generalID; + $rawUserActions = $db->queryFirstField('SELECT JSON_QUERY(`aux`, %s) FROM general WHERE no=%i', "$.{$userActionKey}", $generalID); + if(!$rawUserActions){ + $rawUserActions = '{}'; + } + + $tmp = Json::decode($rawUserActions); + $userActions = UserAction::fromArray($tmp); + + + $gameStor = KVStorage::getStorage($db, 'game_env'); + $gameStor->cacheAll(); + $general = General::createObjFromDB($generalID); + + $item = buildUserActionCommandClass($action, $general, $gameStor->getAll()); + $userActions->reserved[$turnIdx] = new UserActionItem( + $item->getRawClassName(), + $item->getCommandDetailTitle(), + null, + ); + + $db->update('general', [ + 'aux' => $db->sqleval('JSON_SET(`aux`, %s, JSON_EXTRACT(%s, "$"))', "$.{$userActionKey}", Json::encode($userActions->toArray())), + ], 'no=%i', $generalID); + + return [ + 'result' => true, + ]; + } +} diff --git a/hwe/sammo/DTO/UserAction.php b/hwe/sammo/DTO/UserAction.php new file mode 100644 index 00000000..833105ca --- /dev/null +++ b/hwe/sammo/DTO/UserAction.php @@ -0,0 +1,25 @@ + $reserved + * */ + public function __construct( + + #[Convert(MapConverter::class, [UserActionItem::class])] + public ?array $reserved, + #[Convert(ArrayConverter::class, [UserActionItem::class])] + public ?array $active, + ) { + } +} diff --git a/hwe/sammo/DTO/UserActionItem.php b/hwe/sammo/DTO/UserActionItem.php new file mode 100644 index 00000000..81f630f9 --- /dev/null +++ b/hwe/sammo/DTO/UserActionItem.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/hwe/ts/ReservedCommandForUserAction.vue b/hwe/ts/ReservedCommandForUserAction.vue index e9a48a88..6edb9109 100644 --- a/hwe/ts/ReservedCommandForUserAction.vue +++ b/hwe/ts/ReservedCommandForUserAction.vue @@ -17,15 +17,15 @@