2026-10-28 18:45:03 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
use App\Actions\ShowMap;
|
2026-10-28 20:32:09 +00:00
|
|
|
|
use App\Game\Map\Continent;
|
|
|
|
|
|
use App\Models\GameEvent;
|
2026-10-28 18:45:03 +00:00
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
use App\Models\Village;
|
|
|
|
|
|
|
|
|
|
|
|
it('opens on the player village and marks it as their own', function () {
|
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
$other = startVillage(User::factory()->create(['name' => 'Bea']));
|
|
|
|
|
|
|
2026-10-28 20:32:09 +00:00
|
|
|
|
$map = app(ShowMap::class)(owner($village), $village->world_id, null, null, 41, 41);
|
2026-10-28 18:45:03 +00:00
|
|
|
|
|
2026-10-28 20:32:09 +00:00
|
|
|
|
expect($map)->toMatchArray([
|
|
|
|
|
|
'center' => ['x' => $village->x, 'y' => $village->y],
|
|
|
|
|
|
'x' => $village->x - 20,
|
|
|
|
|
|
'y' => $village->y - 20,
|
|
|
|
|
|
'w' => 41,
|
|
|
|
|
|
'h' => 41,
|
|
|
|
|
|
'size' => 1000,
|
|
|
|
|
|
])
|
2026-10-28 18:45:03 +00:00
|
|
|
|
->and(collect($map['villages'])->keyBy('id')->sortKeys()->map(fn ($v) => [$v['x'], $v['y'], $v['own'], $v['player']['name'] ?? null, $v['continent']])->all())
|
|
|
|
|
|
->toBe([
|
2026-10-28 20:32:09 +00:00
|
|
|
|
$village->id => [$village->x, $village->y, true, owner($village)->name, Continent::of($village->x, $village->y)],
|
|
|
|
|
|
$other->id => [$other->x, $other->y, false, 'Bea', Continent::of($other->x, $other->y)],
|
2026-10-28 18:45:03 +00:00
|
|
|
|
]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('shows only the window around the given centre, kept inside the map', function () {
|
|
|
|
|
|
$village = startVillage();
|
|
|
|
|
|
|
|
|
|
|
|
$far = app(ShowMap::class)(owner($village), $village->world_id, 100, 100, 15, 15);
|
2026-10-29 00:51:37 +00:00
|
|
|
|
$edge = app(ShowMap::class)(owner($village), $village->world_id, -498, 498, 15, 999);
|
2026-10-28 18:45:03 +00:00
|
|
|
|
|
2026-10-29 00:51:37 +00:00
|
|
|
|
// Coordinates run from −500 to 499.
|
2026-10-28 18:45:03 +00:00
|
|
|
|
expect($far['villages'])->toBe([])
|
2026-10-29 00:51:37 +00:00
|
|
|
|
->and($edge)->toMatchArray(['x' => -500, 'y' => 439, 'w' => 15, 'h' => 61, 'min' => -500]);
|
2026-10-28 18:45:03 +00:00
|
|
|
|
});
|
2026-10-28 20:32:09 +00:00
|
|
|
|
|
|
|
|
|
|
it('lets barbarian villages grow over time, one building per step', function () {
|
2026-10-29 00:51:37 +00:00
|
|
|
|
config(['game.world.map.barbarians' => ['per_join' => 3, 'near' => 4, 'max_level' => 3, 'growth' => ['every_hours' => 1, 'max_level' => 10]]]);
|
2026-10-28 20:32:09 +00:00
|
|
|
|
$this->travelTo(now()->startOfMinute());
|
|
|
|
|
|
$world = startVillage()->world_id;
|
|
|
|
|
|
$barbarians = fn () => Village::where('world_id', $world)->whereNull('player_id')->with('buildings')->get();
|
|
|
|
|
|
$levels = fn () => $barbarians()->sum(fn ($v) => $v->buildings->sum('level'));
|
|
|
|
|
|
$pending = fn () => GameEvent::where('world_id', $world)->where('type', GameEvent::BARBARIAN_GROWS)->whereNull('processed_at')->count();
|
|
|
|
|
|
$before = ['levels' => $levels(), 'points' => $barbarians()->sum('points')];
|
|
|
|
|
|
|
|
|
|
|
|
expect($pending())->toBe(3);
|
|
|
|
|
|
|
|
|
|
|
|
// Each first step lands within 0.5–1.5 h, the next one an hour later.
|
|
|
|
|
|
$this->travel(3)->hours();
|
|
|
|
|
|
$this->artisan('game:events --once')->assertSuccessful();
|
|
|
|
|
|
|
|
|
|
|
|
expect($levels())->toBeGreaterThanOrEqual($before['levels'] + 6)
|
|
|
|
|
|
->and($barbarians()->sum('points'))->toBeGreaterThan($before['points'])
|
|
|
|
|
|
->and($pending())->toBe(3);
|
|
|
|
|
|
});
|