RJW-Sexperience/RJWSexperience/IdeologyAddon/Ideology/Precepts/PreceptComp_SelftTookThoughtExtended.cs

66 lines
2.3 KiB
C#
Raw Normal View History

2022-02-25 14:15:48 +00:00
using RimWorld;
2022-04-15 16:46:29 +00:00
using System.Diagnostics.CodeAnalysis;
2021-07-27 14:28:31 +00:00
using Verse;
2022-06-19 13:26:35 +00:00
namespace RJWSexperience.Ideology.Precepts
2021-07-27 14:28:31 +00:00
{
public class PreceptComp_SelfTookThoughtTagged : PreceptComp_SelfTookMemoryThought
{
2022-04-15 16:46:29 +00:00
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
2021-07-27 14:28:31 +00:00
public string tag;
2022-04-15 16:46:29 +00:00
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
2021-07-27 14:28:31 +00:00
public bool exclusive = false;
public PreceptComp_SelfTookThoughtTagged() { }
public override void Notify_MemberTookAction(HistoryEvent ev, Precept precept, bool canApplySelfTookThoughts)
{
if (tag != null)
2022-02-25 14:15:48 +00:00
{
2021-07-27 14:28:31 +00:00
if (ev.args.TryGetArg(HistoryEventArgsNamesCustom.Tag, out string tags))
{
2022-02-25 14:15:48 +00:00
if (IdeoUtility.ContainAll(tags, tag.Replace(" ", "").Split(',')) ^ exclusive)
{
2021-07-30 17:25:46 +00:00
TookThought(ev, precept, canApplySelfTookThoughts);
}
2021-07-27 14:28:31 +00:00
}
else if (exclusive)
{
2021-07-30 17:25:46 +00:00
TookThought(ev, precept, canApplySelfTookThoughts);
2021-07-27 14:28:31 +00:00
}
}
2022-02-25 14:15:48 +00:00
else
{
2021-07-30 17:25:46 +00:00
TookThought(ev, precept, canApplySelfTookThoughts);
2021-07-27 14:28:31 +00:00
}
}
2021-07-30 17:25:46 +00:00
protected virtual void TookThought(HistoryEvent ev, Precept precept, bool canApplySelfTookThoughts)
2022-02-25 14:15:48 +00:00
{
2021-07-30 17:25:46 +00:00
if (ev.def != this.eventDef || !canApplySelfTookThoughts)
{
return;
}
Pawn arg = ev.args.GetArg<Pawn>(HistoryEventArgsNames.Doer);
Pawn partner = ev.args.GetArg<Pawn>(HistoryEventArgsNamesCustom.Partner);
2022-04-15 16:46:29 +00:00
if (arg.needs?.mood != null && (!this.onlyForNonSlaves || !arg.IsSlave))
2021-07-30 17:25:46 +00:00
{
if (this.thought.minExpectationForNegativeThought != null && ExpectationsUtility.CurrentExpectationFor(arg).order < this.thought.minExpectationForNegativeThought.order)
{
return;
}
Thought_Memory thought_Memory = ThoughtMaker.MakeThought(this.thought, precept);
2022-04-15 16:46:29 +00:00
if (thought_Memory is Thought_KilledInnocentAnimal thought_KilledInnocentAnimal && ev.args.TryGetArg<Pawn>(HistoryEventArgsNames.Victim, out Pawn animal))
2021-07-30 17:25:46 +00:00
{
thought_KilledInnocentAnimal.SetAnimal(animal);
}
2022-04-15 16:46:29 +00:00
if (thought_Memory is Thought_MemoryObservation thought_MemoryObservation && ev.args.TryGetArg<Corpse>(HistoryEventArgsNames.Subject, out Corpse target))
2021-07-30 17:25:46 +00:00
{
thought_MemoryObservation.Target = target;
}
arg.needs.mood.thoughts.memories.TryGainMemory(thought_Memory, partner);
}
}
2021-07-27 14:28:31 +00:00
}
}