feat,wip: 경매장 API export
This commit is contained in:
@@ -8,7 +8,7 @@ use sammo\AuctionSellRice;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
|
||||
class BidBuyRiceAuction extends \sammo\BaseAPI
|
||||
class BidSellRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
@@ -7,6 +7,7 @@ use DateTimeInterface;
|
||||
use sammo\AuctionSellRice;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Validator;
|
||||
use sammo\General;
|
||||
@@ -34,17 +35,18 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
|
||||
$buyRiceList = [];
|
||||
$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',
|
||||
[
|
||||
AuctionType::BuyRice->value,
|
||||
AuctionType::SellRice->value,
|
||||
]
|
||||
);
|
||||
));
|
||||
|
||||
$auctionIDList = [];
|
||||
foreach ($rawAuctions as $rawAuction) {
|
||||
$auctionIDList[] = $rawAuction['id'];
|
||||
foreach ($auctions as $auction) {
|
||||
$auctionIDList[] = $auction->id;
|
||||
}
|
||||
|
||||
$rawHighestBids = Util::convertArrayToDict($db->query(
|
||||
@@ -64,17 +66,24 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
$rawHighestBids
|
||||
);
|
||||
|
||||
foreach ($rawAuctions as $rawAuction) {
|
||||
$detail = Json::decode($rawAuction['detail']);
|
||||
unset($rawAuction['detail']);
|
||||
$rawAuction = array_merge($rawAuction, $detail);
|
||||
foreach ($auctions as $auction) {
|
||||
$rawAuction = [
|
||||
'id' => $auction->id,
|
||||
'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;
|
||||
if($highestBid === null){
|
||||
if ($highestBid === null) {
|
||||
$rawAuction['highestBid'] = null;
|
||||
}
|
||||
else {
|
||||
$rawAuction['hightestBid'] = [
|
||||
} else {
|
||||
$rawAuction['highestBid'] = [
|
||||
'amount' => $highestBid->amount,
|
||||
'date' => TimeUtil::format($highestBid->date, false),
|
||||
'generalID' => $highestBid->generalID,
|
||||
@@ -95,7 +104,8 @@ class GetActiveResourceAuctionList extends \sammo\BaseAPI
|
||||
'result' => true,
|
||||
'buyRice' => $buyRiceList,
|
||||
'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\General;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
class OpenBuyRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ use sammo\Validator;
|
||||
use sammo\GameConst;
|
||||
use sammo\General;
|
||||
|
||||
class OpenUniqueAuction extends \sammo\BaseAPI
|
||||
class OpenSellRiceAuction extends \sammo\BaseAPI
|
||||
{
|
||||
public function validateArgs(): ?string
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ abstract class Auction
|
||||
|
||||
$this->info->closeDate = $date;
|
||||
$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;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ abstract class Auction
|
||||
$this->info->availableLatestBidCloseDate = $closeDate->add(TimeUtil::secondsToDateInterval(
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ abstract class Auction
|
||||
$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
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace sammo\DTO;
|
||||
use sammo\DTO\Attr\Convert;
|
||||
use sammo\DTO\Attr\JsonString;
|
||||
use sammo\DTO\Attr\NullIsUndefined;
|
||||
use sammo\DTO\Attr\RawName;
|
||||
use sammo\DTO\Converter\DateTimeConverter;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\Enums\ResourceType;
|
||||
@@ -17,11 +18,15 @@ class AuctionInfo extends DTO
|
||||
public AuctionType $type,
|
||||
public bool $finished,
|
||||
public ?string $target,
|
||||
public int $openerGeneralID,
|
||||
#[RawName('host_general_id')]
|
||||
public int $hostGeneralID,
|
||||
#[RawName('reqResource')]
|
||||
public ResourceType $reqResource,
|
||||
|
||||
#[RawName('open_date')]
|
||||
#[Convert(DateTimeConverter::class)]
|
||||
public \DateTimeImmutable $openDate,
|
||||
#[RawName('close_date')]
|
||||
#[Convert(DateTimeConverter::class)]
|
||||
public \DateTimeImmutable $closeDate,
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class AuctionInfoDetail extends DTO
|
||||
{
|
||||
public function __construct(
|
||||
public string $title,
|
||||
public string $openerName,
|
||||
public string $hostName,
|
||||
public int $amount,
|
||||
#[NullIsUndefined]
|
||||
public ?bool $isReverse,
|
||||
|
||||
+2
-2
@@ -696,14 +696,14 @@ CREATE TABLE `ng_auction` (
|
||||
`type` ENUM('buyRice','sellRice','uniqueItem') NOT NULL COLLATE 'utf8mb4_bin',
|
||||
`finished` BIT(1) NOT NULL,
|
||||
`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',
|
||||
`open_date` DATETIME NOT NULL,
|
||||
`close_date` DATETIME NOT NULL,
|
||||
`detail` LONGTEXT NOT NULL COLLATE 'utf8mb4_bin',
|
||||
PRIMARY KEY (`id`) 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`))
|
||||
)
|
||||
COLLATE='utf8mb4_general_ci'
|
||||
|
||||
+248
-160
@@ -1,7 +1,16 @@
|
||||
import type { Args } from "./processing/args";
|
||||
import {
|
||||
callSammoAPI, extractHttpMethod, GET, PATCH, POST, PUT,
|
||||
type APITail, type APICallT, type RawArgType, type ValidResponse, type InvalidResponse
|
||||
callSammoAPI,
|
||||
extractHttpMethod,
|
||||
GET,
|
||||
PATCH,
|
||||
POST,
|
||||
PUT,
|
||||
type APITail,
|
||||
type APICallT,
|
||||
type RawArgType,
|
||||
type ValidResponse,
|
||||
type InvalidResponse,
|
||||
} from "./util/callSammoAPI";
|
||||
export type { ValidResponse, InvalidResponse };
|
||||
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 { 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 {
|
||||
GetConstResponse,
|
||||
GetCurrentHistoryResponse,
|
||||
GetDiplomacyResponse,
|
||||
GetHistoryResponse,
|
||||
} from "./defs/API/Global";
|
||||
import type { CachedMapResult, GeneralListResponse, ItemTypeKey, MapResult } from "./defs";
|
||||
import type { VoteDetailResult, VoteListResult } from "./defs/API/Vote";
|
||||
import type { ActiveResourceAuctionList, OpenAuctionResponse, UniqueItemAuctionDetail, UniqueItemAuctionList } from "./defs/API/Auction";
|
||||
|
||||
const apiRealPath = {
|
||||
Betting: {
|
||||
Bet: PUT as APICallT<{
|
||||
bettingID: number,
|
||||
bettingType: number[],
|
||||
amount: number,
|
||||
}>,
|
||||
GetBettingDetail: NumVar('betting_id',
|
||||
GET as APICallT<undefined, BettingDetailResponse>
|
||||
),
|
||||
GetBettingList: GET as APICallT<{
|
||||
req?: 'bettingNation' | 'tournament'
|
||||
}, BettingListResponse>,
|
||||
},
|
||||
Command: {
|
||||
GetReservedCommand: GET as APICallT<undefined, ReservedCommandResponse>,
|
||||
PushCommand: PUT as APICallT<{
|
||||
amount: number
|
||||
}>,
|
||||
RepeatCommand: PUT as APICallT<{
|
||||
amount: number
|
||||
}>,
|
||||
ReserveCommand: PUT as APICallT<{
|
||||
turnList: number[],
|
||||
action: string,
|
||||
arg?: Args
|
||||
}, ReserveCommandResponse>,
|
||||
ReserveBulkCommand: PUT as APICallT<{
|
||||
turnList: number[],
|
||||
action: string,
|
||||
arg?: Args
|
||||
}[], ReserveBulkCommandResponse>,
|
||||
},
|
||||
General: {
|
||||
Join: POST as APICallT<JoinArgs>,
|
||||
GetGeneralLog: GET as APICallT<{
|
||||
reqType: GeneralLogType,
|
||||
reqTo?: number
|
||||
}, GetGeneralLogResponse>,
|
||||
DropItem: PUT as APICallT<{
|
||||
itemType: ItemTypeKey
|
||||
}>
|
||||
},
|
||||
Global: {
|
||||
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
||||
GeneralListWithToken: GET as APICallT<undefined, GeneralListResponse>,
|
||||
GetConst: GET as APICallT<undefined, GetConstResponse>,
|
||||
GetHistory: StrVar('serverID')(
|
||||
NumVar('year',
|
||||
NumVar('month', GET as APICallT<undefined, GetHistoryResponse>
|
||||
))),
|
||||
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>,
|
||||
GetMap: GET as APICallT<{
|
||||
neutralView?: 0 | 1,
|
||||
showMe?: 0 | 1,
|
||||
}, MapResult>,
|
||||
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
||||
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
||||
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
||||
},
|
||||
InheritAction: {
|
||||
BuyHiddenBuff: PUT as APICallT<{
|
||||
type: inheritBuffType,
|
||||
level: number
|
||||
}>,
|
||||
BuyRandomUnique: PUT as APICallT<undefined>,
|
||||
BuySpecificUnique: PUT as APICallT<{
|
||||
item: string,
|
||||
amount: number,
|
||||
}>,
|
||||
ResetSpecialWar: PUT as APICallT<undefined>,
|
||||
ResetTurnTime: PUT as APICallT<undefined>,
|
||||
SetNextSpecialWar: PUT as APICallT<{
|
||||
type: string,
|
||||
}>,
|
||||
},
|
||||
Misc: {
|
||||
UploadImage: POST as APICallT<{
|
||||
imageData: string,
|
||||
}, UploadImageResponse>
|
||||
},
|
||||
NationCommand: {
|
||||
GetReservedCommand: GET as APICallT<undefined, ChiefResponse>,
|
||||
PushCommand: PUT as APICallT<{
|
||||
amount: number
|
||||
}>,
|
||||
RepeatCommand: PUT as APICallT<{
|
||||
amount: number
|
||||
}>,
|
||||
ReserveCommand: PUT as APICallT<{
|
||||
turnList: number[],
|
||||
action: string,
|
||||
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}>,
|
||||
}
|
||||
Auction: {
|
||||
BidBuyRiceAuction: PUT as APICallT<{
|
||||
auctionID: number;
|
||||
amount: number;
|
||||
}>,
|
||||
BidSellRiceAuction: PUT as APICallT<{
|
||||
auctionID: number;
|
||||
amount: number;
|
||||
}>,
|
||||
GetActiveResourceAuctionList: GET as APICallT<undefined, ActiveResourceAuctionList>,
|
||||
OpenBuyRiceAuction: POST as APICallT<
|
||||
{
|
||||
amount: number;
|
||||
closeTurnCnt: number;
|
||||
startBidAmount: number;
|
||||
finishBidAmount: number;
|
||||
},
|
||||
OpenAuctionResponse
|
||||
>,
|
||||
OpenSellRiceAuction: POST as APICallT<
|
||||
{
|
||||
amount: number;
|
||||
closeTurnCnt: number;
|
||||
startBidAmount: number;
|
||||
finishBidAmount: number;
|
||||
},
|
||||
OpenAuctionResponse
|
||||
>,
|
||||
|
||||
BidUniqueAuction: PUT as APICallT<{
|
||||
auctionID: number;
|
||||
amount: number;
|
||||
}>,
|
||||
GetUniqueItemAuctionDetail: GET as APICallT<{
|
||||
auctionID: number;
|
||||
}, UniqueItemAuctionDetail>,
|
||||
GetUniqueItemAuctionList: GET as APICallT<undefined, UniqueItemAuctionList>,
|
||||
OpenUniqueAuction: POST as APICallT<{
|
||||
itemID: string,
|
||||
amount: number,
|
||||
}, OpenAuctionResponse>,
|
||||
},
|
||||
Betting: {
|
||||
Bet: PUT as APICallT<{
|
||||
bettingID: number;
|
||||
bettingType: number[];
|
||||
amount: number;
|
||||
}>,
|
||||
GetBettingDetail: NumVar("betting_id", GET as APICallT<undefined, BettingDetailResponse>),
|
||||
GetBettingList: GET as APICallT<
|
||||
{
|
||||
req?: "bettingNation" | "tournament";
|
||||
},
|
||||
BettingListResponse
|
||||
>,
|
||||
},
|
||||
Command: {
|
||||
GetReservedCommand: GET as APICallT<undefined, ReservedCommandResponse>,
|
||||
PushCommand: PUT as APICallT<{
|
||||
amount: number;
|
||||
}>,
|
||||
RepeatCommand: PUT as APICallT<{
|
||||
amount: number;
|
||||
}>,
|
||||
ReserveCommand: PUT as APICallT<
|
||||
{
|
||||
turnList: number[];
|
||||
action: string;
|
||||
arg?: Args;
|
||||
},
|
||||
ReserveCommandResponse
|
||||
>,
|
||||
ReserveBulkCommand: PUT as APICallT<
|
||||
{
|
||||
turnList: number[];
|
||||
action: string;
|
||||
arg?: Args;
|
||||
}[],
|
||||
ReserveBulkCommandResponse
|
||||
>,
|
||||
},
|
||||
General: {
|
||||
Join: POST as APICallT<JoinArgs>,
|
||||
GetGeneralLog: GET as APICallT<
|
||||
{
|
||||
reqType: GeneralLogType;
|
||||
reqTo?: number;
|
||||
},
|
||||
GetGeneralLogResponse
|
||||
>,
|
||||
DropItem: PUT as APICallT<{
|
||||
itemType: ItemTypeKey;
|
||||
}>,
|
||||
},
|
||||
Global: {
|
||||
GeneralList: GET as APICallT<undefined, GeneralListResponse>,
|
||||
GeneralListWithToken: GET as APICallT<undefined, GeneralListResponse>,
|
||||
GetConst: GET as APICallT<undefined, GetConstResponse>,
|
||||
GetHistory: StrVar("serverID")(NumVar("year", NumVar("month", GET as APICallT<undefined, GetHistoryResponse>))),
|
||||
GetCurrentHistory: GET as APICallT<undefined, GetCurrentHistoryResponse>,
|
||||
GetMap: GET as APICallT<
|
||||
{
|
||||
neutralView?: 0 | 1;
|
||||
showMe?: 0 | 1;
|
||||
},
|
||||
MapResult
|
||||
>,
|
||||
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
||||
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
||||
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
||||
},
|
||||
InheritAction: {
|
||||
BuyHiddenBuff: PUT as APICallT<{
|
||||
type: inheritBuffType;
|
||||
level: number;
|
||||
}>,
|
||||
BuyRandomUnique: PUT as APICallT<undefined>,
|
||||
BuySpecificUnique: PUT as APICallT<{
|
||||
item: string;
|
||||
amount: number;
|
||||
}>,
|
||||
ResetSpecialWar: PUT as APICallT<undefined>,
|
||||
ResetTurnTime: PUT as APICallT<undefined>,
|
||||
SetNextSpecialWar: PUT as APICallT<{
|
||||
type: string;
|
||||
}>,
|
||||
},
|
||||
Misc: {
|
||||
UploadImage: POST as APICallT<
|
||||
{
|
||||
imageData: string;
|
||||
},
|
||||
UploadImageResponse
|
||||
>,
|
||||
},
|
||||
NationCommand: {
|
||||
GetReservedCommand: GET as APICallT<undefined, ChiefResponse>,
|
||||
PushCommand: PUT as APICallT<{
|
||||
amount: number;
|
||||
}>,
|
||||
RepeatCommand: PUT as APICallT<{
|
||||
amount: number;
|
||||
}>,
|
||||
ReserveCommand: PUT as APICallT<
|
||||
{
|
||||
turnList: number[];
|
||||
action: string;
|
||||
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;
|
||||
|
||||
export const SammoAPI = APIPathGen(apiRealPath, (path: string[], tail: APITail, pathParam) => {
|
||||
const method = extractHttpMethod(tail);
|
||||
return (args?: RawArgType, returnError?: boolean) => {
|
||||
if (returnError) {
|
||||
return callSammoAPI(method, path.join('/'), args, pathParam, true);
|
||||
}
|
||||
return callSammoAPI(method, path.join('/'), args, pathParam);
|
||||
};
|
||||
});
|
||||
const method = extractHttpMethod(tail);
|
||||
return (args?: RawArgType, returnError?: boolean) => {
|
||||
if (returnError) {
|
||||
return callSammoAPI(method, path.join("/"), args, pathParam, true);
|
||||
}
|
||||
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