103 lines
3.5 KiB
PHP
103 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace sammo;
|
|
|
|
use sammo\Enums\RankColumn;
|
|
|
|
/**
|
|
* Build the existing battle simulator request from live, pre-battle objects.
|
|
*
|
|
* This file is loaded only by the deterministic CLI comparison path. It must
|
|
* remain read-only: callers emit the returned value without changing the live
|
|
* objects or consuming RNG.
|
|
*/
|
|
function comparisonBuildBattleGeneralFixture(General $general): array
|
|
{
|
|
$raw = $general->getRaw(true);
|
|
$inheritBuff = $general->getAuxVar('inheritBuff');
|
|
|
|
$fixture = [
|
|
'no' => $general->getID(),
|
|
'name' => $general->getName(),
|
|
'nation' => $general->getNationID(),
|
|
'city' => $general->getCityID(),
|
|
'turntime' => $general->getTurnTime(General::TURNTIME_FULL_MS),
|
|
'turntick' => $general->getTurnTick(),
|
|
'personal' => $raw['personal'] ?? null,
|
|
'special' => $raw['special'] ?? null,
|
|
'special2' => $raw['special2'] ?? null,
|
|
'crew' => $raw['crew'],
|
|
'crewtype' => $raw['crewtype'],
|
|
'atmos' => $raw['atmos'],
|
|
'train' => $raw['train'],
|
|
'intel' => $raw['intel'],
|
|
'intel_exp' => $raw['intel_exp'],
|
|
'book' => $raw['book'] ?? 'None',
|
|
'strength' => $raw['strength'],
|
|
'strength_exp' => $raw['strength_exp'],
|
|
'weapon' => $raw['weapon'] ?? 'None',
|
|
'injury' => $raw['injury'],
|
|
'leadership' => $raw['leadership'],
|
|
'leadership_exp' => $raw['leadership_exp'],
|
|
'horse' => $raw['horse'] ?? 'None',
|
|
'item' => $raw['item'] ?? 'None',
|
|
'explevel' => $raw['explevel'],
|
|
'experience' => $raw['experience'],
|
|
'dedication' => $raw['dedication'],
|
|
'officer_level' => $raw['officer_level'],
|
|
'officer_city' => $raw['officer_city'],
|
|
'gold' => $raw['gold'],
|
|
'rice' => $raw['rice'],
|
|
'dex1' => $raw['dex1'],
|
|
'dex2' => $raw['dex2'],
|
|
'dex3' => $raw['dex3'],
|
|
'dex4' => $raw['dex4'],
|
|
'dex5' => $raw['dex5'],
|
|
'defence_train' => $raw['defence_train'],
|
|
'recent_war' => $raw['recent_war'] ?? null,
|
|
'warnum' => $general->getRankVar(RankColumn::warnum, 0),
|
|
'killnum' => $general->getRankVar(RankColumn::killnum, 0),
|
|
'killcrew' => $general->getRankVar(RankColumn::killcrew, 0),
|
|
];
|
|
if ($inheritBuff !== null) {
|
|
$fixture['inheritBuff'] = $inheritBuff;
|
|
}
|
|
return $fixture;
|
|
}
|
|
|
|
function comparisonBuildBattleFixture(
|
|
string $seed,
|
|
int $year,
|
|
int $month,
|
|
int $startYear,
|
|
General $attacker,
|
|
array $attackerNation,
|
|
array $defenders,
|
|
array $defenderCity,
|
|
array $defenderNation,
|
|
): array {
|
|
return [
|
|
'action' => 'battle',
|
|
'seed' => $seed,
|
|
'repeatCnt' => 1,
|
|
'year' => $year,
|
|
'month' => $month,
|
|
'startYear' => $startYear,
|
|
'scenarioEffect' => GameConst::$scenarioEffect,
|
|
'attackerGeneral' => comparisonBuildBattleGeneralFixture($attacker),
|
|
'attackerCity' => $attacker->getRawCity(),
|
|
'attackerNation' => $attackerNation,
|
|
// General::getGeneralList() can retain IDs as array keys. JSON would
|
|
// then encode the collection as an object, while both simulators use
|
|
// an ordered list. Keep the legacy iteration order but discard keys.
|
|
'defenderGenerals' => array_values(array_map(
|
|
static fn(General $general): array => comparisonBuildBattleGeneralFixture($general),
|
|
$defenders,
|
|
)),
|
|
'defenderCity' => $defenderCity,
|
|
'defenderNation' => $defenderNation,
|
|
];
|
|
}
|