mirror of
https://gitgud.io/amevarashi/rjw-sexperience-ideology.git
synced 2024-08-15 00:43:19 +00:00
Refactor HistoryEventDefExtensionMethods
This commit is contained in:
parent
1323f5b270
commit
2f9bd5bbf9
1 changed files with 22 additions and 13 deletions
|
@ -1,5 +1,7 @@
|
|||
using RimWorld;
|
||||
using Verse;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RJWSexperience.Ideology.HistoryEvents
|
||||
{
|
||||
|
@ -7,18 +9,22 @@ namespace RJWSexperience.Ideology.HistoryEvents
|
|||
{
|
||||
public static void RecordEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
||||
{
|
||||
DefExtension_SecondaryEvents secondaryEvents = def.GetModExtension<DefExtension_SecondaryEvents>();
|
||||
//Log.Message($"[RSI] Recording event {def.ToStringWithPartner(pawn, partner)}");
|
||||
List<TwoPawnEventRule> secondaryEventRules = def.GetModExtension<DefExtension_SecondaryEvents>()?.generationRules;
|
||||
|
||||
if (secondaryEvents != null)
|
||||
if (!secondaryEventRules.NullOrEmpty())
|
||||
{
|
||||
foreach (TwoPawnEventRule rule in secondaryEvents.generationRules)
|
||||
//Log.Message($"[RSI] Event has {secondaryEventRules?.Count} secondary events");
|
||||
foreach (var rule in secondaryEventRules.Where(rule => rule.Applies(pawn, partner)))
|
||||
{
|
||||
if (rule.Applies(pawn, partner))
|
||||
rule.historyEventDef.RecordEventWithPartner(pawn, partner);
|
||||
//Log.Message($"[RSI] Recording secondary event {def.defName}");
|
||||
rule.historyEventDef.RecordEventWithPartner(pawn, partner);
|
||||
}
|
||||
}
|
||||
|
||||
Find.HistoryEventsManager.RecordEvent(def.CreateEventWithPartner(pawn, partner));
|
||||
HistoryEvent historyEvent = def.CreateEventWithPartner(pawn, partner);
|
||||
Find.HistoryEventsManager.RecordEvent(historyEvent);
|
||||
//Log.Message($"[RSI] Recorded event {historyEvent.def.ToStringWithPartner(pawn, partner)}");
|
||||
}
|
||||
|
||||
public static HistoryEvent CreateEvent(this HistoryEventDef def, Pawn pawn)
|
||||
|
@ -28,18 +34,21 @@ namespace RJWSexperience.Ideology.HistoryEvents
|
|||
|
||||
public static HistoryEvent CreateEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
||||
{
|
||||
DefExtension_EventOverrides overrides = def.GetModExtension<DefExtension_EventOverrides>();
|
||||
//Log.Message($"[RSI] Creating event {def.ToStringWithPartner(pawn, partner)}");
|
||||
HistoryEventDef overrideEvent = def.GetModExtension<DefExtension_EventOverrides>()?.overrideRules.FirstOrFallback(rule => rule.Applies(pawn, partner))?.historyEventDef;
|
||||
|
||||
if (overrides == null)
|
||||
return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer), partner.Named(ArgsNamesCustom.Partner));
|
||||
|
||||
foreach (TwoPawnEventRule rule in overrides.overrideRules)
|
||||
if (overrideEvent != null)
|
||||
{
|
||||
if (rule.Applies(pawn, partner))
|
||||
return rule.historyEventDef.CreateEventWithPartner(pawn, partner);
|
||||
//Log.Message($"[RSI] Event overridden by {overrideEvent.ToStringWithPartner(pawn, partner)}");
|
||||
return overrideEvent.CreateEventWithPartner(pawn, partner);
|
||||
}
|
||||
|
||||
return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer), partner.Named(ArgsNamesCustom.Partner));
|
||||
}
|
||||
|
||||
private static string ToStringWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
|
||||
{
|
||||
return $"{def.defName}, doer {pawn.NameShortColored}, partner {partner.NameShortColored}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue