refac,feat: Global/ExecuteEngine
- 턴 실행 - 기존 proc.php와 유사 - 변경된 턴 있음 알림
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace sammo\API\Global;
|
||||||
|
|
||||||
|
use sammo\Session;
|
||||||
|
use DateTimeInterface;
|
||||||
|
use sammo\TurnExecutionHelper;
|
||||||
|
|
||||||
|
class ExecuteEngine extends \sammo\BaseAPI
|
||||||
|
{
|
||||||
|
public function validateArgs(): ?string
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequiredSessionMode(): int
|
||||||
|
{
|
||||||
|
return static::NO_SESSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function launch(Session $session, ?DateTimeInterface $modifiedSince, ?string $reqEtag)
|
||||||
|
{
|
||||||
|
$updated = TurnExecutionHelper::executeAllCommand();
|
||||||
|
return [
|
||||||
|
'result' => true,
|
||||||
|
'updated' => $updated,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -237,7 +237,7 @@ class TurnExecutionHelper
|
|||||||
$general = General::createGeneralObjFromDB($rawGeneral['no']);
|
$general = General::createGeneralObjFromDB($rawGeneral['no']);
|
||||||
$turnObj = new static($general);
|
$turnObj = new static($general);
|
||||||
|
|
||||||
$env = $gameStor->getAll();//NOTE: 매번 재 갱신하도록 유지할 것.
|
$env = $gameStor->getAll(); //NOTE: 매번 재 갱신하도록 유지할 것.
|
||||||
[$startYear, $year, $month, $turnterm] = $gameStor->getValuesAsArray(['startyear', 'year', 'month', 'turnterm']);
|
[$startYear, $year, $month, $turnterm] = $gameStor->getValuesAsArray(['startyear', 'year', 'month', 'turnterm']);
|
||||||
|
|
||||||
$hasNationTurn = false;
|
$hasNationTurn = false;
|
||||||
@@ -264,11 +264,11 @@ class TurnExecutionHelper
|
|||||||
|
|
||||||
$turnObj->preprocessCommand($env);
|
$turnObj->preprocessCommand($env);
|
||||||
|
|
||||||
if ($general->getNPCType() >= 2){
|
if ($general->getNPCType() >= 2) {
|
||||||
$ai = new GeneralAI($turnObj->getGeneral());
|
$ai = new GeneralAI($turnObj->getGeneral());
|
||||||
} else {
|
} else {
|
||||||
$limitYearMonth = $general->getAuxVar('autorun_limit')??Util::joinYearMonth($year-2, $month);
|
$limitYearMonth = $general->getAuxVar('autorun_limit') ?? Util::joinYearMonth($year - 2, $month);
|
||||||
if(Util::joinYearMonth($year, $month) < $limitYearMonth){
|
if (Util::joinYearMonth($year, $month) < $limitYearMonth) {
|
||||||
$ai = new GeneralAI($turnObj->getGeneral());
|
$ai = new GeneralAI($turnObj->getGeneral());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -315,7 +315,7 @@ class TurnExecutionHelper
|
|||||||
$currentTurn = $general->getTurnTime();
|
$currentTurn = $general->getTurnTime();
|
||||||
$general->increaseVarWithLimit('myset', 3, null, 9);
|
$general->increaseVarWithLimit('myset', 3, null, 9);
|
||||||
|
|
||||||
if(($autorun_user['limit_minutes']??false) && $general->getNPCType() < 2 && $hasReservedTurn){
|
if (($autorun_user['limit_minutes'] ?? false) && $general->getNPCType() < 2 && $hasReservedTurn) {
|
||||||
$autorun_limit = Util::joinYearMonth($year, $month);
|
$autorun_limit = Util::joinYearMonth($year, $month);
|
||||||
$autorun_limit += intdiv($autorun_user['limit_minutes'], $turnterm);
|
$autorun_limit += intdiv($autorun_user['limit_minutes'], $turnterm);
|
||||||
|
|
||||||
@@ -329,7 +329,7 @@ class TurnExecutionHelper
|
|||||||
return [false, $currentTurn];
|
return [false, $currentTurn];
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function executeAllCommand()
|
static public function executeAllCommand(): bool
|
||||||
{
|
{
|
||||||
//if(!timeover()) { return; }
|
//if(!timeover()) { return; }
|
||||||
|
|
||||||
@@ -339,16 +339,16 @@ class TurnExecutionHelper
|
|||||||
|
|
||||||
if (TimeUtil::now(true) < $gameStor->turntime) {
|
if (TimeUtil::now(true) < $gameStor->turntime) {
|
||||||
//턴 시각 이전이면 아무것도 하지 않음
|
//턴 시각 이전이면 아무것도 하지 않음
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tryLock()) {
|
if (!tryLock()) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gameStor->isunited == 2 || $gameStor->isunited == 3) {
|
if ($gameStor->isunited == 2 || $gameStor->isunited == 3) {
|
||||||
//천통시에는 동결
|
//천통시에는 동결
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$gameStor->cacheAll();
|
$gameStor->cacheAll();
|
||||||
@@ -361,6 +361,7 @@ class TurnExecutionHelper
|
|||||||
|
|
||||||
$date = TimeUtil::now(true);
|
$date = TimeUtil::now(true);
|
||||||
// 최종 처리 월턴의 다음 월턴시간 구함
|
// 최종 처리 월턴의 다음 월턴시간 구함
|
||||||
|
$lastExecuted = $gameStor->turntime;
|
||||||
$prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm);
|
$prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm);
|
||||||
$nextTurn = addTurn($prevTurn, $gameStor->turnterm);
|
$nextTurn = addTurn($prevTurn, $gameStor->turnterm);
|
||||||
|
|
||||||
@@ -392,7 +393,7 @@ class TurnExecutionHelper
|
|||||||
$gameStor->turntime = $currentTurn;
|
$gameStor->turntime = $currentTurn;
|
||||||
}
|
}
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return $currentTurn !== null && $lastExecuted !== $currentTurn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -482,5 +483,7 @@ class TurnExecutionHelper
|
|||||||
// 잡금 해제
|
// 잡금 해제
|
||||||
$gameStor->resetCache();
|
$gameStor->resetCache();
|
||||||
unlock();
|
unlock();
|
||||||
|
|
||||||
|
return $currentTurn !== null && $lastExecuted !== $currentTurn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ const apiRealPath = {
|
|||||||
}, MapResult>,
|
}, MapResult>,
|
||||||
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
GetCachedMap: GET as APICallT<undefined, CachedMapResult>,
|
||||||
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
GetDiplomacy: GET as APICallT<undefined, GetDiplomacyResponse>,
|
||||||
|
ExecuteEngine: POST as APICallT<undefined, ValidResponse & { updated: boolean }>,
|
||||||
},
|
},
|
||||||
InheritAction: {
|
InheritAction: {
|
||||||
BuyHiddenBuff: PUT as APICallT<{
|
BuyHiddenBuff: PUT as APICallT<{
|
||||||
|
|||||||
Reference in New Issue
Block a user