Files
linuxdistro-roguelite/Assets/Scripts/Combat/EncounterDirector.cs
T
2026-10-29 22:54:29 +01:00

227 lines
16 KiB
C#

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<string> 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); }
}
/// <summary>Authored encounter composition. Reads no random state; spawning owns stat rolls.</summary>
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 >= 4 && wave >= 2 && wave <= RunJourney.BossWave) return SpecialistPlan(wave, route, seed);
if (revision >= 3 && wave >= 5 && wave <= 9) return VariedCampaignPlan(wave, route, seed);
if (revision >= 2) return CampaignPlan(wave, route, seed);
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<string>(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.LegacyBossWave:
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<string>(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 + " (elite)", advice + " " + detail, baseline.UptimeBonus, escort.ToArray())
{ EscortShield = modifier == 1 ? 6 : 0, EscortUptime = modifier == 2 ? 4 : 0 };
}
return plan;
}
private static EncounterPlan SpecialistPlan(int wave, WaveRoute route, int seed)
{
uint hash = unchecked((uint)seed * 0x9E3779B9u + (uint)wave * 0x7FEB352Du);
hash ^= hash >> 16;
int variant = (int)(hash % 3);
var baseline = Plan(wave, route, seed, 3);
if (wave == RunJourney.BossWave)
{
if (variant == 0) return baseline;
return variant == 1
? new EncounterPlan("Process Supervisor", "Cycle: summon two workers, Shield, interrupt. Workers accumulate up to eight living processes; clear them with area damage or race the supervisor. At half Uptime its next attacks gain 3 damage.", baseline.UptimeBonus, "process_supervisor", "firewalld")
: new EncounterPlan("OOM Reaper", "Two RAM are unavailable while the Reaper lives. Cycle: charge with Shield, 14-damage OOM kill, weak recovery attack. Prepare defense for the burst; at half Uptime its next attacks gain 3 damage.", baseline.UptimeBonus, "oom_reaper", "cron_job");
}
if (route != WaveRoute.Challenge || variant == 0) return baseline;
var standard = Plan(wave, WaveRoute.Repair, seed, 3);
var enemies = new List<string>(standard.Enemies) { variant == 1 ? "watchdog" : "process_broker" };
string advice = variant == 1
? "Watchdog escort: two countdown turns, then 12-14 damage. Defeat it before timeout or bank Shield."
: "Process Broker escort: alternates summoning a worker and attacking. Workers accumulate up to eight living processes; stop the broker early.";
return new EncounterPlan(standard.Title + " (elite)", standard.Advice + " " + advice, standard.UptimeBonus, enemies.ToArray());
}
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.LegacyBossWave:
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 " + 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<string>(enemies) { "daemon" };
enemies = harder.ToArray();
title += " (elite)";
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);
}
private static EncounterPlan VariedCampaignPlan(int wave, WaveRoute route, int seed)
{
uint hash = unchecked((uint)seed ^ ((uint)wave * 0x9E3779B9u));
hash ^= hash >> 16; hash = unchecked(hash * 0x7FEB352Du); hash ^= hash >> 15;
int variant = (int)(hash % 3);
if (variant == 0) return CampaignPlan(wave, route, seed);
var baseline = CampaignPlan(wave, route, seed);
var (title, advice, enemies) = (wave, variant) switch
{
(5, 1) => ("Replicating privileges", "Fork Bomb copies itself after acting. Kill it early to expose Rootkit, which resists damage while allies remain.", new[] { "rootkit", "fork_bomb", "zombie_process" }),
(5, _) => ("Scheduled escalation", "Cron Job counts down while Memory Leak grows. Remove urgent threats to expose Rootkit.", new[] { "rootkit", "cron_job", "memory_leak" }),
(6, 1) => ("Protected telemetry", "Firewalld protects Telemetry Collector. Break through Shield before resource interference wears down your build.", new[] { "telemetry_collector", "firewalld", "zombie_process" }),
(6, _) => ("Scheduled collection", "Telemetry Collector interferes with resources while two Cron Jobs count down. Front-load damage or prepare defense for their heavy attacks.", new[] { "telemetry_collector", "cron_job", "cron_job" }),
(7, 1) => ("Growing restrictions", "DRM Guardian and Firewalld shelter a growing Memory Leak. Pick a target you can finish before its next turn.", new[] { "drm_guardian", "firewalld", "memory_leak" }),
(7, _) => ("Licensed replication", "Fork Bomb multiplies behind DRM Guardian's defenses. Segfault leaves a death payload; reserve damage for the process it creates.", new[] { "drm_guardian", "fork_bomb", "segfault" }),
(8, 1) => ("Leaking concurrency", "Race partners can swap order and the survivor enrages. Memory Leak grows each round; balance paired kills against stopping its growth.", new[] { "race_condition", "race_condition", "memory_leak" }),
(8, _) => ("Veiled concurrency", "Damage the Daemon to reveal its committed action. Race partners can swap order; killing one enrages the survivor.", new[] { "race_condition", "race_condition", "daemon" }),
(9, 1) => ("Leaking kernel", "Kernel Panic pressures RAM while Memory Leak grows. Firewalld adds defense; use efficient attacks and leave room to draw.", new[] { "kernel_panic", "memory_leak", "firewalld" }),
_ => ("Scheduled panic", "Kernel Panic pressures RAM, Cron Job counts down, and Segfault leaves a death payload. Save a follow-up for the new process.", new[] { "kernel_panic", "cron_job", "segfault" })
};
var composition = new List<string>(enemies);
if (route == WaveRoute.Challenge)
{
composition.Add("daemon"); title += " (elite)";
advice += baseline.EscortShield > 0 ? " Extra Daemon: 6 starting Shield, hidden intent."
: baseline.EscortUptime > 0 ? " Extra Daemon: +4 Uptime, hidden intent." : " Extra Daemon: hidden intent.";
}
return new EncounterPlan(title, advice, baseline.UptimeBonus, composition.ToArray())
{ EscortShield = baseline.EscortShield, EscortUptime = baseline.EscortUptime };
}
private static EncounterPlan CampaignPlan(int wave, WaveRoute route, int seed)
{
// Keep introductory encounters familiar; introduce the heavier systems before the final boss.
int legacyStage = wave <= 4 ? wave : wave == RunJourney.BossWave ? RunJourney.LegacyBossWave
: wave > RunJourney.BossWave ? wave - 5 : 3;
var baseline = Plan(legacyStage, route, seed, 1);
string title = baseline.Title, advice = baseline.Advice;
var enemies = new List<string>(baseline.Enemies);
string support = unchecked((uint)seed + (uint)wave) % 2 == 0 ? "firewalld" : "cron_job";
switch (wave)
{
case 5:
title = "Privilege escalation";
advice = "Rootkit resists damage while allies remain. Remove its support first.";
enemies = new() { "rootkit", "zombie_process", support }; break;
case 6:
title = "Telemetry breach";
advice = "Telemetry Collector interferes with your resources. Contain the growing Memory Leak.";
enemies = new() { "telemetry_collector", "memory_leak", support }; break;
case 7:
title = "Protected subsystem";
advice = "DRM Guardian protects the subsystem. Plan your damage around its defenses.";
enemies = new() { "drm_guardian", "segfault", support }; break;
case 8:
title = "Critical concurrency";
advice = "Race partners act in uncertain order; defeating one enrages the survivor. Remove their support deliberately.";
enemies = new() { "race_condition", "race_condition", support }; break;
case 9:
title = "Kernel perimeter";
advice = "Kernel Panic pressures your RAM. Clear this last perimeter before the Overseer.";
enemies = new() { "kernel_panic", "daemon", support }; break;
}
if (wave >= 5 && wave < RunJourney.BossWave && route == WaveRoute.Challenge)
{
enemies.Add("daemon"); title += " (elite)";
advice += baseline.EscortShield > 0 ? " Extra Daemon: 6 starting Shield, hidden intent."
: baseline.EscortUptime > 0 ? " Extra Daemon: +4 Uptime, hidden intent." : " Extra Daemon: hidden intent.";
}
if (wave > RunJourney.BossWave) title = "Survival wave " + wave;
return new EncounterPlan(title, advice, Math.Max(0, wave - 1) * CombatTuning.EnemyUptimeGrowthPerWave, enemies.ToArray())
{ EscortShield = baseline.EscortShield, EscortUptime = baseline.EscortUptime };
}
}
}