2022-07-26 03:55:56 +00:00
|
|
|
|
using RimWorld;
|
|
|
|
|
using Verse;
|
2022-08-09 16:30:33 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
2023-11-06 11:28:08 +00:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2022-07-26 03:55:56 +00:00
|
|
|
|
|
|
|
|
|
namespace RJWSexperience.Ideology.HistoryEvents
|
|
|
|
|
{
|
|
|
|
|
public static class HistoryEventDefExtensionMethods
|
|
|
|
|
{
|
|
|
|
|
public static void RecordEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
|
|
|
|
{
|
2022-08-09 16:30:33 +00:00
|
|
|
|
//Log.Message($"[RSI] Recording event {def.ToStringWithPartner(pawn, partner)}");
|
|
|
|
|
List<TwoPawnEventRule> secondaryEventRules = def.GetModExtension<DefExtension_SecondaryEvents>()?.generationRules;
|
2022-07-26 03:55:56 +00:00
|
|
|
|
|
2022-08-09 16:30:33 +00:00
|
|
|
|
if (!secondaryEventRules.NullOrEmpty())
|
2022-07-26 03:55:56 +00:00
|
|
|
|
{
|
2022-08-09 16:30:33 +00:00
|
|
|
|
//Log.Message($"[RSI] Event has {secondaryEventRules?.Count} secondary events");
|
|
|
|
|
foreach (var rule in secondaryEventRules.Where(rule => rule.Applies(pawn, partner)))
|
2022-07-26 03:55:56 +00:00
|
|
|
|
{
|
2022-08-09 16:30:33 +00:00
|
|
|
|
//Log.Message($"[RSI] Recording secondary event {def.defName}");
|
|
|
|
|
rule.historyEventDef.RecordEventWithPartner(pawn, partner);
|
2022-07-26 03:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-09 16:30:33 +00:00
|
|
|
|
HistoryEvent historyEvent = def.CreateEventWithPartner(pawn, partner);
|
|
|
|
|
Find.HistoryEventsManager.RecordEvent(historyEvent);
|
|
|
|
|
//Log.Message($"[RSI] Recorded event {historyEvent.def.ToStringWithPartner(pawn, partner)}");
|
2022-07-26 03:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 11:28:08 +00:00
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2022-07-26 03:55:56 +00:00
|
|
|
|
public static HistoryEvent CreateEvent(this HistoryEventDef def, Pawn pawn)
|
|
|
|
|
{
|
|
|
|
|
return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static HistoryEvent CreateEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
|
|
|
|
{
|
2022-08-09 16:30:33 +00:00
|
|
|
|
//Log.Message($"[RSI] Creating event {def.ToStringWithPartner(pawn, partner)}");
|
|
|
|
|
HistoryEventDef overrideEvent = def.GetModExtension<DefExtension_EventOverrides>()?.overrideRules.FirstOrFallback(rule => rule.Applies(pawn, partner))?.historyEventDef;
|
2022-07-26 03:55:56 +00:00
|
|
|
|
|
2022-08-09 16:30:33 +00:00
|
|
|
|
if (overrideEvent != null)
|
2022-07-26 03:55:56 +00:00
|
|
|
|
{
|
2022-08-09 16:30:33 +00:00
|
|
|
|
//Log.Message($"[RSI] Event overridden by {overrideEvent.ToStringWithPartner(pawn, partner)}");
|
|
|
|
|
return overrideEvent.CreateEventWithPartner(pawn, partner);
|
2022-07-26 03:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer), partner.Named(ArgsNamesCustom.Partner));
|
|
|
|
|
}
|
2022-08-09 16:30:33 +00:00
|
|
|
|
|
|
|
|
|
private static string ToStringWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
|
|
|
|
{
|
|
|
|
|
return $"{def.defName}, doer {pawn.NameShortColored}, partner {partner.NameShortColored}";
|
|
|
|
|
}
|
2022-07-26 03:55:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|