merge(compare): 국가 사령턴 수명주기 계측을 반영
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user