40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Actions\SpawnBarbarians;
|
|
use App\Engine\Waves;
|
|
use App\Models\World;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
class WorldSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$worlds = [];
|
|
foreach (config('worlds') as $slug => $world) {
|
|
$worlds[] = World::firstOrCreate(['slug' => $slug], [
|
|
'name' => $world['name'],
|
|
'config' => ($world['config'] ?? []) ?: null,
|
|
'started_at' => now(),
|
|
]);
|
|
}
|
|
// Barbarian villages that lost their growth event get it back, and their garrison;
|
|
// player villages get a raid planned.
|
|
foreach ($worlds as $world) {
|
|
app(SpawnBarbarians::class)->scheduleGrowth($world);
|
|
app(SpawnBarbarians::class)->scheduleGarrisons($world);
|
|
app(SpawnBarbarians::class)->scheduleRaids($world);
|
|
}
|
|
// 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());
|
|
}
|
|
}
|
|
}
|