mirror of
https://gitgud.io/amevarashi/rjw-sexperience-ideology.git
synced 2024-08-15 00:43:19 +00:00
Fix folders and namespaces (except for the Rituals)
This commit is contained in:
parent
17a8264b49
commit
075260f091
47 changed files with 46 additions and 138 deletions
7
Source/IdeologyAddon/HistoryEvents/ArgsNamesCustom.cs
Normal file
7
Source/IdeologyAddon/HistoryEvents/ArgsNamesCustom.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace RJWSexperience.Ideology.HistoryEvents
|
||||
{
|
||||
public static class ArgsNamesCustom
|
||||
{
|
||||
public const string Partner = "PARTNER";
|
||||
}
|
||||
}
|
|
@ -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>();
|
||||
}
|
||||
}
|
|
@ -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>();
|
||||
}
|
||||
}
|
|
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
16
Source/IdeologyAddon/HistoryEvents/TwoPawnEventRule.cs
Normal file
16
Source/IdeologyAddon/HistoryEvents/TwoPawnEventRule.cs
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue