feat: StaticEventHandler 처리기 추가

- 커맨드 종료 시점에 호출
  - pre, post 각각이 필요한지는 논의 필요
  - 일단 용도에 따라 pre, post 둘중에 하나만 처리
- eventType으로는 full qualified class name 사용
  - 꼭 그럴필요는 없지만, 커맨드에 한해서는 이렇게
This commit is contained in:
2024-09-18 14:54:11 +00:00
parent 04a7a34fcc
commit 477b77b59f
79 changed files with 227 additions and 77 deletions
@@ -12,17 +12,13 @@ use sammo\JosaUtil;
class event_부대발령즉시집합 extends \sammo\BaseStaticEvent
{
function run(General $general, array $env, array $params): bool | string
function run(GeneralLite|General $general, null|GeneralLite|General $destGeneral, array $env, array $params): bool | string
{
$destGeneralID = $params['destGeneralID'] ?? null;
if ($destGeneralID === null) {
return "destGeneralID is null";
}
if (!is_int($destGeneralID)) {
return "destGeneralID is not int";
if($destGeneral === null){
return "destGeneral is null";
}
$destCityID = $params['city'] ?? null;
$destCityID = $params['destCityID'] ?? null;
if ($destCityID === null) {
return "destCityID is null";
}
@@ -30,21 +26,11 @@ class event_부대발령즉시집합 extends \sammo\BaseStaticEvent
return "destCityID is not int";
}
$destGeneral = GeneralLite::createObjFromDB($destGeneralID, ['nation', 'city', 'troop'], GeneralLiteQueryMode::Core);
if ($destGeneral === null) {
return "destGeneral is null";
}
if($destGeneral->getID() !== $destGeneral->getVar('troop')){
//부대장 발령이 아니므로 무시
return true;
}
if($destGeneral->getCityID() === $destCityID){
//이미 제자리이므로 무시
return true;
}
if($destGeneral->getNationID() !== $general->getNationID()){
return "destGeneral is not same nation";
}
@@ -56,8 +42,7 @@ class event_부대발령즉시집합 extends \sammo\BaseStaticEvent
$troopID = $destGeneral->getID();
$troopName = $db->queryFirstField('SELECT name FROM troop WHERE troop_leader = %i', $troopID);
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city!=%i AND troop=%i AND no!=%i', $general->getNationID(), $destCityID, $troopID, $general->getID());
$generalList = $db->queryFirstColumn('SELECT no FROM general WHERE nation=%i AND city!=%i AND troop=%i AND no!=%i', $destGeneral->getNationID(), $destCityID, $troopID, $destGeneral->getID());
if($generalList){
$db->update('general', [
'city'=>$destCityID
@@ -69,9 +54,6 @@ class event_부대발령즉시집합 extends \sammo\BaseStaticEvent
$targetLogger->flush();
}
$general->setVar('city', $destGeneral->getCityID());
$general->applyDB(DB::db());
return true;
}
}
@@ -9,7 +9,7 @@ use sammo\GeneralLite;
class event_부대탑승즉시이동 extends \sammo\BaseStaticEvent
{
function run(General $general, array $env, array $params): bool | string
function run(GeneralLite|General $general, null|GeneralLite|General $destGeneral, array $env, array $params): bool | string
{
$troopID = $params['troopID'] ?? null;