refac,feat: Global/ExecuteEngine

- 턴 실행
- 기존 proc.php와 유사
- 변경된 턴 있음 알림
This commit is contained in:
2022-04-27 02:43:04 +09:00
parent 8d4ce7c23c
commit 0de4476096
3 changed files with 43 additions and 10 deletions
+29
View File
@@ -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,
];
}
}
+8 -5
View File
@@ -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;
} }
} }
+1
View File
@@ -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<{