107 lines
3.1 KiB
PHP
107 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace sammo;
|
|
|
|
use sammo\Enums\AuctionType;
|
|
|
|
function registerAuction(RandUtil $rng)
|
|
{
|
|
$db = DB::db();
|
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
|
|
$admin = $gameStor->getValues(['startyear', 'year', 'month', 'turnterm']);
|
|
|
|
$unit = 60 * $admin['turnterm'];
|
|
|
|
// 장수들 평금,평쌀
|
|
$general = $db->queryFirstRow('SELECT avg(gold) as gold, avg(rice) as rice,max(gold) as maxgold from general where npc<2');
|
|
|
|
if ($general['gold'] < 1000) {
|
|
$general['gold'] = 1000;
|
|
}
|
|
if ($general['gold'] > 20000) {
|
|
$general['gold'] = 20000;
|
|
}
|
|
if ($general['rice'] < 1000) {
|
|
$general['rice'] = 1000;
|
|
}
|
|
if ($general['rice'] > 20000) {
|
|
$general['rice'] = 20000;
|
|
}
|
|
|
|
$count = $db->queryFirstField('SELECT count(*) FROM auction WHERE type=0 AND no1=0');
|
|
$count += 5;
|
|
|
|
$dummyGeneral = AuctionBasicResource::genDummy();
|
|
|
|
// 판매건 등록
|
|
if ($rng->nextBool(1 / $count)) {
|
|
//평균 쌀의 5% ~ 25%
|
|
$mul = $rng->nextRangeInt(1, 5);
|
|
$amount = $general['rice'] / 20 * $mul;
|
|
$cost = $general['gold'] / 20 * 0.9 * $mul;
|
|
$topv = $amount * 2;
|
|
$cost = Util::valueFit($cost, $amount * 0.8, $amount * 1.2);
|
|
|
|
$amount = Util::round($amount, -1);
|
|
$cost = Util::round($cost, -1);
|
|
$topv = Util::round($topv, -1);
|
|
|
|
$term = $rng->nextRangeInt(3, 12);
|
|
AuctionBuyRice::openResourceAuction($dummyGeneral, $amount, $term, $cost, $topv);
|
|
}
|
|
|
|
$count = $db->queryFirstField('SELECT count(*) FROM auction WHERE type=1 AND no1=0');
|
|
$count += 5;
|
|
// 구매건 등록
|
|
if ($rng->nextBool(1 / $count)) {
|
|
//평균 쌀의 5% ~ 25%
|
|
$mul = $rng->nextRangeInt(1, 5);
|
|
$amount = $general['rice'] / 20 * $mul;
|
|
$cost = $general['gold'] / 20 * 1.1 * $mul;
|
|
$topv = $amount * 0.5;
|
|
$cost = Util::valueFit($cost, $amount * 0.8, $amount * 1.2);
|
|
|
|
$amount = Util::round($amount, -1);
|
|
$cost = Util::round($cost, -1);
|
|
$topv = Util::round($topv, -1);
|
|
|
|
$term = $rng->nextRangeInt(3, 12);
|
|
AuctionSellRice::openResourceAuction($dummyGeneral, $amount, $term, $cost, $topv);
|
|
}
|
|
}
|
|
|
|
function processAuction()
|
|
{
|
|
$db = DB::db();
|
|
$gameStor = KVStorage::getStorage($db, 'game_env');
|
|
|
|
$now = TimeUtil::now();
|
|
[$year, $month] = $gameStor->getValuesAsArray(['year', 'month']);
|
|
|
|
$admin = $gameStor->getValues(['year', 'month']);
|
|
|
|
|
|
$auctionList = $db->queryFirstColumn(
|
|
'SELECT id, `type` FROM ng_auction WHERE `type` IN %ls AND `close_date` <= %s',
|
|
[AuctionType::BuyRice->value, AuctionType::SellRice->value],
|
|
$now
|
|
);
|
|
|
|
if(!$auctionList){
|
|
return;
|
|
}
|
|
|
|
$dummyGeneral = AuctionBasicResource::genDummy();
|
|
foreach($auctionList as [$auctionID, $rawAuctionType]) {
|
|
$auctionType = AuctionType::from($rawAuctionType);
|
|
if($auctionType === AuctionType::BuyRice){
|
|
$auction = new AuctionBuyRice($auctionID, $dummyGeneral);
|
|
}
|
|
else{
|
|
$auction = new AuctionSellRice($auctionID, $dummyGeneral);
|
|
}
|
|
$auction->tryFinish();
|
|
}
|
|
}
|