feat,wip: 경매장 API export
This commit is contained in:
@@ -8,7 +8,7 @@ use sammo\AuctionSellRice;
|
|||||||
use sammo\Validator;
|
use sammo\Validator;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
|
|
||||||
class BidBuyRiceAuction extends \sammo\BaseAPI
|
class BidSellRiceAuction extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
public function validateArgs(): ?string
|
public function validateArgs(): ?string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use DateTimeInterface;
|
|||||||
use sammo\AuctionSellRice;
|
use sammo\AuctionSellRice;
|
||||||
use sammo\DB;
|
use sammo\DB;
|
||||||
use sammo\DTO\AuctionBidItem;
|
use sammo\DTO\AuctionBidItem;
|
||||||
|
use sammo\DTO\AuctionInfo;
|
||||||
use sammo\Enums\AuctionType;
|
use sammo\Enums\AuctionType;
|
||||||
use sammo\Validator;
|
use sammo\Validator;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
@@ -34,17 +35,18 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
|||||||
|
|
||||||
$buyRiceList = [];
|
$buyRiceList = [];
|
||||||
$sellRiceList = [];
|
$sellRiceList = [];
|
||||||
$rawAuctions = $db->query(
|
/** @var AuctionInfo[] */
|
||||||
|
$auctions = array_map(fn ($raw) => AuctionInfo::fromArray($raw), $db->query(
|
||||||
'SELECT * FROM `ng_auction` WHERE `type` IN %ls AND `finished` != 0 ORDER BY `close_date` DESC',
|
'SELECT * FROM `ng_auction` WHERE `type` IN %ls AND `finished` != 0 ORDER BY `close_date` DESC',
|
||||||
[
|
[
|
||||||
AuctionType::BuyRice->value,
|
AuctionType::BuyRice->value,
|
||||||
AuctionType::SellRice->value,
|
AuctionType::SellRice->value,
|
||||||
]
|
]
|
||||||
);
|
));
|
||||||
|
|
||||||
$auctionIDList = [];
|
$auctionIDList = [];
|
||||||
foreach ($rawAuctions as $rawAuction) {
|
foreach ($auctions as $auction) {
|
||||||
$auctionIDList[] = $rawAuction['id'];
|
$auctionIDList[] = $auction->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rawHighestBids = Util::convertArrayToDict($db->query(
|
$rawHighestBids = Util::convertArrayToDict($db->query(
|
||||||
@@ -64,17 +66,24 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
|||||||
$rawHighestBids
|
$rawHighestBids
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($rawAuctions as $rawAuction) {
|
foreach ($auctions as $auction) {
|
||||||
$detail = Json::decode($rawAuction['detail']);
|
$rawAuction = [
|
||||||
unset($rawAuction['detail']);
|
'id' => $auction->id,
|
||||||
$rawAuction = array_merge($rawAuction, $detail);
|
'type' => $auction->type->value,
|
||||||
|
'hostGeneralID' => $auction->hostGeneralID,
|
||||||
|
'hostName' => $auction->detail->hostName,
|
||||||
|
'openDate' => TimeUtil::format($auction->openDate, false),
|
||||||
|
'closeDate' => TimeUtil::format($auction->closeDate, false),
|
||||||
|
'amount' => $auction->detail->amount,
|
||||||
|
'startBidAmount' => $auction->detail->startBidAmount,
|
||||||
|
'finishBidAmount' => $auction->detail->finishBidAmount,
|
||||||
|
];
|
||||||
|
|
||||||
$highestBid = $highestBids[$rawAuction['id']] ?? null;
|
$highestBid = $highestBids[$rawAuction['id']] ?? null;
|
||||||
if($highestBid === null){
|
if ($highestBid === null) {
|
||||||
$rawAuction['highestBid'] = null;
|
$rawAuction['highestBid'] = null;
|
||||||
}
|
} else {
|
||||||
else {
|
$rawAuction['highestBid'] = [
|
||||||
$rawAuction['hightestBid'] = [
|
|
||||||
'amount' => $highestBid->amount,
|
'amount' => $highestBid->amount,
|
||||||
'date' => TimeUtil::format($highestBid->date, false),
|
'date' => TimeUtil::format($highestBid->date, false),
|
||||||
'generalID' => $highestBid->generalID,
|
'generalID' => $highestBid->generalID,
|
||||||
@@ -95,7 +104,8 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
|||||||
'result' => true,
|
'result' => true,
|
||||||
'buyRice' => $buyRiceList,
|
'buyRice' => $buyRiceList,
|
||||||
'sellRice' => $sellRiceList,
|
'sellRice' => $sellRiceList,
|
||||||
'recentLogs' => $recentLogs
|
'recentLogs' => $recentLogs,
|
||||||
|
'generalID' => $session->generalID,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\Auction;
|
||||||
|
|
||||||
|
use sammo\Session;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\DTO\AuctionBidItem;
|
||||||
|
use sammo\DTO\AuctionInfo;
|
||||||
|
use sammo\Enums\AuctionType;
|
||||||
|
use sammo\Validator;
|
||||||
|
|
||||||
|
class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
$v = new Validator($this->args);
|
||||||
|
$v->rule('required', [
|
||||||
|
'auction_id',
|
||||||
|
])
|
||||||
|
->rule('integer', 'auction_id');
|
||||||
|
|
||||||
|
if (!$v->validate()) {
|
||||||
|
return $v->errorStr();
|
||||||
|
}
|
||||||
|
$this->args['auction_id'] = (int)$this->args['auction_id'];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::REQ_GAME_LOGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$generalID = $session->generalID;
|
||||||
|
$auctionID = $this->args['auction_id'];
|
||||||
|
|
||||||
|
$rawAuction = $db->queryFirstRow(
|
||||||
|
'SELECT * FROM `ng_auction` WHERE `type` = %s AND `auction_id` = %s',
|
||||||
|
AuctionType::UniqueItem,
|
||||||
|
$auctionID
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$rawAuction) {
|
||||||
|
return '선택한 경매가 없습니다.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$auction = AuctionInfo::fromArray($rawAuction);
|
||||||
|
|
||||||
|
/** @var AuctionBidItem[] */
|
||||||
|
$bidList = array_map(fn ($raw) => AuctionBidItem::fromArray($raw), $db->query(
|
||||||
|
'SELECT * FROM `ng_auction_bid` WHERE `auction_id` = %s ORDER BY `amount` DESC',
|
||||||
|
$auctionID
|
||||||
|
) ?? []);
|
||||||
|
|
||||||
|
$responseBid = [];
|
||||||
|
foreach ($bidList as $bid) {
|
||||||
|
$responseBid[] = [
|
||||||
|
'generalName' => $bid->data->generalName,
|
||||||
|
'amount' => $bid->amount,
|
||||||
|
'isCallerHighestBidder' => $bid->generalID === $generalID,
|
||||||
|
'date' => $bid->date,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'result' => true,
|
||||||
|
'auction' => [
|
||||||
|
'id' => $auction->id,
|
||||||
|
'finished' => $auction->finished,
|
||||||
|
'title' => $auction->detail->title,
|
||||||
|
'target' => $auction->target,
|
||||||
|
'isCallerHost' => $auction->openerGeneralID === $generalID,
|
||||||
|
'hostName' => $auction->detail->hostName,
|
||||||
|
'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt,
|
||||||
|
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||||
|
],
|
||||||
|
'bidList' => $responseBid,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\Auction;
|
||||||
|
|
||||||
|
use sammo\Session;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use sammo\DB;
|
||||||
|
use sammo\DTO\AuctionBidItem;
|
||||||
|
use sammo\DTO\AuctionInfo;
|
||||||
|
use sammo\Enums\AuctionType;
|
||||||
|
use sammo\Util;
|
||||||
|
|
||||||
|
class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::REQ_GAME_LOGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
$db = DB::db();
|
||||||
|
|
||||||
|
$generalID = $session->generalID;
|
||||||
|
|
||||||
|
/** @var AuctionInfo[] */
|
||||||
|
$auctions = array_map(fn($raw)=>AuctionInfo::fromArray($raw), $db->query(
|
||||||
|
'SELECT * FROM `ng_auction` WHERE `type` = %s ORDER BY `close_date` DESC',
|
||||||
|
AuctionType::UniqueItem->value
|
||||||
|
) ?? []);
|
||||||
|
|
||||||
|
$auctionIDList = [];
|
||||||
|
foreach ($auctions as $auction) {
|
||||||
|
$auctionIDList[] = $auction->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$rawHighestBids = Util::convertArrayToDict($db->query(
|
||||||
|
'SELECT bid.* FROM `ng_auction_bid` bid INNER JOIN (
|
||||||
|
SELECT `auction_id`, MAX(`amount`) as `max_amount`
|
||||||
|
FROM `ng_auction_bid`
|
||||||
|
WHERE `auction_id` IN %li
|
||||||
|
GROUP BY `auction_id`
|
||||||
|
ORDER BY `amount`
|
||||||
|
) AS max_bid
|
||||||
|
ON bid.`auction_id` = max_bid.`auction_id` AND bid.`amount` = max_bid.`max_amount`',
|
||||||
|
$auctionIDList,
|
||||||
|
) ?? [], 'auction_id');
|
||||||
|
/** @var array<int,AuctionBidItem> */
|
||||||
|
$highestBids = Util::mapWithKey(
|
||||||
|
fn ($auctionID, $bid) => AuctionBidItem::fromArray($bid),
|
||||||
|
$rawHighestBids
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = [];
|
||||||
|
foreach ($auctions as $auction) {
|
||||||
|
$auctionID = $auction->id;
|
||||||
|
$highestBid = $highestBids[$auctionID] ?? null;
|
||||||
|
if($highestBid === null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response[] = [
|
||||||
|
'id' => $auctionID,
|
||||||
|
'finished' => $auction->finished,
|
||||||
|
'title' => $auction->detail->title,
|
||||||
|
'target' => $auction->target,
|
||||||
|
'isCallerHost' => $auction->openerGeneralID === $generalID,
|
||||||
|
'hostName' => $auction->detail->hostName,
|
||||||
|
'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt,
|
||||||
|
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||||
|
'highestBid' => [
|
||||||
|
'generalName' => $highestBid->data->generalName,
|
||||||
|
'amount' => $highestBid->amount,
|
||||||
|
'isCallerHighestBidder' => $highestBid->generalID === $generalID,
|
||||||
|
'date' => $highestBid->date,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'result' => true,
|
||||||
|
'list' => $response,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ use sammo\Validator;
|
|||||||
use sammo\GameConst;
|
use sammo\GameConst;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
|
|
||||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
class OpenBuyRiceAuction extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
public function validateArgs(): ?string
|
public function validateArgs(): ?string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use sammo\Validator;
|
|||||||
use sammo\GameConst;
|
use sammo\GameConst;
|
||||||
use sammo\General;
|
use sammo\General;
|
||||||
|
|
||||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
class OpenSellRiceAuction extends \sammo\BaseAPI
|
||||||
{
|
{
|
||||||
public function validateArgs(): ?string
|
public function validateArgs(): ?string
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ abstract class Auction
|
|||||||
|
|
||||||
$this->info->closeDate = $date;
|
$this->info->closeDate = $date;
|
||||||
$db = DB::db();
|
$db = DB::db();
|
||||||
$db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id);
|
$db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,7 @@ abstract class Auction
|
|||||||
$this->info->availableLatestBidCloseDate = $closeDate->add(TimeUtil::secondsToDateInterval(
|
$this->info->availableLatestBidCloseDate = $closeDate->add(TimeUtil::secondsToDateInterval(
|
||||||
max(static::MIN_EXTENSION_MINUTES_PER_BID, $turnTerm * static::COEFF_EXTENSION_MINUTES_PER_BID) * 60
|
max(static::MIN_EXTENSION_MINUTES_PER_BID, $turnTerm * static::COEFF_EXTENSION_MINUTES_PER_BID) * 60
|
||||||
));
|
));
|
||||||
$db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id);
|
$db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ abstract class Auction
|
|||||||
$this->rollbackAuction();
|
$this->rollbackAuction();
|
||||||
}
|
}
|
||||||
|
|
||||||
$db->update('ng_auction', $this->info->toArrayExcept('id'), 'id = %i', $this->info->id);
|
$db->update('ng_auction', $this->info->toArray('id'), 'id = %i', $this->info->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function bidInheritPoint(int $amount, \DateTimeImmutable $now, bool $tryExtendCloseDate): ?string
|
private function bidInheritPoint(int $amount, \DateTimeImmutable $now, bool $tryExtendCloseDate): ?string
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace sammo\DTO;
|
|||||||
use sammo\DTO\Attr\Convert;
|
use sammo\DTO\Attr\Convert;
|
||||||
use sammo\DTO\Attr\JsonString;
|
use sammo\DTO\Attr\JsonString;
|
||||||
use sammo\DTO\Attr\NullIsUndefined;
|
use sammo\DTO\Attr\NullIsUndefined;
|
||||||
|
use sammo\DTO\Attr\RawName;
|
||||||
use sammo\DTO\Converter\DateTimeConverter;
|
use sammo\DTO\Converter\DateTimeConverter;
|
||||||
use sammo\Enums\AuctionType;
|
use sammo\Enums\AuctionType;
|
||||||
use sammo\Enums\ResourceType;
|
use sammo\Enums\ResourceType;
|
||||||
@@ -17,11 +18,15 @@ class AuctionInfo extends DTO
|
|||||||
public AuctionType $type,
|
public AuctionType $type,
|
||||||
public bool $finished,
|
public bool $finished,
|
||||||
public ?string $target,
|
public ?string $target,
|
||||||
public int $openerGeneralID,
|
#[RawName('host_general_id')]
|
||||||
|
public int $hostGeneralID,
|
||||||
|
#[RawName('reqResource')]
|
||||||
public ResourceType $reqResource,
|
public ResourceType $reqResource,
|
||||||
|
|
||||||
|
#[RawName('open_date')]
|
||||||
#[Convert(DateTimeConverter::class)]
|
#[Convert(DateTimeConverter::class)]
|
||||||
public \DateTimeImmutable $openDate,
|
public \DateTimeImmutable $openDate,
|
||||||
|
#[RawName('close_date')]
|
||||||
#[Convert(DateTimeConverter::class)]
|
#[Convert(DateTimeConverter::class)]
|
||||||
public \DateTimeImmutable $closeDate,
|
public \DateTimeImmutable $closeDate,
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class AuctionInfoDetail extends DTO
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $title,
|
public string $title,
|
||||||
public string $openerName,
|
public string $hostName,
|
||||||
public int $amount,
|
public int $amount,
|
||||||
#[NullIsUndefined]
|
#[NullIsUndefined]
|
||||||
public ?bool $isReverse,
|
public ?bool $isReverse,
|
||||||
|
|||||||
+2
-2
@@ -696,14 +696,14 @@ CREATE TABLE `ng_auction` (
|
|||||||
`type` ENUM('buyRice','sellRice','uniqueItem') NOT NULL COLLATE 'utf8mb4_bin',
|
`type` ENUM('buyRice','sellRice','uniqueItem') NOT NULL COLLATE 'utf8mb4_bin',
|
||||||
`finished` BIT(1) NOT NULL,
|
`finished` BIT(1) NOT NULL,
|
||||||
`target` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
|
`target` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_bin',
|
||||||
`opener_general_id` INT(11) NOT NULL,
|
`host_general_id` INT(11) NOT NULL,
|
||||||
`req_resource` ENUM('gold','rice','inheritPoint') NOT NULL COLLATE 'utf8mb4_bin',
|
`req_resource` ENUM('gold','rice','inheritPoint') NOT NULL COLLATE 'utf8mb4_bin',
|
||||||
`open_date` DATETIME NOT NULL,
|
`open_date` DATETIME NOT NULL,
|
||||||
`close_date` DATETIME NOT NULL,
|
`close_date` DATETIME NOT NULL,
|
||||||
`detail` LONGTEXT NOT NULL COLLATE 'utf8mb4_bin',
|
`detail` LONGTEXT NOT NULL COLLATE 'utf8mb4_bin',
|
||||||
PRIMARY KEY (`id`) USING BTREE,
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
INDEX `by_close` (`finished`, `type`, `close_date`) USING BTREE,
|
INDEX `by_close` (`finished`, `type`, `close_date`) USING BTREE,
|
||||||
INDEX `by_general_id` (`opener_general_id`, `type`, `finished`) USING BTREE,
|
INDEX `by_general_id` (`host_general_id`, `type`, `finished`) USING BTREE,
|
||||||
CONSTRAINT `detail` CHECK (json_valid(`detail`))
|
CONSTRAINT `detail` CHECK (json_valid(`detail`))
|
||||||
)
|
)
|
||||||
COLLATE='utf8mb4_general_ci'
|
COLLATE='utf8mb4_general_ci'
|
||||||
|
|||||||
+248
-160
@@ -1,7 +1,16 @@
|
|||||||
import type { Args } from "./processing/args";
|
import type { Args } from "./processing/args";
|
||||||
import {
|
import {
|
||||||
callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT,
|
callSammoAPI,
|
||||||
type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse
|
extractHttpMethod,
|
||||||
|
GET,
|
||||||
|
PATCH,
|
||||||
|
POST,
|
||||||
|
PUT,
|
||||||
|
type APITail,
|
||||||
|
type APICallT,
|
||||||
|
type RawArgType,
|
||||||
|
type ValidResponse,
|
||||||
|
type InvalidResponse,
|
||||||
} from "./util/callSammoAPI";
|
} from "./util/callSammoAPI";
|
||||||
export type { ValidResponse, InvalidResponse };
|
export type { ValidResponse, InvalidResponse };
|
||||||
import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js";
|
import { APIPathGen, NumVar, StrVar } from "./util/APIPathGen.js";
|
||||||
@@ -12,168 +21,247 @@ import type { inheritBuffType } 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";
|
||||||
import type { GetConstResponse, GetCurrentHistoryResponse, GetDiplomacyResponse, GetHistoryResponse } from "./defs/API/Global";
|
import type {
|
||||||
|
GetConstResponse,
|
||||||
|
GetCurrentHistoryResponse,
|
||||||
|
GetDiplomacyResponse,
|
||||||
|
GetHistoryResponse,
|
||||||
|
} from "./defs/API/Global";
|
||||||
import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs";
|
import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs";
|
||||||
import type { VoteDetailResult, VoteListResult } from "./defs/API/Vote";
|
import type { VoteDetailResult, VoteListResult } from "./defs/API/Vote";
|
||||||
|
import type { ActiveResourceAuctionList, OpenAuctionResponse, UniqueItemAuctionDetail, UniqueItemAuctionList } from "./defs/API/Auction";
|
||||||
|
|
||||||
const apiRealPath = {
|
const apiRealPath = {
|
||||||
Betting: {
|
Auction: {
|
||||||
Bet: PUT as APICallT<{
|
BidBuyRiceAuction: PUT as APICallT<{
|
||||||
bettingID: number,
|
auctionID: number;
|
||||||
bettingType: number[],
|
amount: number;
|
||||||
amount: number,
|
}>,
|
||||||
}>,
|
BidSellRiceAuction: PUT as APICallT<{
|
||||||
GetBettingDetail: NumVar('betting_id',
|
auctionID: number;
|
||||||
GET as APICallT<undefined, BettingDetailResponse>
|
amount: number;
|
||||||
),
|
}>,
|
||||||
GetBettingList: GET as APICallT<{
|
GetActiveResourceAuctionList: GET as APICallT<undefined, ActiveResourceAuctionList>,
|
||||||
req?: 'bettingNation' | 'tournament'
|
OpenBuyRiceAuction: POST as APICallT<
|
||||||
}, BettingListResponse>,
|
{
|
||||||
},
|
amount: number;
|
||||||
Command: {
|
closeTurnCnt: number;
|
||||||
GetReservedCommand: GET as APICallT<undefined, ReservedCommandResponse>,
|
startBidAmount: number;
|
||||||
PushCommand: PUT as APICallT<{
|
finishBidAmount: number;
|
||||||
amount: number
|
},
|
||||||
}>,
|
OpenAuctionResponse
|
||||||
RepeatCommand: PUT as APICallT<{
|
>,
|
||||||
amount: number
|
OpenSellRiceAuction: POST as APICallT<
|
||||||
}>,
|
{
|
||||||
ReserveCommand: PUT as APICallT<{
|
amount: number;
|
||||||
turnList: number[],
|
closeTurnCnt: number;
|
||||||
action: string,
|
startBidAmount: number;
|
||||||
arg?: Args
|
finishBidAmount: number;
|
||||||
}, ReserveCommandResponse>,
|
},
|
||||||
ReserveBulkCommand: PUT as APICallT<{
|
OpenAuctionResponse
|
||||||
turnList: number[],
|
>,
|
||||||
action: string,
|
|
||||||
arg?: Args
|
BidUniqueAuction: PUT as APICallT<{
|
||||||
}[], ReserveBulkCommandResponse>,
|
auctionID: number;
|
||||||
},
|
amount: number;
|
||||||
General: {
|
}>,
|
||||||
Join: POST as APICallT<JoinArgs>,
|
GetUniqueItemAuctionDetail: GET as APICallT<{
|
||||||
GetGeneralLog: GET as APICallT<{
|
auctionID: number;
|
||||||
reqType: GeneralLogType,
|
}, UniqueItemAuctionDetail>,
|
||||||
reqTo?: number
|
GetUniqueItemAuctionList: GET as APICallT<undefined, UniqueItemAuctionList>,
|
||||||
}, GetGeneralLogResponse>,
|
OpenUniqueAuction: POST as APICallT<{
|
||||||
DropItem: PUT as APICallT<{
|
itemID: string,
|
||||||
itemType: ItemTypeKey
|
amount: number,
|
||||||
}>
|
}, OpenAuctionResponse>,
|
||||||
},
|
},
|
||||||
Global: {
|
Betting: {
|
||||||
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
Bet: PUT as APICallT<{
|
||||||
GeneralListWithToken: GET as APICallT<undefined, GeneralListResponse>,
|
bettingID: number;
|
||||||
GetConst: GET as APICallT<undefined, GetConstResponse>,
|
bettingType: number[];
|
||||||
GetHistory: StrVar('serverID')(
|
amount: number;
|
||||||
NumVar('year',
|
}>,
|
||||||
NumVar('month', GET as APICallT<undefined, GetHistoryResponse>
|
GetBettingDetail: NumVar("betting_id", GET as APICallT<undefined, BettingDetailResponse>),
|
||||||
))),
|
GetBettingList: GET as APICallT<
|
||||||
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>,
|
{
|
||||||
GetMap: GET as APICallT<{
|
req?: "bettingNation" | "tournament";
|
||||||
neutralView?: 0 | 1,
|
},
|
||||||
showMe?: 0 | 1,
|
BettingListResponse
|
||||||
}, MapResult>,
|
>,
|
||||||
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
},
|
||||||
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
Command: {
|
||||||
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
GetReservedCommand: GET as APICallT<undefined, ReservedCommandResponse>,
|
||||||
},
|
PushCommand: PUT as APICallT<{
|
||||||
InheritAction: {
|
amount: number;
|
||||||
BuyHiddenBuff: PUT as APICallT<{
|
}>,
|
||||||
type: inheritBuffType,
|
RepeatCommand: PUT as APICallT<{
|
||||||
level: number
|
amount: number;
|
||||||
}>,
|
}>,
|
||||||
BuyRandomUnique: PUT as APICallT<undefined>,
|
ReserveCommand: PUT as APICallT<
|
||||||
BuySpecificUnique: PUT as APICallT<{
|
{
|
||||||
item: string,
|
turnList: number[];
|
||||||
amount: number,
|
action: string;
|
||||||
}>,
|
arg?: Args;
|
||||||
ResetSpecialWar: PUT as APICallT<undefined>,
|
},
|
||||||
ResetTurnTime: PUT as APICallT<undefined>,
|
ReserveCommandResponse
|
||||||
SetNextSpecialWar: PUT as APICallT<{
|
>,
|
||||||
type: string,
|
ReserveBulkCommand: PUT as APICallT<
|
||||||
}>,
|
{
|
||||||
},
|
turnList: number[];
|
||||||
Misc: {
|
action: string;
|
||||||
UploadImage: POST as APICallT<{
|
arg?: Args;
|
||||||
imageData: string,
|
}[],
|
||||||
}, UploadImageResponse>
|
ReserveBulkCommandResponse
|
||||||
},
|
>,
|
||||||
NationCommand: {
|
},
|
||||||
GetReservedCommand: GET as APICallT<undefined, ChiefResponse>,
|
General: {
|
||||||
PushCommand: PUT as APICallT<{
|
Join: POST as APICallT<JoinArgs>,
|
||||||
amount: number
|
GetGeneralLog: GET as APICallT<
|
||||||
}>,
|
{
|
||||||
RepeatCommand: PUT as APICallT<{
|
reqType: GeneralLogType;
|
||||||
amount: number
|
reqTo?: number;
|
||||||
}>,
|
},
|
||||||
ReserveCommand: PUT as APICallT<{
|
GetGeneralLogResponse
|
||||||
turnList: number[],
|
>,
|
||||||
action: string,
|
DropItem: PUT as APICallT<{
|
||||||
arg?: Args
|
itemType: ItemTypeKey;
|
||||||
}, ReserveCommandResponse>,
|
}>,
|
||||||
ReserveBulkCommand: PUT as APICallT<{
|
},
|
||||||
turnList: number[],
|
Global: {
|
||||||
action: string,
|
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
||||||
arg?: Args
|
GeneralListWithToken: GET as APICallT<undefined, GeneralListResponse>,
|
||||||
}[], ReserveBulkCommandResponse>,
|
GetConst: GET as APICallT<undefined, GetConstResponse>,
|
||||||
},
|
GetHistory: StrVar("serverID")(NumVar("year", NumVar("month", GET as APICallT<undefined, GetHistoryResponse>))),
|
||||||
Nation: {
|
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>,
|
||||||
GeneralList: GET as APICallT<undefined, NationGeneralListResponse>,
|
GetMap: GET as APICallT<
|
||||||
SetNotice: PUT as APICallT<{
|
{
|
||||||
msg: string,
|
neutralView?: 0 | 1;
|
||||||
}>,
|
showMe?: 0 | 1;
|
||||||
SetScoutMsg: PUT as APICallT<{
|
},
|
||||||
msg: string,
|
MapResult
|
||||||
}>,
|
>,
|
||||||
SetBill: PATCH as APICallT<{
|
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
||||||
amount: number,
|
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
||||||
}>,
|
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
||||||
SetRate: PATCH as APICallT<{
|
},
|
||||||
amount: number,
|
InheritAction: {
|
||||||
}>,
|
BuyHiddenBuff: PUT as APICallT<{
|
||||||
SetSecretLimit: PATCH as APICallT<{
|
type: inheritBuffType;
|
||||||
amount: number,
|
level: number;
|
||||||
}>,
|
}>,
|
||||||
SetBlockWar: PATCH as APICallT<{
|
BuyRandomUnique: PUT as APICallT<undefined>,
|
||||||
value: boolean,
|
BuySpecificUnique: PUT as APICallT<{
|
||||||
}, SetBlockWarResponse>,
|
item: string;
|
||||||
SetBlockScout: PATCH as APICallT<{
|
amount: number;
|
||||||
value: boolean,
|
}>,
|
||||||
}>,
|
ResetSpecialWar: PUT as APICallT<undefined>,
|
||||||
GetGeneralLog: GET as APICallT<{
|
ResetTurnTime: PUT as APICallT<undefined>,
|
||||||
generalID: number,
|
SetNextSpecialWar: PUT as APICallT<{
|
||||||
reqType: GeneralLogType,
|
type: string;
|
||||||
reqTo?: number
|
}>,
|
||||||
}, GetGeneralLogResponse>
|
},
|
||||||
},
|
Misc: {
|
||||||
Vote: {
|
UploadImage: POST as APICallT<
|
||||||
AddComment: POST as APICallT<{
|
{
|
||||||
voteID: number,
|
imageData: string;
|
||||||
text: string,
|
},
|
||||||
}>,
|
UploadImageResponse
|
||||||
GetVoteList: GET as APICallT<undefined, VoteListResult>,
|
>,
|
||||||
GetVoteDetail: GET as APICallT<{
|
},
|
||||||
voteID: number
|
NationCommand: {
|
||||||
}, VoteDetailResult>,
|
GetReservedCommand: GET as APICallT<undefined, ChiefResponse>,
|
||||||
NewVote: POST as APICallT<{
|
PushCommand: PUT as APICallT<{
|
||||||
title: string,
|
amount: number;
|
||||||
multipleOptions?: number,
|
}>,
|
||||||
endDate?: string,
|
RepeatCommand: PUT as APICallT<{
|
||||||
options: string[],
|
amount: number;
|
||||||
keepOldVote?: boolean,
|
}>,
|
||||||
}>,
|
ReserveCommand: PUT as APICallT<
|
||||||
Vote: POST as APICallT<{
|
{
|
||||||
voteID: number,
|
turnList: number[];
|
||||||
selection: number[],
|
action: string;
|
||||||
}, ValidResponse & {wonLottery: boolean}>,
|
arg?: Args;
|
||||||
}
|
},
|
||||||
|
ReserveCommandResponse
|
||||||
|
>,
|
||||||
|
ReserveBulkCommand: PUT as APICallT<
|
||||||
|
{
|
||||||
|
turnList: number[];
|
||||||
|
action: string;
|
||||||
|
arg?: Args;
|
||||||
|
}[],
|
||||||
|
ReserveBulkCommandResponse
|
||||||
|
>,
|
||||||
|
},
|
||||||
|
Nation: {
|
||||||
|
GeneralList: GET as APICallT<undefined, NationGeneralListResponse>,
|
||||||
|
SetNotice: PUT as APICallT<{
|
||||||
|
msg: string;
|
||||||
|
}>,
|
||||||
|
SetScoutMsg: PUT as APICallT<{
|
||||||
|
msg: string;
|
||||||
|
}>,
|
||||||
|
SetBill: PATCH as APICallT<{
|
||||||
|
amount: number;
|
||||||
|
}>,
|
||||||
|
SetRate: PATCH as APICallT<{
|
||||||
|
amount: number;
|
||||||
|
}>,
|
||||||
|
SetSecretLimit: PATCH as APICallT<{
|
||||||
|
amount: number;
|
||||||
|
}>,
|
||||||
|
SetBlockWar: PATCH as APICallT<
|
||||||
|
{
|
||||||
|
value: boolean;
|
||||||
|
},
|
||||||
|
SetBlockWarResponse
|
||||||
|
>,
|
||||||
|
SetBlockScout: PATCH as APICallT<{
|
||||||
|
value: boolean;
|
||||||
|
}>,
|
||||||
|
GetGeneralLog: GET as APICallT<
|
||||||
|
{
|
||||||
|
generalID: number;
|
||||||
|
reqType: GeneralLogType;
|
||||||
|
reqTo?: number;
|
||||||
|
},
|
||||||
|
GetGeneralLogResponse
|
||||||
|
>,
|
||||||
|
},
|
||||||
|
Vote: {
|
||||||
|
AddComment: POST as APICallT<{
|
||||||
|
voteID: number;
|
||||||
|
text: string;
|
||||||
|
}>,
|
||||||
|
GetVoteList: GET as APICallT<undefined, VoteListResult>,
|
||||||
|
GetVoteDetail: GET as APICallT<
|
||||||
|
{
|
||||||
|
voteID: number;
|
||||||
|
},
|
||||||
|
VoteDetailResult
|
||||||
|
>,
|
||||||
|
NewVote: POST as APICallT<{
|
||||||
|
title: string;
|
||||||
|
multipleOptions?: number;
|
||||||
|
endDate?: string;
|
||||||
|
options: string[];
|
||||||
|
keepOldVote?: boolean;
|
||||||
|
}>,
|
||||||
|
Vote: POST as APICallT<
|
||||||
|
{
|
||||||
|
voteID: number;
|
||||||
|
selection: number[];
|
||||||
|
},
|
||||||
|
ValidResponse & { wonLottery: boolean }
|
||||||
|
>,
|
||||||
|
},
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => {
|
export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => {
|
||||||
const method = extractHttpMethod(tail);
|
const method = extractHttpMethod(tail);
|
||||||
return (args?: RawArgType, returnError?: boolean) => {
|
return (args?: RawArgType, returnError?: boolean) => {
|
||||||
if (returnError) {
|
if (returnError) {
|
||||||
return callSammoAPI(method, path.join('/'), args, pathParam, true);
|
return callSammoAPI(method, path.join("/"), args, pathParam, true);
|
||||||
}
|
}
|
||||||
return callSammoAPI(method, path.join('/'), args, pathParam);
|
return callSammoAPI(method, path.join("/"), args, pathParam);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import type { ValidResponse } from "@/util/callSammoAPI";
|
||||||
|
|
||||||
|
export type BasicResourceAuctionBidder = {
|
||||||
|
amount: number;
|
||||||
|
date: string;
|
||||||
|
generalID: number;
|
||||||
|
generalName: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type BasicResourceAuctionInfo = {
|
||||||
|
id: number;
|
||||||
|
type: "buyRice" | "sellRice";
|
||||||
|
hostGeneralID: number;
|
||||||
|
hostName: string;
|
||||||
|
openDate: string;
|
||||||
|
closeDate: string;
|
||||||
|
amount: number;
|
||||||
|
startBidAmount: number;
|
||||||
|
finishBidAmount: number;
|
||||||
|
highestBid: BasicResourceAuctionBidder;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UniqueItemAuctionBidder = {
|
||||||
|
generalName: string;
|
||||||
|
amount: number;
|
||||||
|
isCallerHighestBidder: boolean;
|
||||||
|
date: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UniqueItemAuctionInfo = {
|
||||||
|
id: number;
|
||||||
|
finished: boolean;
|
||||||
|
title: string;
|
||||||
|
target: string;
|
||||||
|
isCallerHost: boolean;
|
||||||
|
hostName: string;
|
||||||
|
remainCloseDateExtensionCnt: number;
|
||||||
|
availableLatestBidCloseDate: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ActiveResourceAuctionList = ValidResponse & {
|
||||||
|
buyRice: BasicResourceAuctionInfo[];
|
||||||
|
sellRice: BasicResourceAuctionInfo[];
|
||||||
|
recentLogs: string[];
|
||||||
|
generalID: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UniqueItemAuctionList = ValidResponse & {
|
||||||
|
list: (
|
||||||
|
| UniqueItemAuctionInfo
|
||||||
|
| {
|
||||||
|
highestBid: UniqueItemAuctionBidder;
|
||||||
|
}
|
||||||
|
)[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type UniqueItemAuctionDetail = ValidResponse & {
|
||||||
|
auction: UniqueItemAuctionInfo;
|
||||||
|
bidList: UniqueItemAuctionBidder[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type OpenAuctionResponse = ValidResponse & {
|
||||||
|
auctionID: number;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user