2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Actions\JoinWorld;
|
|
|
|
|
use App\Actions\ListWorlds;
|
|
|
|
|
use App\Actions\ShowVillage;
|
2026-10-28 20:32:09 +00:00
|
|
|
use App\Game\Map\Continent;
|
2026-10-28 18:17:34 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\World;
|
|
|
|
|
|
|
|
|
|
it('starts a village with HQ, storage and farm at level 0', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
2026-10-28 20:32:09 +00:00
|
|
|
// On the spawn ring: start radius 6 ± 2 around 500|500.
|
|
|
|
|
expect(hypot($village->x - 500, $village->y - 500))->toBeBetween(3.0, 9.0)
|
2026-10-28 21:16:45 +00:00
|
|
|
->and($village->only('space', 'points'))->toBe(['space' => 40, 'points' => 21])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($village->resources())->toBe(['wood' => 500.0, 'clay' => 500.0, 'iron' => 500.0, 'food' => 300.0])
|
2026-10-28 18:45:02 +00:00
|
|
|
->and($village->buildings->map->only('type', 'level')->all())->toBe([
|
|
|
|
|
['type' => 'headquarters', 'level' => 0],
|
|
|
|
|
['type' => 'storage', 'level' => 0],
|
|
|
|
|
['type' => 'farm', 'level' => 0],
|
2026-10-28 18:17:34 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns the same village when joining again', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
|
|
|
|
expect(app(JoinWorld::class)(owner($village), $village->world_id)->id)->toBe($village->id);
|
|
|
|
|
});
|
|
|
|
|
|
2026-10-28 20:32:09 +00:00
|
|
|
it('spawns players on the ring, never next to another village', function () {
|
|
|
|
|
$villages = collect(range(1, 6))->map(fn () => startVillage(User::factory()->create()));
|
2026-10-28 18:17:34 +00:00
|
|
|
|
2026-10-28 20:32:09 +00:00
|
|
|
foreach ($villages as $a) {
|
|
|
|
|
foreach ($villages as $b) {
|
|
|
|
|
if ($a->isNot($b)) {
|
|
|
|
|
expect(max(abs($a->x - $b->x), abs($a->y - $b->y)))->toBeGreaterThanOrEqual(2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-28 18:17:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('lists worlds with their speed and the player village', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
$dev = World::where('slug', 'dev')->first();
|
|
|
|
|
|
|
|
|
|
expect(app(ListWorlds::class)(owner($village)))->toBe([
|
|
|
|
|
['id' => $village->world_id, 'name' => 'World 1', 'slug' => 'w1', 'speed' => 1.0, 'village_id' => $village->id],
|
|
|
|
|
['id' => $dev->id, 'name' => 'Dev world', 'slug' => 'dev', 'speed' => 100.0, 'village_id' => null],
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('shows a start village to its owner only', function () {
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
$state = shown($village);
|
|
|
|
|
|
2026-10-28 21:16:45 +00:00
|
|
|
expect($state['space'])->toBe(['used' => 17, 'max' => 40])
|
2026-10-28 20:32:09 +00:00
|
|
|
->and($state['continent'])->toBe(Continent::of($village->x, $village->y))
|
2026-10-28 20:28:16 +00:00
|
|
|
->and($state['rates'])->toBe(['wood' => 5.0, 'clay' => 5.0, 'iron' => 5.0, 'food' => 6.0])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($state['storage_cap'])->toEqual(1000)
|
2026-10-28 20:39:48 +00:00
|
|
|
->and($state['population'])->toEqual(['food_budget' => 30, 'upkeep' => 24, 'villagers' => 24, 'workers' => 5, 'soldiers' => 0, 'training' => 0])
|
2026-10-28 18:17:34 +00:00
|
|
|
->and($state['builders'])->toBe(2)
|
|
|
|
|
->and(collect($state['buildable'])->firstWhere('type', 'headquarters')['blocked'])->toBe('max_per_village')
|
2026-10-28 19:58:35 +00:00
|
|
|
->and(collect($state['buildable'])->firstWhere('type', 'wall')['blocked'])->toBeNull()
|
2026-10-28 18:17:34 +00:00
|
|
|
->and(rule(fn () => app(ShowVillage::class)(User::factory()->create(), $village->id)))->toBe('not_found');
|
|
|
|
|
});
|