88 lines
4.7 KiB
C#
88 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace KernelPanic.Run
|
|
{
|
|
public enum WaveRoute { Repair, Challenge, Encounter, Cache, Forge, Sacrifice, Recycle }
|
|
|
|
/// <summary>Serializable route decisions, independent of combat and repository presentation.</summary>
|
|
[Serializable]
|
|
public sealed class RunJourney
|
|
{
|
|
public const int BossWave = 10;
|
|
public const int LegacyBossWave = 5;
|
|
public const int RepairUptime = 6;
|
|
public const int ChallengeBits = 8;
|
|
public bool campaign;
|
|
public bool endless;
|
|
public WaveRoute selectedRoute;
|
|
public WaveRoute activeRoute;
|
|
public string lastReward;
|
|
public int encounterRevision;
|
|
public int pendingRewardWave;
|
|
public int claimedRewardWave;
|
|
public int mapRevision;
|
|
public int mapStartWave = 2;
|
|
public int selectedNodeId;
|
|
public int resolvedEventWave;
|
|
public string eventOutcome;
|
|
public List<RouteVisit> visits = new();
|
|
|
|
// Revisions are persisted: an existing route must never change underneath its saved decisions.
|
|
public int FinalWave => encounterRevision >= 2 ? BossWave : LegacyBossWave;
|
|
public bool IsRewardWave(int wave) => encounterRevision > 0 && wave >= 2 && wave < FinalWave && wave % 2 == 0;
|
|
public bool AtMilestone(int wavesCleared) => campaign && !endless && wavesCleared >= FinalWave;
|
|
public static RunJourney NewCampaign() => new() { campaign = true, encounterRevision = 4, mapRevision = 2 };
|
|
public RunJourney Copy()
|
|
{
|
|
var copy = (RunJourney)MemberwiseClone();
|
|
copy.visits = (visits ?? new List<RouteVisit>()).Select(v => v.Copy()).ToList();
|
|
return copy;
|
|
}
|
|
|
|
public void Validate(int wave)
|
|
{
|
|
RunCheckpoint.Require(encounterRevision >= 0 && encounterRevision <= 4, "Unsupported encounter revision.");
|
|
RunCheckpoint.Require((pendingRewardWave == 0 || IsRewardWave(pendingRewardWave))
|
|
&& (claimedRewardWave == 0 || IsRewardWave(claimedRewardWave))
|
|
&& claimedRewardWave < wave
|
|
&& (pendingRewardWave == 0 || (campaign && encounterRevision > 0
|
|
&& pendingRewardWave == wave - 1 && pendingRewardWave > claimedRewardWave)), "Invalid saved reward choice.");
|
|
RunCheckpoint.Require(Enum.IsDefined(typeof(WaveRoute), selectedRoute)
|
|
&& Enum.IsDefined(typeof(WaveRoute), activeRoute), "Invalid saved route.");
|
|
RunCheckpoint.Require(!endless || (campaign && wave > FinalWave), "Invalid endless-mode checkpoint.");
|
|
RunCheckpoint.Require(!campaign || endless || wave <= FinalWave + 1, "Missing campaign completion choice.");
|
|
RunCheckpoint.Require(mapRevision >= 0 && mapRevision <= 2, "Unsupported route map.");
|
|
if (mapRevision == 0) return;
|
|
RunCheckpoint.Require(campaign && mapStartWave >= 2 && mapStartWave <= wave,
|
|
"Invalid route map start.");
|
|
RunCheckpoint.Require(visits != null && visits.Count <= wave && visits.All(v => v != null
|
|
&& v.wave >= mapStartWave && v.wave < wave && v.nodeId / 10 == v.wave
|
|
&& Enum.IsDefined(typeof(WaveRoute), v.route) && v.cleared), "Invalid route history.");
|
|
RunCheckpoint.Require(visits.Select(v => v.wave).Distinct().Count() == visits.Count,
|
|
"Duplicate route history.");
|
|
RunCheckpoint.Require(resolvedEventWave == 0 || resolvedEventWave == wave,
|
|
"Invalid route event claim.");
|
|
}
|
|
|
|
public void ValidateMap(int seed, int wave)
|
|
{
|
|
if (mapRevision == 0) return;
|
|
RouteNode previous = null;
|
|
foreach (var visit in visits)
|
|
{
|
|
var node = RunRouteMap.Row(seed, visit.wave, mapStartWave, mapRevision).FirstOrDefault(n => n.Id == visit.nodeId);
|
|
RunCheckpoint.Require(node != null && node.Route == visit.route
|
|
&& (previous == null ? visit.wave == mapStartWave : RunRouteMap.Connected(seed, previous, node, mapStartWave, mapRevision)),
|
|
"Disconnected route history.");
|
|
previous = node;
|
|
}
|
|
RunCheckpoint.Require(visits.Count == Math.Max(0, wave - mapStartWave), "Incomplete route history.");
|
|
var selected = RunRouteMap.Available(seed, wave, this).FirstOrDefault(n => n.Id == selectedNodeId);
|
|
RunCheckpoint.Require(selected != null && selected.Route == selectedRoute, "Unavailable saved route.");
|
|
RunCheckpoint.Require(resolvedEventWave == 0 || RunRouteMap.IsEvent(selectedRoute), "Unexpected event claim.");
|
|
}
|
|
}
|
|
}
|