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

118 lines
4.1 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;
2021-08-21 16:29:59 +00:00
namespace RJWSexperience.Ideology
2021-07-27 14:28:31 +00:00
{
public static class HistoryEventArgsNamesCustom
{
public const string Tag = "TAG";
public const string Partner = "PARTNER";
}
public static class HETag
2022-02-25 14:15:48 +00:00
{
2021-07-27 14:28:31 +00:00
public const string Incestous = "[Incestuos]";
2021-07-30 17:25:46 +00:00
public const string BeenRaped = "[BeenRaped]";
2021-07-27 14:28:31 +00:00
public const string Rape = "[Rape]";
2021-09-24 15:14:02 +00:00
public const string Spouse = "[Spouse]";
public const string NotSpouse = "[NotSpouse]";
2021-07-30 17:25:46 +00:00
public static string Gender(Pawn pawn) => "[" + pawn.gender + "]";
2022-02-25 14:15:48 +00:00
}
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
}
public class PreceptComp_KnowsMemoryThoughtTagged : PreceptComp_KnowsMemoryThought
2022-02-25 14:15:48 +00:00
{
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;
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 applyonpartner = false;
public PreceptComp_KnowsMemoryThoughtTagged() { }
public override void Notify_MemberWitnessedAction(HistoryEvent ev, Precept precept, Pawn member)
2022-02-25 14:15:48 +00:00
{
2022-04-15 16:46:29 +00:00
if (!applyonpartner && ev.args.TryGetArg(HistoryEventArgsNamesCustom.Partner, out Pawn pawn) && pawn == member)
2022-02-25 14:15:48 +00:00
{
2022-04-15 16:46:29 +00:00
return;
2022-02-25 14:15:48 +00:00
}
2021-07-27 14:28:31 +00:00
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) base.Notify_MemberWitnessedAction(ev, precept, member);
2021-07-27 14:28:31 +00:00
}
else if (exclusive)
{
base.Notify_MemberWitnessedAction(ev, precept, member);
}
}
else
2022-02-25 14:15:48 +00:00
{
2021-07-27 14:28:31 +00:00
base.Notify_MemberWitnessedAction(ev, precept, member);
2022-02-25 14:15:48 +00:00
}
}
}
2021-07-27 14:28:31 +00:00
}