96 lines
2.5 KiB
PHP
96 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace sammo;
|
|
|
|
use DateTimeImmutable;
|
|
use sammo\DTO\AuctionInfo;
|
|
use sammo\Enums\InheritanceKey;
|
|
use sammo\Enums\ResourceType;
|
|
use sammo\RandUtil;
|
|
|
|
class AuctionUniqueItem extends Auction
|
|
{
|
|
|
|
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): ?string
|
|
{
|
|
if ($startAmount < GameConst::$inheritItemUniqueMinPoint) {
|
|
return '최소 경매 금액은 ' . GameConst::$inheritItemUniqueMinPoint . '입니다.';
|
|
}
|
|
|
|
if($general->getInheritancePoint(InheritanceKey::previous) < $startAmount){
|
|
return '경매를 시작할 포인트가 부족합니다.';
|
|
}
|
|
|
|
$auctionID = static::genNextAuctionID();
|
|
$now = new DateTimeImmutable();
|
|
|
|
$db = DB::db();
|
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
$turnTerm = $gameStor->getValue('turnterm');
|
|
|
|
$closeDate = $now->add(TimeUtil::secondsToDateInterval(24 * 60 * $turnTerm * 60));
|
|
|
|
$info = new AuctionInfo(
|
|
$auctionID,
|
|
static::genObfuscatedName($general->getID()),
|
|
$general->getID(),
|
|
$item->getRawClassName(),
|
|
"{$item->getName()} 경매",
|
|
false,
|
|
ResourceType::inheritancePoint,
|
|
$startAmount,
|
|
null,
|
|
$now,
|
|
$closeDate
|
|
);
|
|
|
|
$result = static::openAuction($info, $general);
|
|
if($result !== null){
|
|
return $result;
|
|
}
|
|
$auction = new static($auctionID, $general);
|
|
try{
|
|
$auction->bid($startAmount);
|
|
}
|
|
catch(\Exception $e){
|
|
//실패해선 안된다.
|
|
$msg = $e->getMessage();
|
|
$auction->closeAuction();
|
|
return "경매를 시작했지만, 첫 입찰에 실패했습니다: {$msg}";
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|