60 lines
2.6 KiB
PHP
60 lines
2.6 KiB
PHP
<?php
|
||
|
||
use App\Actions\ShowMap;
|
||
use App\Game\Map\Continent;
|
||
use App\Models\GameEvent;
|
||
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']));
|
||
|
||
$map = app(ShowMap::class)(owner($village), $village->world_id, null, null, 41, 41);
|
||
|
||
expect($map)->toMatchArray([
|
||
'center' => ['x' => $village->x, 'y' => $village->y],
|
||
'x' => $village->x - 20,
|
||
'y' => $village->y - 20,
|
||
'w' => 41,
|
||
'h' => 41,
|
||
'size' => 1000,
|
||
])
|
||
->and(collect($map['villages'])->keyBy('id')->sortKeys()->map(fn ($v) => [$v['x'], $v['y'], $v['own'], $v['player']['name'] ?? null, $v['continent']])->all())
|
||
->toBe([
|
||
$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)],
|
||
]);
|
||
});
|
||
|
||
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);
|
||
$edge = app(ShowMap::class)(owner($village), $village->world_id, -498, 498, 15, 999);
|
||
|
||
// Coordinates run from −500 to 499.
|
||
expect($far['villages'])->toBe([])
|
||
->and($edge)->toMatchArray(['x' => -500, 'y' => 439, 'w' => 15, 'h' => 61, 'min' => -500]);
|
||
});
|
||
|
||
it('lets barbarian villages grow over time, one building per step', function () {
|
||
config(['game.world.map.barbarians' => ['per_join' => 3, 'near' => 4, 'max_level' => 3, 'growth' => ['every_hours' => 1, 'max_level' => 10]]]);
|
||
$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);
|
||
});
|