30 lines
1.2 KiB
PHP
30 lines
1.2 KiB
PHP
<?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])
|
||
// One of 20 catapults falls; 19 take the building down one level, 20 would take two.
|
||
->and($result['building'])->toBe(['before' => 20, 'after' => 19])
|
||
->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%.
|
||
expect($low['power']['attack'])->toBe(round(1000 * 0.3 * 0.75, 1));
|
||
});
|