feat,wip: 유니크 입찰 기본 구현
This commit is contained in:
@@ -4,10 +4,12 @@ namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionUniqueItem;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\Validator;
|
||||
|
||||
class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
@@ -16,14 +18,14 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
{
|
||||
$v = new Validator($this->args);
|
||||
$v->rule('required', [
|
||||
'auction_id',
|
||||
'auctionID',
|
||||
])
|
||||
->rule('integer', 'auction_id');
|
||||
->rule('integer', 'auctionID');
|
||||
|
||||
if (!$v->validate()) {
|
||||
return $v->errorStr();
|
||||
}
|
||||
$this->args['auction_id'] = (int)$this->args['auction_id'];
|
||||
$this->args['auctionID'] = (int)$this->args['auctionID'];
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -37,11 +39,11 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
$db = DB::db();
|
||||
|
||||
$generalID = $session->generalID;
|
||||
$auctionID = $this->args['auction_id'];
|
||||
$auctionID = $this->args['auctionID'];
|
||||
|
||||
$rawAuction = $db->queryFirstRow(
|
||||
'SELECT * FROM `ng_auction` WHERE `type` = %s AND `auction_id` = %s',
|
||||
AuctionType::UniqueItem,
|
||||
'SELECT * FROM `ng_auction` WHERE `type` = %s AND `id` = %i',
|
||||
AuctionType::UniqueItem->value,
|
||||
$auctionID
|
||||
);
|
||||
|
||||
@@ -63,10 +65,12 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
'generalName' => $bid->aux->generalName,
|
||||
'amount' => $bid->amount,
|
||||
'isCallerHighestBidder' => $bid->generalID === $generalID,
|
||||
'date' => $bid->date,
|
||||
'date' => TimeUtil::format($bid->date, false),
|
||||
];
|
||||
}
|
||||
|
||||
$obfuscatedName = AuctionUniqueItem::genObfuscatedName($generalID);
|
||||
|
||||
return [
|
||||
'result' => true,
|
||||
'auction' => [
|
||||
@@ -80,6 +84,7 @@ class GetUniqueItemAuctionDetail extends \sammo\BaseAPI
|
||||
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||
],
|
||||
'bidList' => $responseBid,
|
||||
'obfuscatedName' => $obfuscatedName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,12 @@ namespace sammo\API\Auction;
|
||||
|
||||
use sammo\Session;
|
||||
use DateTimeInterface;
|
||||
use sammo\AuctionUniqueItem;
|
||||
use sammo\DB;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\Enums\AuctionType;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\Util;
|
||||
|
||||
class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||
@@ -56,6 +58,8 @@ class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||
$rawHighestBids
|
||||
);
|
||||
|
||||
$obfuscatedName = AuctionUniqueItem::genObfuscatedName($generalID);
|
||||
|
||||
$response = [];
|
||||
foreach ($auctions as $auction) {
|
||||
$auctionID = $auction->id;
|
||||
@@ -71,8 +75,9 @@ class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||
'target' => $auction->target,
|
||||
'isCallerHost' => $auction->hostGeneralID === $generalID,
|
||||
'hostName' => $auction->detail->hostName,
|
||||
'closeDate' => TimeUtil::format($auction->closeDate, false),
|
||||
'remainCloseDateExtensionCnt' => $auction->detail->remainCloseDateExtensionCnt,
|
||||
'availableLatestBidCloseDate' => $auction->detail->availableLatestBidCloseDate,
|
||||
'availableLatestBidCloseDate' => TimeUtil::format($auction->detail->availableLatestBidCloseDate, false),
|
||||
'highestBid' => [
|
||||
'generalName' => $highestBid->aux->generalName,
|
||||
'amount' => $highestBid->amount,
|
||||
@@ -85,6 +90,7 @@ class GetUniqueItemAuctionList extends \sammo\BaseAPI
|
||||
return [
|
||||
'result' => true,
|
||||
'list' => $response,
|
||||
'obfuscatedName' => $obfuscatedName,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
+34
-2
@@ -31,6 +31,37 @@ abstract class Auction
|
||||
|
||||
protected AuctionBidItem|null|false $_highestBid = false;
|
||||
|
||||
static public function genObfuscatedName(int $id): string
|
||||
{
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
$namePool = $gameStor->getValue('obfuscatedNamePool');
|
||||
if ($namePool === null) {
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
)));
|
||||
$namePool = [];
|
||||
foreach (GameConst::$randGenFirstName as $ch0) {
|
||||
foreach (GameConst::$randGenMiddleName as $ch1) {
|
||||
foreach (GameConst::$randGenLastName as $ch2) {
|
||||
$namePool[] = "{$ch0}{$ch1}{$ch2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
$namePool = $rng->shuffle($namePool);
|
||||
$gameStor->setValue('obfuscatedNamePool', $namePool);
|
||||
}
|
||||
|
||||
|
||||
$dupIdx = intdiv($id, count($namePool));
|
||||
$subIdx = $id % count($namePool);
|
||||
if ($dupIdx == 0) {
|
||||
return $namePool[$subIdx];
|
||||
}
|
||||
return "{$namePool[$subIdx]}{$dupIdx}";
|
||||
}
|
||||
|
||||
static protected function openAuction(AuctionInfo $info, General $general): int|string
|
||||
{
|
||||
$db = DB::db();
|
||||
@@ -238,6 +269,7 @@ abstract class Auction
|
||||
return '유산포인트가 부족합니다.';
|
||||
}
|
||||
|
||||
$obfuscatedName = static::genObfuscatedName($general->getID());
|
||||
//여기서부터 입찰 성공
|
||||
|
||||
$newBid = new AuctionBidItem(
|
||||
@@ -249,7 +281,7 @@ abstract class Auction
|
||||
$now,
|
||||
new AuctionBidItemData(
|
||||
$general->getVar('owner_name'),
|
||||
$general->getName(),
|
||||
$obfuscatedName,
|
||||
$tryExtendCloseDate,
|
||||
)
|
||||
);
|
||||
@@ -275,7 +307,7 @@ abstract class Auction
|
||||
$general->increaseRankVar(RankColumn::inherit_point_spent_dynamic, $morePoint);
|
||||
|
||||
if ($highestBid !== null && $myPrevBid === null) {
|
||||
$this->refundBid($highestBid, "{$auctionInfo->id}번 $auctionInfo->detail->title}에 상회입찰자가 나타났습니다.");
|
||||
$this->refundBid($highestBid, "{$auctionInfo->id}번 {$auctionInfo->detail->title}에 상회입찰자가 나타났습니다.");
|
||||
}
|
||||
$general->applyDB($db);
|
||||
return null;
|
||||
|
||||
@@ -17,37 +17,6 @@ class AuctionUniqueItem extends Auction
|
||||
|
||||
static AuctionType $auctionType = AuctionType::UniqueItem;
|
||||
|
||||
static public function genObfuscatedName(int $id): string
|
||||
{
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
$namePool = $gameStor->getValue('obfuscatedNamePool');
|
||||
if ($namePool === null) {
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
)));
|
||||
$namePool = [];
|
||||
foreach (GameConst::$randGenFirstName as $ch0) {
|
||||
foreach (GameConst::$randGenMiddleName as $ch1) {
|
||||
foreach (GameConst::$randGenLastName as $ch2) {
|
||||
$namePool[] = "{$ch0}{$ch1}{$ch2}";
|
||||
}
|
||||
}
|
||||
}
|
||||
$namePool = $rng->shuffle($namePool);
|
||||
$gameStor->setValue('obfuscatedNamePool', $namePool);
|
||||
}
|
||||
|
||||
|
||||
$dupIdx = intdiv($id, count($namePool));
|
||||
$subIdx = $id % count($namePool);
|
||||
if ($dupIdx == 0) {
|
||||
return $namePool[$subIdx];
|
||||
}
|
||||
return "{$namePool[$subIdx]}{$dupIdx}";
|
||||
}
|
||||
|
||||
static public function openItemAuction(BaseItem $item, General $general, int $startAmount): self|string
|
||||
{
|
||||
if ($startAmount < GameConst::$inheritItemUniqueMinPoint) {
|
||||
|
||||
Reference in New Issue
Block a user