Fix folders and namespaces (except for the Rituals)

This commit is contained in:
amevarashi 2022-10-14 21:35:31 +05:00
parent 17a8264b49
commit 075260f091
47 changed files with 46 additions and 138 deletions

View file

@ -0,0 +1,7 @@
namespace RJWSexperience.Ideology.HistoryEvents
{
public static class ArgsNamesCustom
{
public const string Partner = "PARTNER";
}
}

View file

@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology.HistoryEvents
{
public class DefExtension_EventOverrides : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<TwoPawnEventRule> overrideRules = new List<TwoPawnEventRule>();
}
}

View file

@ -0,0 +1,12 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology.HistoryEvents
{
public class DefExtension_SecondaryEvents : DefModExtension
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public List<TwoPawnEventRule> generationRules = new List<TwoPawnEventRule>();
}
}

View file

@ -0,0 +1,54 @@
using RimWorld;
using Verse;
using System.Linq;
using System.Collections.Generic;
namespace RJWSexperience.Ideology.HistoryEvents
{
public static class HistoryEventDefExtensionMethods
{
public static void RecordEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
{
//Log.Message($"[RSI] Recording event {def.ToStringWithPartner(pawn, partner)}");
List<TwoPawnEventRule> secondaryEventRules = def.GetModExtension<DefExtension_SecondaryEvents>()?.generationRules;
if (!secondaryEventRules.NullOrEmpty())
{
//Log.Message($"[RSI] Event has {secondaryEventRules?.Count} secondary events");
foreach (var rule in secondaryEventRules.Where(rule => rule.Applies(pawn, partner)))
{
//Log.Message($"[RSI] Recording secondary event {def.defName}");
rule.historyEventDef.RecordEventWithPartner(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)
{
return new HistoryEvent(def, pawn.Named(HistoryEventArgsNames.Doer));
}
public static HistoryEvent CreateEventWithPartner(this HistoryEventDef def, Pawn pawn, Pawn partner)
{
//Log.Message($"[RSI] Creating event {def.ToStringWithPartner(pawn, partner)}");
HistoryEventDef overrideEvent = def.GetModExtension<DefExtension_EventOverrides>()?.overrideRules.FirstOrFallback(rule => rule.Applies(pawn, partner))?.historyEventDef;
if (overrideEvent != null)
{
//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}";
}
}
}

View file

@ -0,0 +1,16 @@
using RimWorld;
using System.Diagnostics.CodeAnalysis;
using Verse;
namespace RJWSexperience.Ideology.HistoryEvents
{
public class TwoPawnEventRule
{
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public HistoryEventDef historyEventDef;
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
public TwoPawnFilter filter;
public bool Applies(Pawn pawn, Pawn partner) => filter?.Applies(pawn, partner) == true;
}
}