feat,wip: 유니크 경매 시작, 입찰 구현
- 누군가는 무작위로 유니크를 하나를 먹을 수 있도록 설계?
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace sammo;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Ds\Set;
|
||||
use sammo\DTO\AuctionBidItem;
|
||||
use sammo\DTO\AuctionInfo;
|
||||
use sammo\DTO\AuctionInfoDetail;
|
||||
@@ -59,10 +60,33 @@ class AuctionUniqueItem extends Auction
|
||||
return '구매할 수 있는 아이템입니다.';
|
||||
}
|
||||
|
||||
$itemKey = $item->getRawClassName();
|
||||
$db = DB::db();
|
||||
$auctionIDonProgress = $db->queryFirstField(
|
||||
'SELECT `id` FROM ng_auction WHERE `finished` = 0 AND `target` = %s AND `target` = %s',
|
||||
AuctionType::UniqueItem->value,
|
||||
$itemKey
|
||||
);
|
||||
if ($auctionIDonProgress !== null) {
|
||||
return '이미 경매가 진행중입니다.';
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$givenUnique = $gameStor->getValue('givenUnique') ?? [];
|
||||
$givenUniqueCnt = $givenUnique[$itemKey] ?? 0;
|
||||
$remainUniqueCnt = 0;
|
||||
foreach (GameConst::$allItems as $itemList) {
|
||||
if (!key_exists($itemKey, $itemList)) {
|
||||
continue;
|
||||
}
|
||||
$remainUniqueCnt += $itemList[$itemKey];
|
||||
}
|
||||
if ($remainUniqueCnt > 1 && $givenUniqueCnt >= $remainUniqueCnt - 1) {
|
||||
return '더이상 이 아이템을 경매로 가져갈 수 없습니다.';
|
||||
}
|
||||
|
||||
$now = new DateTimeImmutable();
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$turnTerm = $gameStor->getValue('turnterm');
|
||||
|
||||
$closeDate = $now->add(TimeUtil::secondsToDateInterval(
|
||||
@@ -76,7 +100,7 @@ class AuctionUniqueItem extends Auction
|
||||
null,
|
||||
AuctionType::UniqueItem,
|
||||
false,
|
||||
$item->getRawClassName(),
|
||||
$itemKey,
|
||||
$general->getID(),
|
||||
ResourceType::inheritancePoint,
|
||||
$now,
|
||||
@@ -113,6 +137,9 @@ class AuctionUniqueItem extends Auction
|
||||
{
|
||||
|
||||
$itemKey = $this->info->target;
|
||||
if ($itemKey === null) {
|
||||
throw new \Exception('아이템 키가 없습니다.');
|
||||
}
|
||||
$itemObj = buildItemClass($itemKey);
|
||||
$general = $bidder;
|
||||
$availableItemTypes = [];
|
||||
@@ -192,6 +219,11 @@ class AuctionUniqueItem extends Auction
|
||||
$logger->pushGlobalHistoryLog("<C><b>【보물발견】</b></><D><b>{$nationName}</b></>의 <Y>{$generalName}</>{$josaYi} <C>{$itemName}</>{$josaUl} 습득했습니다!");
|
||||
|
||||
$general->applyDB($db);
|
||||
|
||||
$givenUnique = $gameStor->getValue('givenUnique') ?? [];
|
||||
$givenUnique[$itemKey] = ($givenUnique[$itemKey] ?? 0) + 1;
|
||||
$gameStor->setValue('givenUnique', $givenUnique);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -263,7 +295,60 @@ class AuctionUniqueItem extends Auction
|
||||
|
||||
public function bid(int $amount, bool $tryExtendCloseDate = false): ?string
|
||||
{
|
||||
//TODO: 입찰 가능 제한확인(다른 경매 진행 등)
|
||||
|
||||
$db = DB::db();
|
||||
/** @var AuctionInfo[] */
|
||||
$openUniqueAuctions = array_map(fn ($raw) => AuctionInfo::fromArray($raw), $db->query(
|
||||
'SELECT * FROM `ng_auction` WHERE `finished` = 0 AND `type`= %s',
|
||||
AuctionType::UniqueItem->value
|
||||
) ?? []);
|
||||
|
||||
$db = DB::db();
|
||||
$rawHighestBids = Util::convertArrayToDict($db->queryFirstRow(
|
||||
'SELECT * FROM ng_auction_bid WHERE auction_id IN %i ORDER BY `amount` DESC LIMIT 1',
|
||||
$this->info->id
|
||||
) ?? [], 'auction_id');
|
||||
/** @var array<int,AuctionBidItem> */
|
||||
$highestBids = Util::mapWithKey(
|
||||
fn ($auctionID, $bid) => AuctionBidItem::fromArray($bid),
|
||||
$rawHighestBids
|
||||
);
|
||||
|
||||
$itemCode = $this->info->target;
|
||||
$bidItemTypes = new Set();
|
||||
foreach (GameConst::$allItems as $itemType => $itemList) {
|
||||
if (($itemList[$itemCode] ?? 0) <= 0) {
|
||||
continue;
|
||||
}
|
||||
$bidItemTypes->add($itemType);
|
||||
}
|
||||
|
||||
foreach ($openUniqueAuctions as $auction) {
|
||||
$auctionID = $auction->id;
|
||||
if (!isset($highestBids[$auctionID])) {
|
||||
continue;
|
||||
}
|
||||
if ($auctionID === $this->auctionID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$bid = $highestBids[$auctionID];
|
||||
if ($bid->generalID !== $this->general->getID()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$itemCodeComp = $auction->target;
|
||||
|
||||
foreach (GameConst::$allItems as $itemType => $itemList) {
|
||||
if (($itemList[$itemCodeComp] ?? 0) <= 0) {
|
||||
continue;
|
||||
}
|
||||
if ($bidItemTypes->contains($itemType)) {
|
||||
return '1순위 입찰자인 경매중에 같은 부위가 있습니다.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parent::bid($amount, $tryExtendCloseDate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user