using System; using System.Collections.Generic; using KernelPanic.Run; namespace KernelPanic.Combat { public sealed class EncounterPlan { public string Title { get; } public string Advice { get; } public IReadOnlyList Enemies { get; } public int UptimeBonus { get; } public int EscortShield { get; internal set; } public int EscortUptime { get; internal set; } public EncounterPlan(string title, string advice, int uptimeBonus, params string[] enemies) { Title = title; Advice = advice; UptimeBonus = uptimeBonus; Enemies = Array.AsReadOnly(enemies); } } /// Authored encounter composition. Reads no random state; spawning owns stat rolls. public static class EncounterDirector { // A stable integer mixer, independent of both gameplay random streams and runtime hash codes. public static EncounterPlan Plan(int wave, WaveRoute route, int seed, int revision) { if (revision == 0) return Plan(wave, route); uint hash = unchecked((uint)seed ^ ((uint)wave * 0x9E3779B9u)); hash ^= hash >> 16; hash = unchecked(hash * 0x7FEB352Du); hash ^= hash >> 15; int variant = (int)(hash % 3); var baseline = Plan(wave, WaveRoute.Repair); string title = baseline.Title, advice = baseline.Advice; string[] enemies = new List(baseline.Enemies).ToArray(); if (variant > 0) { switch (wave) { case 1: title = variant == 1 ? "Stale services" : "Scheduled startup"; enemies = variant == 1 ? new[] { "zombie_process", "zombie_process" } : new[] { "zombie_process", "cron_job" }; advice = variant == 1 ? "Both Zombies can revive once. Finish weakened zombies decisively." : "The Zombie can revive once. Cron Job announces its heavy attack with a countdown."; break; case 2: title = variant == 1 ? "Leaking firewall" : "Orphan cleanup"; enemies = variant == 1 ? new[] { "firewalld", "memory_leak" } : new[] { "zombie_process", "segfault" }; advice = variant == 1 ? "Memory Leak grows each round while firewalld shields its neighbour." : "The Zombie can revive once. Segfault has a death payload; plan for the process it leaves behind."; break; case 3: title = variant == 1 ? "Hidden dependencies" : "Scheduled replication"; enemies = variant == 1 ? new[] { "rootkit", "zombie_process", "memory_leak" } : new[] { "fork_bomb", "cron_job", "zombie_process" }; advice = variant == 1 ? "Rootkit resists damage while allies remain. Clear its support while containing the growing Memory Leak." : "Fork Bomb copies itself after acting. Cron Job counts down to a heavy attack; stop their growth early."; break; case 4: title = variant == 1 ? "Protected concurrency" : "Leaking concurrency"; enemies = new[] { "race_condition", "race_condition", variant == 1 ? "firewalld" : "memory_leak" }; advice = "Race partners act in uncertain order; defeating one enrages the survivor. Choose between support and paired threats."; break; case RunJourney.BossWave: title = variant == 1 ? "Kernel Overseer / scheduled interrupt" : "Kernel Overseer / memory pressure"; enemies = new[] { "kernel_overseer", variant == 1 ? "cron_job" : "memory_leak" }; advice = baseline.Advice; break; } } var plan = new EncounterPlan(title, advice, baseline.UptimeBonus, enemies); if (wave > 1 && route == WaveRoute.Challenge) { int modifier = (int)((hash >> 8) % 3); var escort = new List(enemies) { "daemon" }; string detail = modifier == 0 ? "Veiled escort: damage the extra Daemon to reveal its intent." : modifier == 1 ? "Armored escort: the extra Daemon starts with 6 Shield; damage reveals its intent." : "Hardened escort: the extra Daemon has +4 Uptime; damage reveals its intent."; plan = new EncounterPlan(title + " / challenge", advice + " " + detail, baseline.UptimeBonus, escort.ToArray()) { EscortShield = modifier == 1 ? 6 : 0, EscortUptime = modifier == 2 ? 4 : 0 }; } return plan; } public static EncounterPlan Plan(int wave, WaveRoute route) { string title, advice; string[] enemies; switch (wave) { case 1: title = "Boot diagnostics"; advice = "Memory Leak grows each round. A Zombie can revive once: finish weakened zombies decisively."; enemies = new[] { "zombie_process", "memory_leak" }; break; case 2: title = "Firewall maintenance"; advice = "firewalld shields its neighbours. Cron Job counts down to a heavy attack."; enemies = new[] { "firewalld", "cron_job" }; break; case 3: title = "Process explosion"; advice = "Fork Bomb copies itself after acting. Stop it before the process table fills."; enemies = new[] { "fork_bomb", "memory_leak", "firewalld" }; break; case 4: title = "Concurrency fault"; advice = "Race partners attack in uncertain order; killing one enrages the survivor. Segfault has a death payload."; enemies = new[] { "race_condition", "race_condition", "segfault" }; break; case RunJourney.BossWave: title = "Kernel Overseer"; advice = "Boss cycle: shield, probe, heavy interrupt. At half uptime its NEXT announced attacks become stronger."; enemies = new[] { "kernel_overseer", "firewalld" }; break; default: title = "Endless / " + wave; advice = "Threats return in stronger combinations. Race partners remain paired."; enemies = (wave % 4) switch { 0 => new[] { "race_condition", "race_condition", "drm_guardian", "segfault" }, 1 => new[] { "kernel_overseer", "telemetry_collector", "firewalld" }, 2 => new[] { "rootkit", "fork_bomb", "cron_job", "memory_leak" }, _ => new[] { "kernel_panic", "daemon", "firewalld", "zombie_process" } }; break; } if (wave > 1 && route == WaveRoute.Challenge) { var harder = new List(enemies) { "daemon" }; enemies = harder.ToArray(); title += " / challenge"; advice += " An elite Daemon escorts this route; damage it to expose its intent."; } return new EncounterPlan(title, advice, Math.Max(0, wave - 1) * CombatTuning.EnemyUptimeGrowthPerWave, enemies); } } }