feat(combat): to-hit roll, ±15% damage variance, crits, and new log format

This commit is contained in:
Keith Solomon
2026-07-26 21:41:53 -05:00
parent 9eac4981f4
commit 4cc457c231
3 changed files with 657 additions and 79 deletions
+36 -23
View File
@@ -92,34 +92,47 @@ final class PostMatchActionTest extends TestCase
$matchArray = ScenarioSerializer::matchToArray($match);
$matchArray['units'][0]['position'] = ['x' => 6, 'y' => 7];
$match = ScenarioSerializer::matchFromArray($matchArray);
$token = $this->tokenFor($match);
[$csrf, $cookie] = CsrfToken::issue(self::SECRET);
$response = (new PostMatchAttack(self::SECRET))->handle(
$this->buildRequest(
match: $match,
csrf: $csrf,
turnToken: $token,
cookies: ['__csrf' => $cookie, '__csrf_token' => $token],
body: [
'matchId' => self::MATCH_ID,
'match' => ScenarioSerializer::matchToArray($match),
'attackerId' => 'alpha-1',
'targetId' => 'bravo-1',
],
),
[],
);
self::assertSame(200, $response->status);
$body = json_decode($response->body, true);
// Loop until a hit lands; the to-hit roll can miss.
$bravo = null;
foreach ($body['match']['units'] as $unit) {
if ($unit['id'] === 'bravo-1') {
$bravo = $unit;
for ($i = 0; $i < 200; $i += 1) {
$match = $this->freshMatch();
$matchArray = ScenarioSerializer::matchToArray($match);
$matchArray['units'][0]['position'] = ['x' => 6, 'y' => 7];
$match = ScenarioSerializer::matchFromArray($matchArray);
$token = $this->tokenFor($match);
[$csrf, $cookie] = CsrfToken::issue(self::SECRET);
$response = (new PostMatchAttack(self::SECRET))->handle(
$this->buildRequest(
match: $match,
csrf: $csrf,
turnToken: $token,
cookies: ['__csrf' => $cookie, '__csrf_token' => $token],
body: [
'matchId' => self::MATCH_ID,
'match' => ScenarioSerializer::matchToArray($match),
'attackerId' => 'alpha-1',
'targetId' => 'bravo-1',
],
),
[],
);
self::assertSame(200, $response->status);
$body = json_decode($response->body, true);
$bravo = null;
foreach ($body['match']['units'] as $unit) {
if ($unit['id'] === 'bravo-1') {
$bravo = $unit;
break;
}
}
if ($bravo !== null && $bravo['health'] < 10) {
break;
}
}
self::assertNotNull($bravo);
self::assertLessThan(10, $bravo['health']);
}