merge: trace city changes and NPC troop leaders
This commit is contained in:
@@ -114,12 +114,19 @@ function comparisonMonthlyDetails(array $observe, int $worldHistoryAfterId): arr
|
|||||||
'term' => 'term',
|
'term' => 'term',
|
||||||
'dead' => 'dead',
|
'dead' => 'dead',
|
||||||
'population' => 'pop',
|
'population' => 'pop',
|
||||||
|
'populationMax' => 'pop_max',
|
||||||
'agriculture' => 'agri',
|
'agriculture' => 'agri',
|
||||||
|
'agricultureMax' => 'agri_max',
|
||||||
'commerce' => 'comm',
|
'commerce' => 'comm',
|
||||||
|
'commerceMax' => 'comm_max',
|
||||||
'security' => 'secu',
|
'security' => 'secu',
|
||||||
|
'securityMax' => 'secu_max',
|
||||||
'trust' => 'trust',
|
'trust' => 'trust',
|
||||||
|
'trade' => 'trade',
|
||||||
'defence' => 'def',
|
'defence' => 'def',
|
||||||
|
'defenceMax' => 'def_max',
|
||||||
'wall' => 'wall',
|
'wall' => 'wall',
|
||||||
|
'wallMax' => 'wall_max',
|
||||||
'conflict' => 'conflict',
|
'conflict' => 'conflict',
|
||||||
],
|
],
|
||||||
['conflict'],
|
['conflict'],
|
||||||
@@ -198,6 +205,8 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
'RaiseInvader',
|
'RaiseInvader',
|
||||||
'AutoDeleteInvader',
|
'AutoDeleteInvader',
|
||||||
'InvaderEnding',
|
'InvaderEnding',
|
||||||
|
'ChangeCity',
|
||||||
|
'ProvideNPCTroopLeader',
|
||||||
];
|
];
|
||||||
if (!in_array($actionName, $supportedActions, true)) {
|
if (!in_array($actionName, $supportedActions, true)) {
|
||||||
throw new \InvalidArgumentException('unsupported monthly action');
|
throw new \InvalidArgumentException('unsupported monthly action');
|
||||||
@@ -313,7 +322,7 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
throw new \InvalidArgumentException('setup.gameEnvironment must be an object');
|
throw new \InvalidArgumentException('setup.gameEnvironment must be an object');
|
||||||
}
|
}
|
||||||
$gameStorage = KVStorage::getStorage(DB::db(), 'game_env');
|
$gameStorage = KVStorage::getStorage(DB::db(), 'game_env');
|
||||||
foreach (['isunited', 'refreshLimit', 'block_change_scout'] as $key) {
|
foreach (['isunited', 'refreshLimit', 'block_change_scout', 'lastNPCTroopLeaderID'] as $key) {
|
||||||
if (array_key_exists($key, $gameEnvironmentPatch)) {
|
if (array_key_exists($key, $gameEnvironmentPatch)) {
|
||||||
$gameStorage->setValue($key, $gameEnvironmentPatch[$key]);
|
$gameStorage->setValue($key, $gameEnvironmentPatch[$key]);
|
||||||
}
|
}
|
||||||
@@ -370,7 +379,7 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
throw new \InvalidArgumentException('ProcessSemiAnnual requires resource');
|
throw new \InvalidArgumentException('ProcessSemiAnnual requires resource');
|
||||||
}
|
}
|
||||||
$action = new $actionClass($resource);
|
$action = new $actionClass($resource);
|
||||||
} elseif (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseInvader', 'AutoDeleteInvader'], true)) {
|
} elseif (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseInvader', 'AutoDeleteInvader', 'ChangeCity'], true)) {
|
||||||
$args = $request['args'] ?? [];
|
$args = $request['args'] ?? [];
|
||||||
if (!is_array($args)) {
|
if (!is_array($args)) {
|
||||||
throw new \InvalidArgumentException("{$actionName} args must be an array");
|
throw new \InvalidArgumentException("{$actionName} args must be an array");
|
||||||
@@ -381,6 +390,9 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
if ($actionName === 'RaiseInvader' && count($args) > 4) {
|
if ($actionName === 'RaiseInvader' && count($args) > 4) {
|
||||||
throw new \InvalidArgumentException('RaiseInvader args must have at most four entries');
|
throw new \InvalidArgumentException('RaiseInvader args must have at most four entries');
|
||||||
}
|
}
|
||||||
|
if ($actionName === 'ChangeCity' && count($args) !== 2) {
|
||||||
|
throw new \InvalidArgumentException('ChangeCity args must have exactly two entries');
|
||||||
|
}
|
||||||
$action = new $actionClass(...$args);
|
$action = new $actionClass(...$args);
|
||||||
} else {
|
} else {
|
||||||
$action = new $actionClass();
|
$action = new $actionClass();
|
||||||
@@ -405,7 +417,7 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
$actionEnvironment['killturn'] = $killturn;
|
$actionEnvironment['killturn'] = $killturn;
|
||||||
$actionEnvironment['turnterm'] = $turnterm;
|
$actionEnvironment['turnterm'] = $turnterm;
|
||||||
}
|
}
|
||||||
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseNPCNation', 'RaiseInvader'], true)) {
|
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseNPCNation', 'RaiseInvader', 'ProvideNPCTroopLeader'], true)) {
|
||||||
$turnterm = $environment['turnterm'] ?? null;
|
$turnterm = $environment['turnterm'] ?? null;
|
||||||
$turntime = $environment['turntime'] ?? null;
|
$turntime = $environment['turntime'] ?? null;
|
||||||
$showImgLevel = $environment['show_img_level'] ?? 3;
|
$showImgLevel = $environment['show_img_level'] ?? 3;
|
||||||
@@ -437,7 +449,7 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
$after = comparisonTurnStateSnapshot($snapshotRequest);
|
$after = comparisonTurnStateSnapshot($snapshotRequest);
|
||||||
$afterDetails = comparisonMonthlyDetails($snapshotRequest['observe'], $worldHistoryAfterId);
|
$afterDetails = comparisonMonthlyDetails($snapshotRequest['observe'], $worldHistoryAfterId);
|
||||||
$createdGenerals = [];
|
$createdGenerals = [];
|
||||||
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseNPCNation', 'RaiseInvader'], true)) {
|
if (in_array($actionName, ['CreateManyNPC', 'RegNPC', 'RegNeutralNPC', 'RaiseNPCNation', 'RaiseInvader', 'ProvideNPCTroopLeader'], true)) {
|
||||||
foreach ($db->query('SELECT * FROM general WHERE no > %i ORDER BY no', $generalIdBeforeAction) as $row) {
|
foreach ($db->query('SELECT * FROM general WHERE no > %i ORDER BY no', $generalIdBeforeAction) as $row) {
|
||||||
$generalId = (int)$row['no'];
|
$generalId = (int)$row['no'];
|
||||||
$turnRows = $db->query(
|
$turnRows = $db->query(
|
||||||
@@ -494,6 +506,10 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
'SELECT count(*) FROM rank_data WHERE general_id = %i AND value != 0',
|
'SELECT count(*) FROM rank_data WHERE general_id = %i AND value != 0',
|
||||||
$generalId,
|
$generalId,
|
||||||
),
|
),
|
||||||
|
'troop' => $db->queryFirstRow(
|
||||||
|
'SELECT troop_leader AS id, nation AS nationId, name FROM troop WHERE troop_leader = %i',
|
||||||
|
$generalId,
|
||||||
|
) ?: null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -552,6 +568,12 @@ function comparisonMonthlyEventTraceMain(): void
|
|||||||
$response['createdGenerals'] = $createdGenerals;
|
$response['createdGenerals'] = $createdGenerals;
|
||||||
$response['createdNations'] = $createdNations;
|
$response['createdNations'] = $createdNations;
|
||||||
}
|
}
|
||||||
|
if ($actionName === 'ProvideNPCTroopLeader') {
|
||||||
|
$response['createdGenerals'] = $createdGenerals;
|
||||||
|
$response['gameEnvironment'] = KVStorage::getStorage(DB::db(), 'game_env')->getValues([
|
||||||
|
'lastNPCTroopLeaderID',
|
||||||
|
]);
|
||||||
|
}
|
||||||
if ($actionName === 'RaiseInvader') {
|
if ($actionName === 'RaiseInvader') {
|
||||||
$response['createdEvents'] = array_map(
|
$response['createdEvents'] = array_map(
|
||||||
static fn(array $row): array => comparisonPickRow(
|
static fn(array $row): array => comparisonPickRow(
|
||||||
|
|||||||
Reference in New Issue
Block a user