From e1a817c55f6f08fc72bf52a375de0d278ee23519 Mon Sep 17 00:00:00 2001 From: c0ffee Date: Wed, 17 Nov 2021 09:59:06 -0800 Subject: [PATCH] added tracker for when pawn last ingested human milk --- CRIALactation/CRIALactation.csproj | 2 ++ .../Source/Comps/CompInduceLactation.cs | 4 +++ .../HarmonyPatch_FoodUtility.cs | 2 -- .../HarmonyPatches/HarmonyPatch_Thing.cs | 25 +++++++++++++++++ ...ThoughtWorker_Precept_NoRecentHumanMilk.cs | 27 +++++++++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 CRIALactation/Source/HarmonyPatches/HarmonyPatch_Thing.cs create mode 100644 CRIALactation/Source/Thoughts/ThoughtWorker_Precept_NoRecentHumanMilk.cs diff --git a/CRIALactation/CRIALactation.csproj b/CRIALactation/CRIALactation.csproj index 7ee399b..4105640 100644 --- a/CRIALactation/CRIALactation.csproj +++ b/CRIALactation/CRIALactation.csproj @@ -76,6 +76,7 @@ + @@ -93,6 +94,7 @@ + diff --git a/CRIALactation/Source/Comps/CompInduceLactation.cs b/CRIALactation/Source/Comps/CompInduceLactation.cs index be442d2..bda7a63 100644 --- a/CRIALactation/Source/Comps/CompInduceLactation.cs +++ b/CRIALactation/Source/Comps/CompInduceLactation.cs @@ -16,9 +16,12 @@ namespace CRIALactation private int TicksSinceLastMassage = -60000; private float InductionCompletionPercent = 0f; + public bool isActive = false; public bool CanMassage = true; + public int lastHumanLactationIngestedTick = 0; + public override void CompTick() { base.CompTick(); @@ -107,6 +110,7 @@ namespace CRIALactation base.PostExposeData(); Scribe_Values.Look(ref this.InductionCompletionPercent, "InductionCompletionPercent", 0f); Scribe_Values.Look(ref this.TicksSinceLastMassage, "TicksSinceLastMassage", -60000); + Scribe_Values.Look(ref this.lastHumanLactationIngestedTick, "lastHumanLactationIngestedTick", 0); Scribe_Values.Look(ref this.isActive, "IsActive", false); Scribe_Values.Look(ref this.CanMassage, "CanMassage", false); diff --git a/CRIALactation/Source/HarmonyPatches/HarmonyPatch_FoodUtility.cs b/CRIALactation/Source/HarmonyPatches/HarmonyPatch_FoodUtility.cs index 0cfb0ee..c60c105 100644 --- a/CRIALactation/Source/HarmonyPatches/HarmonyPatch_FoodUtility.cs +++ b/CRIALactation/Source/HarmonyPatches/HarmonyPatch_FoodUtility.cs @@ -53,11 +53,9 @@ namespace CRIALactation AddThoughtsFromIdeo_Patch(HistoryEventDefOf_Milk.DrankMilkMeal, ingester, ingredient, meatSourceCategory); } - } } - } } diff --git a/CRIALactation/Source/HarmonyPatches/HarmonyPatch_Thing.cs b/CRIALactation/Source/HarmonyPatches/HarmonyPatch_Thing.cs new file mode 100644 index 0000000..e77e30f --- /dev/null +++ b/CRIALactation/Source/HarmonyPatches/HarmonyPatch_Thing.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; +using RimWorld; + +namespace CRIALactation +{ + [HarmonyPatch(typeof(Thing), "Ingested")] + public static class HarmonyPatch_Thing + { + public static void Prefix(Thing __instance, Pawn ingester) + { + + if(__instance.def == ThingDefOf_Milk.HumanMilk || __instance.def == ThingDefOf_Milk.HumanoidMilk) + { + ingester.TryGetComp().lastHumanLactationIngestedTick = Find.TickManager.TicksGame; + } + + } + } +} diff --git a/CRIALactation/Source/Thoughts/ThoughtWorker_Precept_NoRecentHumanMilk.cs b/CRIALactation/Source/Thoughts/ThoughtWorker_Precept_NoRecentHumanMilk.cs new file mode 100644 index 0000000..cf208d8 --- /dev/null +++ b/CRIALactation/Source/Thoughts/ThoughtWorker_Precept_NoRecentHumanMilk.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Verse; +using RimWorld; +using UnityEngine; + +namespace CRIALactation +{ + public class ThoughtWorker_Precept_NoRecentHumanMilk : ThoughtWorker_Precept, IPreceptCompDescriptionArgs + { + public IEnumerable GetDescriptionArgs() + { + yield return MinDaysSinceLastHumanMeatForThought.Named("HUMANMILKREQUIREDINTERVAL"); + } + + protected override ThoughtState ShouldHaveThought(Pawn p) + { + int num = Mathf.Max(0, p.TryGetComp().lastHumanLactationIngestedTick); + return Find.TickManager.TicksGame - num > 480000; + } + + public const int MinDaysSinceLastHumanMeatForThought = 8; + } +}