2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Game\Buildings\BuildingRules;
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
it('costs the base at level 1 and grows by the factor per level', function () {
|
2026-10-28 18:17:34 +00:00
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->cost('timber_camp', 1))->toBe(['wood' => 50, 'clay' => 60, 'iron' => 40])
|
|
|
|
|
->and($rules->cost('timber_camp', 3))->toBe([
|
2026-10-28 18:17:34 +00:00
|
|
|
'wood' => (int) round(50 * 1.25 ** 2),
|
|
|
|
|
'clay' => (int) round(60 * 1.25 ** 2),
|
|
|
|
|
'iron' => (int) round(40 * 1.25 ** 2),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('makes later instances of a type more expensive', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->cost('farm', 1, 1))->toBe(['wood' => 68, 'clay' => 60, 'iron' => 45])
|
|
|
|
|
->and($rules->cost('headquarters', 1, 3))->toBe($rules->cost('headquarters', 1));
|
2026-10-28 18:17:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('divides build time by world speed, headquarters level and staffing', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 100]]));
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(90)
|
|
|
|
|
->and($rules->buildSeconds('timber_camp', 2, 1, 1.0))->toBe(108)
|
|
|
|
|
->and($rules->buildSeconds('timber_camp', 1, 11, 1.0))->toBe(60)
|
|
|
|
|
->and($rules->buildSeconds('timber_camp', 1, 1, 0.5))->toBe(180)
|
|
|
|
|
->and($fast->buildSeconds('timber_camp', 1, 1, 1.0))->toBe(1);
|
2026-10-28 18:17:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('takes half the time and refunds half the cost when demolishing', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->demolishSeconds('timber_camp', 2, 1, 1.0))->toBe(54)
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($rules->demolishRefund('timber_camp', 0))->toBe(['wood' => 25, 'clay' => 30, 'iron' => 20]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('rounds workers and scales output with world speed', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
$fast = new BuildingRules(gameConfig(['world' => ['speed' => 2]]));
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->workers('timber_camp', 1))->toBe(2)
|
|
|
|
|
->and($rules->workers('timber_camp', 11))->toBe((int) round(2 * 1.12 ** 10))
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($rules->workers('hiding_place', 5))->toBe(0)
|
2026-10-28 21:26:25 +00:00
|
|
|
->and($rules->output('timber_camp', 1))->toBe(['resource' => 'wood', 'per_hour' => 30.0])
|
|
|
|
|
->and($fast->output('farm', 1))->toBe(['resource' => 'food', 'per_hour' => 60.0])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($rules->output('storage', 3))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('gives storage capacity only to storage', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->capacity('storage', 1))->toBe(1000.0)
|
|
|
|
|
->and($rules->capacity('storage', 2))->toBe(1230.0)
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($rules->capacity('farm', 1))->toBe(0.0);
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-28 18:45:02 +00:00
|
|
|
it('takes building space per type at every level, and none for the wall', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
|
|
|
|
expect($rules->space('headquarters'))->toBe(9)
|
|
|
|
|
->and($rules->space('wall'))->toBe(0)
|
|
|
|
|
->and($rules->spaceUsed(['headquarters', 'storage', 'farm', 'hiding_place', 'wall']))->toBe(18);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('gives points per building level', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->points('headquarters', 1))->toBe(10)
|
|
|
|
|
->and($rules->points('headquarters', 6))->toBe((int) round(10 * 1.2 ** 5))
|
|
|
|
|
->and($rules->points('rally_point', 1))->toBe(2);
|
2026-10-28 18:45:02 +00:00
|
|
|
});
|
|
|
|
|
|
2026-10-28 18:17:34 +00:00
|
|
|
it('adds builders at the configured headquarters levels', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
|
|
|
|
expect($rules->builders(0))->toBe(2)
|
|
|
|
|
->and($rules->builders(9))->toBe(2)
|
|
|
|
|
->and($rules->builders(10))->toBe(3)
|
|
|
|
|
->and($rules->builders(20))->toBe(4);
|
|
|
|
|
});
|
2026-10-28 21:16:45 +00:00
|
|
|
|
|
|
|
|
it('adds building space for every headquarters level', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
expect($rules->spaceMax(40, 1))->toBe(40)
|
2026-10-29 15:20:52 +00:00
|
|
|
->and($rules->spaceMax(40, 2))->toBe(45)
|
|
|
|
|
->and($rules->spaceMax(40, 30))->toBe(185);
|
2026-10-28 21:16:45 +00:00
|
|
|
});
|
2026-10-29 13:32:19 +00:00
|
|
|
|
|
|
|
|
it('lists what an instance does at a level', function () {
|
|
|
|
|
$rules = new BuildingRules(gameConfig());
|
|
|
|
|
|
|
|
|
|
expect($rules->effects('timber_camp', 1))->toBe([['key' => 'production', 'value' => 30.0, 'resource' => 'wood']])
|
|
|
|
|
->and($rules->effects('storage', 2))->toBe([['key' => 'capacity', 'value' => 1230]])
|
|
|
|
|
->and($rules->effects('hiding_place', 1))->toBe([['key' => 'hides', 'value' => 150]])
|
2026-10-30 12:45:02 +00:00
|
|
|
->and($rules->effects('hospital', 2))->toBe([['key' => 'beds', 'value' => 24]])
|
2026-10-29 13:32:19 +00:00
|
|
|
->and($rules->effects('wall', 3))->toBe([['key' => 'wall_defense', 'value' => 60], ['key' => 'wall_bonus', 'value' => 12]])
|
2026-10-29 15:20:52 +00:00
|
|
|
->and($rules->effects('headquarters', 3))->toBe([['key' => 'build_speed', 'value' => 10], ['key' => 'builders', 'value' => 2], ['key' => 'space', 'value' => 50]])
|
2026-10-29 13:32:19 +00:00
|
|
|
->and($rules->effects('barracks', 6))->toBe([['key' => 'recruit_speed', 'value' => 25]])
|
|
|
|
|
->and($rules->effects('rally_point', 1))->toBe([]);
|
|
|
|
|
});
|