2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Actions\JoinWorld;
|
|
|
|
|
use App\Actions\ShowVillage;
|
|
|
|
|
use App\Game\Buildings\BuildingState;
|
|
|
|
|
use App\Game\GameRuleViolation;
|
|
|
|
|
use App\Game\WorldConfig;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Village;
|
|
|
|
|
use App\Models\World;
|
|
|
|
|
use App\Presenters\VillagePresenter;
|
|
|
|
|
use Database\Seeders\WorldSeeder;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
2026-10-29 15:07:54 +00:00
|
|
|
// Feature tests start without barbarians and raids unless a test asks for them, so tests can place their own.
|
2026-10-28 18:45:02 +00:00
|
|
|
pest()->extend(TestCase::class)->use(RefreshDatabase::class)
|
2026-10-29 15:07:54 +00:00
|
|
|
->beforeEach(fn () => config(['game.world.map.barbarians.per_join' => 0, 'game.raids.enabled' => false]))
|
2026-10-28 18:45:02 +00:00
|
|
|
->in('Feature');
|
2026-10-28 18:17:34 +00:00
|
|
|
|
|
|
|
|
/** The default game config without booting Laravel, so unit tests stay pure. */
|
|
|
|
|
function gameConfig(array $overrides = []): WorldConfig
|
|
|
|
|
{
|
|
|
|
|
$dir = __DIR__.'/../config/game';
|
|
|
|
|
|
|
|
|
|
return WorldConfig::make([
|
|
|
|
|
'world' => require "$dir/world.php",
|
|
|
|
|
'economy' => require "$dir/economy.php",
|
|
|
|
|
'buildings' => require "$dir/buildings.php",
|
2026-10-28 20:39:48 +00:00
|
|
|
'units' => require "$dir/units.php",
|
2026-10-28 22:56:55 +00:00
|
|
|
'combat' => require "$dir/combat.php",
|
|
|
|
|
'movement' => require "$dir/movement.php",
|
2026-10-29 15:07:54 +00:00
|
|
|
'raids' => require "$dir/raids.php",
|
2026-10-30 09:47:41 +00:00
|
|
|
'tribes' => require "$dir/tribes.php",
|
2026-10-29 09:05:55 +00:00
|
|
|
'quests' => require "$dir/quests.php",
|
2026-10-28 18:17:34 +00:00
|
|
|
], $overrides);
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-28 21:26:25 +00:00
|
|
|
function building(int $id, string $type, int $level = 1, int $priority = 5): BuildingState
|
2026-10-28 18:17:34 +00:00
|
|
|
{
|
|
|
|
|
return new BuildingState($id, $type, $level, $priority);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** A user with a fresh start village in World 1 (speed 1). */
|
|
|
|
|
function startVillage(?User $user = null): Village
|
|
|
|
|
{
|
|
|
|
|
(new WorldSeeder)->run();
|
|
|
|
|
|
|
|
|
|
return app(JoinWorld::class)($user ?? User::factory()->create(), World::where('slug', 'w1')->value('id'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function owner(Village $village): User
|
|
|
|
|
{
|
|
|
|
|
return $village->player->user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** The client payload, as `village.show` would send it now. */
|
|
|
|
|
function shown(Village $village): array
|
|
|
|
|
{
|
|
|
|
|
return VillagePresenter::present(app(ShowVillage::class)(owner($village), $village->id), now()->toImmutable());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rule(Closure $intent): string
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$intent();
|
|
|
|
|
} catch (GameRuleViolation $e) {
|
|
|
|
|
return $e->reason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new RuntimeException('Expected a GameRuleViolation.');
|
|
|
|
|
}
|