2026-10-29 15:07:54 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2026-10-31 10:05:05 +00:00
|
|
|
|
use App\Game\Combat\Battle;
|
2026-10-29 15:07:54 +00:00
|
|
|
|
use App\Game\Combat\Raids;
|
|
|
|
|
|
|
|
|
|
|
|
it('sizes a band by the village points in its camp profile', function () {
|
|
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
|
|
|
|
|
|
// 50 + 1.5 × 300 = 500 attack; a spearmen head hits 0.7 × 10 + 0.3 × 25 = 14.5, so 35 heads.
|
|
|
|
|
|
expect($raids->attack(300))->toBe(500.0)
|
|
|
|
|
|
->and($raids->band('spearmen', 300, 0))->toBe(['spear' => 25, 'sword' => 10])
|
|
|
|
|
|
// Riders: 0.5 × 130 + 0.5 × 10 = 70 a head, 155 / 70 → 3 heads.
|
|
|
|
|
|
->and($raids->band('riders', 70, 0))->toBe(['light_cavalry' => 2, 'spear' => 1])
|
|
|
|
|
|
->and($raids->band(null, 300, 0))->toBe([]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-31 10:04:35 +00:00
|
|
|
|
it('brings a ram for every two wall levels of a big enough village', function () {
|
2026-10-29 15:07:54 +00:00
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
|
2026-10-31 10:04:35 +00:00
|
|
|
|
expect($raids->band('swordsmen', 300, 4))->toHaveKey('ram', 2)
|
|
|
|
|
|
->and($raids->band('swordsmen', 300, 5))->toHaveKey('ram', 3)
|
|
|
|
|
|
->and($raids->band('swordsmen', 300, 1))->toHaveKey('ram', 1)
|
2026-10-29 15:07:54 +00:00
|
|
|
|
->and($raids->band('swordsmen', 299, 5))->not->toHaveKey('ram')
|
|
|
|
|
|
->and($raids->band('swordsmen', 300, 0))->not->toHaveKey('ram');
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('shrinks the band with its camp and scatters it below a quarter', function () {
|
|
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
$band = ['spear' => 25, 'sword' => 10];
|
|
|
|
|
|
|
|
|
|
|
|
expect($raids->muster($band, 1.0))->toBe($band)
|
|
|
|
|
|
->and($raids->muster($band, 0.5))->toBe(['spear' => 13, 'sword' => 5])
|
|
|
|
|
|
->and($raids->muster($band, 0.25))->toBe(['spear' => 6, 'sword' => 3])
|
|
|
|
|
|
->and($raids->muster($band, 0.24))->toBe([]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('leaves half its attack strength as bounty when beaten', function () {
|
|
|
|
|
|
// 25 × 10 + 10 × 25 = 500 attack → 250, a third each.
|
|
|
|
|
|
expect((new Raids(gameConfig()))->bounty(['spear' => 25, 'sword' => 10]))->toBe(['wood' => 83, 'clay' => 83, 'iron' => 83]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-31 10:04:35 +00:00
|
|
|
|
it('comes every 20 to 40 real hours on any world, after three real hours of warning', function () {
|
2026-10-29 15:07:54 +00:00
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
$fast = new Raids(gameConfig(['world' => ['speed' => 100]]));
|
|
|
|
|
|
|
2026-10-31 10:04:35 +00:00
|
|
|
|
expect($raids->interval(0.0))->toBe(20 * 3600)
|
|
|
|
|
|
->and($raids->interval(0.5))->toBe(30 * 3600)
|
|
|
|
|
|
->and($fast->interval(0.5))->toBe(30 * 3600)
|
2026-10-29 15:07:54 +00:00
|
|
|
|
->and($raids->gatherSeconds())->toBe(3 * 3600)
|
2026-10-31 10:04:35 +00:00
|
|
|
|
->and($fast->gatherSeconds())->toBe(3 * 3600);
|
2026-10-29 15:07:54 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-31 10:05:05 +00:00
|
|
|
|
it('stays home when the band would lose with less than 30% of the defence\'s strength', function () {
|
|
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
|
|
|
|
|
|
expect($raids->dares(new Battle(true, 0.0, 1.0, 0, 0, 100.0, 1.0)))->toBeTrue()
|
|
|
|
|
|
->and($raids->dares(new Battle(false, 1.0, 0.0, 0, 0, 30.0, 100.0)))->toBeTrue()
|
|
|
|
|
|
->and($raids->dares(new Battle(false, 1.0, 0.0, 0, 0, 29.0, 100.0)))->toBeFalse()
|
|
|
|
|
|
// Shot to pieces before the melee.
|
|
|
|
|
|
->and($raids->dares(new Battle(false, 1.0, 0.0, 0, 0, 0.0, 0.0)))->toBeFalse()
|
|
|
|
|
|
->and((new Raids(gameConfig(['raids' => ['dare' => 0]])))->dares(new Battle(false, 1.0, 0.0, 0, 0, 1.0, 100.0)))->toBeTrue();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-10-29 15:07:54 +00:00
|
|
|
|
it('picks the nearest camp in range', function () {
|
|
|
|
|
|
$raids = new Raids(gameConfig());
|
|
|
|
|
|
$camps = [['id' => 7, 'x' => 10, 'y' => 0], ['id' => 3, 'x' => 0, 'y' => 4], ['id' => 2, 'x' => 4, 'y' => 0], ['id' => 9, 'x' => 16, 'y' => 0]];
|
|
|
|
|
|
|
|
|
|
|
|
expect($raids->nearest($camps, 0, 0))->toBe(2)
|
|
|
|
|
|
->and($raids->nearest([['id' => 9, 'x' => 16, 'y' => 0]], 0, 0))->toBeNull();
|
|
|
|
|
|
});
|