addSeconds((int) round($this->config->get('world.season.crowns_after_days', 30) * 86400)); } /** How long a holder must keep the crowns to win: hold_days real days, on every world speed. */ public function holdSeconds(): int { return max(1, (int) round($this->config->get('world.season.hold_days', 7) * 86400)); } public function count(): int { return (int) $this->config->get('world.season.crowns', 0); } /** More than half of the crowns. */ public function needed(): int { return intdiv($this->count(), 2) + 1; } /** * Where the crowns should stand: evenly round a ring of `radius` fields about 0|0. * * @return list */ public function spots(): array { $radius = (float) $this->config->get('world.season.radius', 10); $spots = []; for ($i = 0; $i < $this->count(); $i++) { $angle = 2 * M_PI * $i / $this->count() - M_PI / 2; $spots[] = [(int) round($radius * cos($angle)), (int) round($radius * sin($angle))]; } return $spots; } /** * The player holding more than half of the crowns, if anyone does. * * @param iterable $owners the owner of every crown, null for barbarian */ public function holder(iterable $owners): ?int { $held = []; foreach ($owners as $owner) { if ($owner !== null) { $held[$owner] = ($held[$owner] ?? 0) + 1; } } arsort($held); $top = array_key_first($held); return $top !== null && $held[$top] >= $this->needed() ? (int) $top : null; } /** "w1" → "w2", "dev" → "dev2", "World 1" → "World 2". */ public static function next(string $name): string { return preg_match('/^(.*?)(\d+)$/', $name, $m) ? $m[1].((int) $m[2] + 1) : $name.'2'; } }