gameConfig()); $crowns = $world->crowns_placed_at ? Village::where('world_id', $world->id)->where('crown', true)->with('player:id,name')->orderBy('id')->get() : collect(); return [ // When they appear, or appeared. 'crowns_at' => self::iso($world->crowns_placed_at ?? $season->crownsAt($world->started_at)), 'count' => $season->count(), 'needed' => $season->needed(), 'hold_seconds' => $season->holdSeconds(), 'crowns' => $crowns->map(fn (Village $v) => [ 'id' => $v->id, 'name' => $v->name, 'x' => $v->x, 'y' => $v->y, 'player' => self::player($v->player), ])->values()->all(), 'holder' => self::player($world->holder), // When the holder wins if they keep the crowns. 'ends_at' => $world->ends_at ? self::iso($world->ends_at) : null, 'ended_at' => $world->ended_at ? self::iso($world->ended_at) : null, 'winner' => self::player($world->winner), ]; } private static function player(?Player $player): ?array { return $player ? ['id' => $player->id, 'name' => $player->name] : null; } private static function iso(CarbonImmutable $at): string { return $at->utc()->format('Y-m-d\TH:i:s.v\Z'); } }