feat: replace game schedules with logical ticks
This commit is contained in:
@@ -11,7 +11,8 @@ use sammo\Session;
|
||||
use sammo\General;
|
||||
use sammo\JosaUtil;
|
||||
use sammo\KVStorage;
|
||||
use sammo\TimeUtil;
|
||||
use sammo\GameClock;
|
||||
use sammo\Util;
|
||||
|
||||
use function sammo\addTurn;
|
||||
use function sammo\increaseRefresh;
|
||||
@@ -37,6 +38,8 @@ class DieOnPrestart extends \sammo\BaseAPI
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->cacheValues(['turnterm', 'opentime', 'turntime', 'year', 'month']);
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
$nowTick = $clock->nowTick();
|
||||
|
||||
$general = $db->queryFirstRow('SELECT no,name,nation,owner_name,npc FROM general WHERE owner=%i AND npc = 0', $userID);
|
||||
if (!$general) {
|
||||
@@ -67,9 +70,9 @@ class DieOnPrestart extends \sammo\BaseAPI
|
||||
}
|
||||
|
||||
$targetTime = $generalObj->getAuxVar('prestart_delete_after');
|
||||
if (!is_string($targetTime) || $targetTime === '') {
|
||||
if (!is_int($targetTime)) {
|
||||
$targetTime = addTurn(
|
||||
$lastRefresh ?: TimeUtil::now(),
|
||||
$lastRefresh === null ? $nowTick : Util::toInt($lastRefresh),
|
||||
$gameStor->turnterm,
|
||||
GameConst::$minTurnDieOnPrestart
|
||||
);
|
||||
@@ -78,8 +81,8 @@ class DieOnPrestart extends \sammo\BaseAPI
|
||||
}
|
||||
|
||||
//서버 가오픈시 할 수 있는 행동
|
||||
if ($targetTime > TimeUtil::now()) {
|
||||
$targetTimeShort = substr($targetTime, 0, 19);
|
||||
if ($targetTime > $nowTick) {
|
||||
$targetTimeShort = $clock->formatTick($targetTime);
|
||||
return "아직 삭제할 수 없습니다. {$targetTimeShort} 부터 가능합니다.";
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use sammo\Enums\GeneralColumn;
|
||||
use sammo\Enums\GeneralQueryMode;
|
||||
use sammo\Enums\RankColumn;
|
||||
use sammo\GameConst;
|
||||
use sammo\GameClock;
|
||||
use sammo\General;
|
||||
use sammo\KVStorage;
|
||||
use sammo\LastTurn;
|
||||
@@ -105,6 +106,7 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
$db = DB::db();
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
$gameStor->cacheValues(['isunited', 'opentime', 'refresh']);
|
||||
|
||||
$lastHistoryID = $this->args['lastWorldHistoryID'];
|
||||
@@ -158,6 +160,7 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
private function generateGlobalInfo(MeekroDB $db): array
|
||||
{
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
|
||||
[
|
||||
$scenarioText, $extendedGeneral, $isFiction, $npcMode,
|
||||
@@ -210,7 +213,8 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
'month' => $month,
|
||||
'autorunUser' => $autorunUser,
|
||||
'turnterm' => $turnterm,
|
||||
'lastExecuted' => $lastExecuted,
|
||||
'lastExecutedTick' => $lastExecuted,
|
||||
'lastExecuted' => $clock->formatTick(Util::toInt($lastExecuted), true),
|
||||
'lastVoteID' => $lastVoteID,
|
||||
'develCost' => $develCost,
|
||||
'noticeMsg' => $noticeMsg,
|
||||
@@ -224,7 +228,8 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
'isLocked' => $isLocked,
|
||||
'tournamentType' => $tournamentType,
|
||||
'tournamentState' => $tournamentState,
|
||||
'tournamentTime' => $tournamentTime,
|
||||
'tournamentTimeTick' => $tournamentTime,
|
||||
'tournamentTime' => $tournamentTime === null ? null : $clock->formatTick(Util::toInt($tournamentTime)),
|
||||
'genCount' => $globalGenCount,
|
||||
'generalCntLimit' => $generalCntLimit,
|
||||
'serverCnt' => $serverCnt,
|
||||
@@ -361,6 +366,7 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
|
||||
public function generateGeneralInfo(MeekroDB $db, General $general, array $rawNation): array
|
||||
{
|
||||
$clock = GameClock::fromStorage(KVStorage::getStorage($db, 'game_env'));
|
||||
|
||||
$permission = checkSecretPermission($general->getRaw());
|
||||
|
||||
@@ -425,8 +431,12 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
'crew' => $general->getVar(GeneralColumn::crew), // number;
|
||||
'train' => $general->getVar(GeneralColumn::train), // number;
|
||||
'atmos' => $general->getVar(GeneralColumn::atmos), // number;
|
||||
'turntime' => $general->getVar(GeneralColumn::turntime), // string;
|
||||
'recent_war' => $general->getVar(GeneralColumn::recent_war), // string;
|
||||
'turntimeTick' => $general->getTurnTick(), // number;
|
||||
'turntime' => $general->getTurnTime(), // string;
|
||||
'recent_war_tick' => $general->getVar(GeneralColumn::recent_war), // number|null;
|
||||
'recent_war' => $general->getVar(GeneralColumn::recent_war) === null
|
||||
? null
|
||||
: $clock->formatTick(Util::toInt($general->getVar(GeneralColumn::recent_war)), true), // string|null;
|
||||
'horse' => $general->getVar(GeneralColumn::horse), // GameObjClassKey;
|
||||
'weapon' => $general->getVar(GeneralColumn::weapon), // GameObjClassKey;
|
||||
'book' => $general->getVar(GeneralColumn::book), // GameObjClassKey;
|
||||
@@ -544,7 +554,7 @@ class GetFrontInfo extends \sammo\BaseAPI
|
||||
'result' => false,
|
||||
'reason' => '접속 제한중입니다.',
|
||||
'recovery' => APIRecoveryType::GameQuota,
|
||||
'recovery_arg' => $general->getVar('turntime'),
|
||||
'recovery_arg' => $general->getTurnTime(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use sammo\Enums\APIRecoveryType;
|
||||
use sammo\Enums\GeneralAccessLogColumn;
|
||||
use sammo\Enums\RankColumn;
|
||||
use sammo\GameConst;
|
||||
use sammo\GameClock;
|
||||
use sammo\GameUnitConst;
|
||||
use sammo\General;
|
||||
use sammo\InheritancePointManager;
|
||||
@@ -165,6 +166,7 @@ class Join extends \sammo\BaseAPI
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->cacheValues(['year', 'month', 'maxgeneral', 'scenario', 'show_img_level', 'block_general_create', 'turnterm', 'turntime', 'genius', 'npcmode']);
|
||||
$clock = GameClock::fromStorage($gameStor);
|
||||
########## 동일 정보 존재여부 확인. ##########
|
||||
|
||||
$block_general_create = $gameStor->getValue('block_general_create');
|
||||
@@ -222,7 +224,7 @@ class Join extends \sammo\BaseAPI
|
||||
|
||||
$userLogger = new UserLogger($userID, $admin['year'], $admin['month'], false);
|
||||
|
||||
$now = TimeUtil::now(false);
|
||||
$now = $clock->nowTick();
|
||||
$rng = new RandUtil(new LiteHashDRBG(Util::simpleSerialize(
|
||||
UniqueConst::$hiddenSeed,
|
||||
'MakeGeneral',
|
||||
@@ -360,17 +362,14 @@ class Join extends \sammo\BaseAPI
|
||||
|
||||
$userLogger->push(sprintf("턴 시간 %02d:%02d 로 지정", intdiv($inheritTurntime, 60), $inheritTurntime % 60), "inheritPoint");
|
||||
|
||||
$inheritTurntime += $rng->nextRangeInt(0, 999999) / 1000000;
|
||||
|
||||
$turntime = new \DateTimeImmutable(cutTurn($admin['turntime'], $admin['turnterm']));
|
||||
$turntime = $turntime->add(TimeUtil::secondsToDateInterval($inheritTurntime));
|
||||
$turntime = TimeUtil::format($turntime, true);
|
||||
$inheritTurnMicrosecond = $rng->nextRangeInt(0, 999999);
|
||||
$turntime = cutTurn(Util::toInt($admin['turntime']), $admin['turnterm'])
|
||||
+ $clock->ticksFromSeconds($inheritTurntime)
|
||||
+ intdiv($inheritTurnMicrosecond * $clock->ticksPerSecond(), 1_000_000);
|
||||
} else {
|
||||
$turntime = getRandTurn($rng, $admin['turnterm'], new \DateTimeImmutable($admin['turntime']));
|
||||
$turntime = getRandTurn($rng, $admin['turnterm'], Util::toInt($admin['turntime']));
|
||||
}
|
||||
|
||||
|
||||
$now = TimeUtil::now(true);
|
||||
if ($now >= $turntime) {
|
||||
$turntime = addTurn($turntime, $admin['turnterm']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user