2026-10-28 18:17:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
2026-10-29 00:51:37 +00:00
|
|
|
use App\Actions\SpawnBarbarians;
|
2026-11-03 08:33:52 +00:00
|
|
|
use App\Engine\Waves;
|
2026-10-28 18:17:34 +00:00
|
|
|
use App\Models\World;
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
2026-10-29 00:51:37 +00:00
|
|
|
/**
|
2026-11-03 11:14:21 +00:00
|
|
|
* The default world and a fast dev world (config/worlds.php). They start empty:
|
|
|
|
|
* villages, barbarian ones included, come with the players who join and the barbarian
|
|
|
|
|
* waves near them. A world that exists keeps its config. Safe to run on every deploy.
|
2026-10-29 00:51:37 +00:00
|
|
|
*/
|
2026-10-28 18:17:34 +00:00
|
|
|
class WorldSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
public function run(): void
|
|
|
|
|
{
|
2026-11-03 11:14:21 +00:00
|
|
|
$worlds = [];
|
|
|
|
|
foreach (config('worlds') as $slug => $world) {
|
|
|
|
|
$worlds[] = World::firstOrCreate(['slug' => $slug], [
|
|
|
|
|
'name' => $world['name'],
|
|
|
|
|
'config' => ($world['config'] ?? []) ?: null,
|
2026-10-28 18:45:03 +00:00
|
|
|
'started_at' => now(),
|
2026-11-03 11:14:21 +00:00
|
|
|
]);
|
|
|
|
|
}
|
2026-10-29 15:07:54 +00:00
|
|
|
// Barbarian villages that lost their growth event get it back, and their garrison;
|
|
|
|
|
// player villages get a raid planned.
|
2026-10-28 18:45:03 +00:00
|
|
|
foreach ($worlds as $world) {
|
2026-10-29 00:51:37 +00:00
|
|
|
app(SpawnBarbarians::class)->scheduleGrowth($world);
|
2026-10-29 15:02:49 +00:00
|
|
|
app(SpawnBarbarians::class)->scheduleGarrisons($world);
|
2026-10-29 15:07:54 +00:00
|
|
|
app(SpawnBarbarians::class)->scheduleRaids($world);
|
2026-10-28 18:45:03 +00:00
|
|
|
}
|
2026-11-03 08:33:52 +00:00
|
|
|
// Every open world without a barbarian wave planned gets one an interval from now.
|
|
|
|
|
foreach (World::whereNull('ended_at')->whereNull('barbarians_at')->get() as $world) {
|
|
|
|
|
Waves::start($world, now()->toImmutable());
|
|
|
|
|
}
|
2026-10-28 18:17:34 +00:00
|
|
|
}
|
|
|
|
|
}
|