2026-10-28 23:08:43 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
use App\Actions\SimulateBattle;
|
|
|
|
|
|
use App\Models\World;
|
|
|
|
|
|
use Database\Seeders\WorldSeeder;
|
|
|
|
|
|
|
|
|
|
|
|
it('simulates a battle with the world\'s rules and changes nothing', function () {
|
|
|
|
|
|
(new WorldSeeder)->run();
|
|
|
|
|
|
$world = World::where('slug', 'w1')->value('id');
|
|
|
|
|
|
|
|
|
|
|
|
$result = app(SimulateBattle::class)($world, ['light_cavalry' => 100, 'catapult' => 20, 'axe' => 5], ['spear' => 50, 'militia' => 10], 0, 100, 0, false, 20);
|
|
|
|
|
|
|
|
|
|
|
|
expect($result['won'])->toBeTrue()
|
|
|
|
|
|
->and((array) $result['attacker']['units'])->toBe(['light_cavalry' => 100, 'catapult' => 20])
|
|
|
|
|
|
->and((array) $result['defender']['lost'])->toBe(['spear' => 50, 'militia' => 10])
|
2026-10-31 09:59:32 +00:00
|
|
|
|
// 20 catapults shoot 10 food at 60 before the melee: a sixth of each falls.
|
|
|
|
|
|
->and((array) $result['volley']['defender'])->toBe(['spear' => 8, 'militia' => 2])
|
|
|
|
|
|
->and((array) $result['volley']['attacker'])->toBe(['light_cavalry' => 0, 'catapult' => 0])
|
2026-10-31 09:56:05 +00:00
|
|
|
|
// 2100 defence against 15000 attack: under 1% falls, no catapult, so 20 take the building down two levels.
|
|
|
|
|
|
->and($result['building'])->toBe(['before' => 20, 'after' => 18])
|
2026-10-28 23:08:43 +00:00
|
|
|
|
->and($result['wall'])->toBeNull();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('keeps morale and luck within the world\'s limits', function () {
|
|
|
|
|
|
(new WorldSeeder)->run();
|
|
|
|
|
|
$world = World::where('slug', 'w1')->value('id');
|
|
|
|
|
|
|
|
|
|
|
|
$low = app(SimulateBattle::class)($world, ['spear' => 100], [], 0, 0, -90, false, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// Morale never below 30%, luck never below −25%.
|
2026-10-31 09:59:32 +00:00
|
|
|
|
expect($low['power']['attack'])->toBe(round(1000 * 0.3 * 0.75, 1))
|
|
|
|
|
|
->and($low['volley'])->toBeNull();
|
2026-10-28 23:08:43 +00:00
|
|
|
|
});
|