From 7c96d238cac19f931d36455f33841ab835dc6e78 Mon Sep 17 00:00:00 2001 From: hided62 Date: Sun, 16 Aug 2026 11:34:57 +0000 Subject: [PATCH] =?UTF-8?q?test(compare):=20=EA=B5=AD=EA=B0=80=20=EC=82=AC?= =?UTF-8?q?=EB=A0=B9=ED=84=B4=20=EC=88=98=EB=AA=85=EC=A3=BC=EA=B8=B0=20?= =?UTF-8?q?=EA=B3=84=EC=B8=A1=EC=9D=84=20=ED=99=95=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/compare/turn_command_trace.php | 113 +++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 15 deletions(-) diff --git a/hwe/compare/turn_command_trace.php b/hwe/compare/turn_command_trace.php index 6f7236ce..d7197fd0 100644 --- a/hwe/compare/turn_command_trace.php +++ b/hwe/compare/turn_command_trace.php @@ -162,7 +162,7 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void } } - foreach (['nations', 'cities', 'generals', 'troops', 'diplomacy'] as $collection) { + foreach (['nations', 'cities', 'generals', 'troops', 'diplomacy', 'generalTurns', 'nationTurns'] as $collection) { if (isset($setup[$collection]) && !is_array($setup[$collection])) { throw new \InvalidArgumentException("setup.{$collection} must be an array"); } @@ -541,6 +541,55 @@ function comparisonApplyTurnFixtureSetup(mixed $setup): void $data += ['state' => 3, 'term' => 0, 'dead' => 0]; $db->insertUpdate('diplomacy', $data, $data); } + + foreach ($setup['generalTurns'] ?? [] as $row) { + if ( + !is_array($row) + || !is_int($row['generalId'] ?? null) + || !is_int($row['turnIndex'] ?? null) + || !is_string($row['action'] ?? null) + || $row['generalId'] < 1 + || $row['turnIndex'] < 0 + || $row['turnIndex'] >= GameConst::$maxTurn + || $row['action'] === '' + ) { + throw new \InvalidArgumentException('setup.generalTurns entries are invalid'); + } + $data = [ + 'general_id' => $row['generalId'], + 'turn_idx' => $row['turnIndex'], + 'action' => $row['action'], + 'arg' => Json::encode($row['args'] ?? []), + 'brief' => $row['action'], + ]; + $db->insertUpdate('general_turn', $data, $data); + } + + foreach ($setup['nationTurns'] ?? [] as $row) { + if ( + !is_array($row) + || !is_int($row['nationId'] ?? null) + || !is_int($row['officerLevel'] ?? null) + || !is_int($row['turnIndex'] ?? null) + || !is_string($row['action'] ?? null) + || $row['nationId'] < 1 + || $row['officerLevel'] < 5 + || $row['turnIndex'] < 0 + || $row['turnIndex'] >= GameConst::$maxChiefTurn + || $row['action'] === '' + ) { + throw new \InvalidArgumentException('setup.nationTurns entries are invalid'); + } + $data = [ + 'nation_id' => $row['nationId'], + 'officer_level' => $row['officerLevel'], + 'turn_idx' => $row['turnIndex'], + 'action' => $row['action'], + 'arg' => Json::encode($row['args'] ?? []), + 'brief' => $row['action'], + ]; + $db->insertUpdate('nation_turn', $data, $data); + } } function comparisonRunTurnCommand(array $request): array @@ -567,23 +616,50 @@ function comparisonRunTurnCommand(array $request): array if (!is_bool($includeLifecycle)) { throw new \InvalidArgumentException('includeLifecycle must be a boolean'); } - if ($includeLifecycle && $kind !== 'general') { - throw new \InvalidArgumentException('includeLifecycle currently supports general commands only'); + if ($includeLifecycle && !in_array($kind, ['general', 'nation'], true)) { + throw new \InvalidArgumentException('includeLifecycle supports general and nation commands only'); } comparisonApplyTurnFixtureSetup($request['setup'] ?? null); if ($includeLifecycle) { - DB::db()->insertUpdate('general_turn', [ - 'general_id' => $actorGeneralId, - 'turn_idx' => 0, - 'action' => $action, - 'arg' => Json::encode($args), - 'brief' => $action, - ], [ - 'action' => $action, - 'arg' => Json::encode($args), - 'brief' => $action, - ]); + if ($kind === 'general') { + DB::db()->insertUpdate('general_turn', [ + 'general_id' => $actorGeneralId, + 'turn_idx' => 0, + 'action' => $action, + 'arg' => Json::encode($args), + 'brief' => $action, + ], [ + 'action' => $action, + 'arg' => Json::encode($args), + 'brief' => $action, + ]); + } else { + $actorOfficer = DB::db()->queryFirstRow( + 'SELECT nation, officer_level FROM general WHERE no = %i', + $actorGeneralId, + ); + if ($actorOfficer === null) { + throw new \RuntimeException('장수 정보를 불러올 수 없습니다.'); + } + $actorNationId = (int)$actorOfficer['nation']; + $actorOfficerLevel = (int)$actorOfficer['officer_level']; + if ($actorNationId < 1 || $actorOfficerLevel < 5) { + throw new \InvalidArgumentException('nation lifecycle requires a nation officer'); + } + DB::db()->insertUpdate('nation_turn', [ + 'nation_id' => $actorNationId, + 'officer_level' => $actorOfficerLevel, + 'turn_idx' => 0, + 'action' => $action, + 'arg' => Json::encode($args), + 'brief' => $action, + ], [ + 'action' => $action, + 'arg' => Json::encode($args), + 'brief' => $action, + ]); + } } $snapshotRequest = ['observe' => $request['observe'] ?? []]; $before = comparisonTurnStateSnapshot($snapshotRequest); @@ -721,7 +797,14 @@ function comparisonRunTurnCommand(array $request): array } if ($includeLifecycle) { - pullGeneralCommand($general->getID()); + if ($kind === 'general') { + pullGeneralCommand($general->getID()); + } else { + pullNationCommand( + $general->getNationID(), + (int)$general->getVar('officer_level'), + ); + } $general->increaseVarWithLimit( 'myset', GameConst::$incDefSettingChange,