diff --git a/hwe/compare/turn_command_trace.php b/hwe/compare/turn_command_trace.php index 4ceef57c..793a3edf 100644 --- a/hwe/compare/turn_command_trace.php +++ b/hwe/compare/turn_command_trace.php @@ -517,8 +517,10 @@ function comparisonRunTurnCommand(array $request): array throw new \RuntimeException('TURN_DIFFERENTIAL_ENABLED=1 is required'); } $kind = $request['kind'] ?? null; - if (!in_array($kind, ['general', 'nation', 'instantNation'], true)) { - throw new \InvalidArgumentException('kind must be general, nation, or instantNation'); + if (!in_array($kind, ['general', 'nation', 'instantNation', 'troopJoinStaticEvent'], true)) { + throw new \InvalidArgumentException( + 'kind must be general, nation, instantNation, or troopJoinStaticEvent', + ); } $actorGeneralId = $request['actorGeneralId'] ?? null; $action = $request['action'] ?? null; @@ -557,6 +559,62 @@ function comparisonRunTurnCommand(array $request): array $gameStorage = KVStorage::getStorage($db, 'game_env'); $gameStorage->resetCache(); $environment = $gameStorage->getAll(); + if ($kind === 'troopJoinStaticEvent') { + if ($action !== \sammo\API\Troop\JoinTroop::class) { + throw new \InvalidArgumentException('troopJoinStaticEvent requires the JoinTroop API action'); + } + $troopId = is_array($args) ? ($args['troopID'] ?? null) : null; + if (!is_int($troopId) || $troopId < 1) { + throw new \InvalidArgumentException('troopJoinStaticEvent requires a positive integer troopID'); + } + $general = GeneralLite::createObjFromDB( + $actorGeneralId, + ['troop'], + Enums\GeneralLiteQueryMode::Lite, + ); + if ($general === null) { + throw new \RuntimeException('장수 정보를 불러올 수 없습니다.'); + } + if ($general->getVar('troop') != 0) { + throw new \RuntimeException('이미 부대에 소속되어 있습니다.'); + } + $nationId = $general->getNationID(); + if ($nationId == 0) { + throw new \RuntimeException('국가에 소속되어 있지 않습니다.'); + } + $troopExists = $db->queryFirstField( + 'SELECT `troop_leader` FROM `troop` WHERE `troop_leader` = %i AND `nation` = %i', + $troopId, + $nationId, + ); + if (!$troopExists) { + throw new \RuntimeException('부대가 올바르지 않습니다.'); + } + + GameConst::$staticEventHandlers = [ + \sammo\API\Troop\JoinTroop::class => ['event_부대탑승즉시이동'], + ]; + $general->setVar('troop', $troopId); + StaticEventHandler::handleEvent($general, null, \sammo\API\Troop\JoinTroop::class, [], $args); + $general->applyDB($db); + $after = comparisonTurnStateSnapshot($snapshotRequest); + + return [ + 'schemaVersion' => 1, + 'engine' => 'ref', + 'execution' => [ + 'kind' => $kind, + 'actorGeneralId' => $actorGeneralId, + 'action' => $action, + 'args' => $args, + 'seedDomain' => 'none', + 'outcome' => ['completed' => true], + ], + 'before' => $before, + 'after' => $after, + 'rng' => [], + ]; + } $general = General::createObjFromDB($actorGeneralId); if ($kind === 'instantNation') { $command = buildNationCommandClass($action, $general, $environment, new LastTurn(), $args);