- Keep LifeSagaSession across Clear; wipe on map load/clear with bind key - Soft-bias Prefer/cross-MC/cast and prefer roster MCs in aftermath/recover/park - Resolve war/plot principals plus discrete/WorldLog labels from live libraries - Amortize roster world scans, gate Relayout, and add hitch probe/save-slot helpers
141 lines
3.1 KiB
C#
141 lines
3.1 KiB
C#
using HarmonyLib;
|
|
|
|
namespace IdleSpectator;
|
|
|
|
/// <summary>War genesis/end patches from mutation discovery.</summary>
|
|
[HarmonyPatch]
|
|
public static class WarEventPatches
|
|
{
|
|
[HarmonyPatch(typeof(WarManager), nameof(WarManager.newWar))]
|
|
[HarmonyPostfix]
|
|
public static void PostfixNewWar(War __result)
|
|
{
|
|
if (__result == null || !AgentHarness.LiveFeedsAllowed)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
WarInterestFeed.EmitFromWarObject(__result, phase: "new");
|
|
NoteWarPrincipals(__result, ended: false, provenance: "newWar");
|
|
}
|
|
catch
|
|
{
|
|
// Fallback: poll path still covers ongoing wars.
|
|
}
|
|
}
|
|
|
|
[HarmonyPatch(typeof(WarManager), nameof(WarManager.endWar))]
|
|
[HarmonyPostfix]
|
|
public static void PostfixEndWar(object[] __args)
|
|
{
|
|
if (!AgentHarness.LiveFeedsAllowed || __args == null || __args.Length == 0 || __args[0] == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
WarInterestFeed.EmitFromWarObject(__args[0], phase: "end");
|
|
if (__args[0] is War endedWar)
|
|
{
|
|
NoteWarPrincipals(endedWar, ended: true, provenance: "endWar");
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
private static void NoteWarPrincipals(War war, bool ended, string provenance)
|
|
{
|
|
if (war == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string warKey = "";
|
|
try
|
|
{
|
|
warKey = war.getID().ToString();
|
|
}
|
|
catch
|
|
{
|
|
warKey = "";
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(warKey))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Kingdom attacker = null;
|
|
Kingdom defender = null;
|
|
try
|
|
{
|
|
attacker = war.main_attacker;
|
|
defender = war.main_defender;
|
|
}
|
|
catch
|
|
{
|
|
attacker = null;
|
|
defender = null;
|
|
}
|
|
|
|
Actor attackKing = LiveEnsemble.PreferKingdomLeader(attacker);
|
|
Actor defendKing = LiveEnsemble.PreferKingdomLeader(defender);
|
|
if (attackKing == null)
|
|
{
|
|
try
|
|
{
|
|
attackKing = attacker?.king;
|
|
}
|
|
catch
|
|
{
|
|
attackKing = null;
|
|
}
|
|
}
|
|
|
|
if (defendKing == null)
|
|
{
|
|
try
|
|
{
|
|
defendKing = defender?.king;
|
|
}
|
|
catch
|
|
{
|
|
defendKing = null;
|
|
}
|
|
}
|
|
|
|
string attackName = KingdomName(attacker);
|
|
string defendName = KingdomName(defender);
|
|
LifeSagaMemory.RecordWarPrincipals(
|
|
attackKing,
|
|
defendKing,
|
|
warKey,
|
|
attackName,
|
|
defendName,
|
|
ended,
|
|
provenance);
|
|
}
|
|
|
|
private static string KingdomName(Kingdom kingdom)
|
|
{
|
|
if (kingdom == null)
|
|
{
|
|
return "";
|
|
}
|
|
|
|
try
|
|
{
|
|
return kingdom.name ?? "";
|
|
}
|
|
catch
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
}
|