From 8a48d2e463fe360412cdb3b11238166a9f0d4ee8 Mon Sep 17 00:00:00 2001 From: amevarashi Date: Mon, 17 Apr 2023 14:17:07 +0500 Subject: [PATCH] Optimized Ate Cum thought --- 1.4/Defs/ThoughtDefs/Thoughts_ate.xml | 4 +- Source/RJWSexperience/Cum/Thought_AteCum.cs | 34 +++----------- .../SexHistory/UI/SexStatusWindow.cs | 2 - .../ThoughtDefExtension_StageFromRecord.cs | 44 ++++++++++++++++++- .../Thoughts/Thought_Recordbased.cs | 33 +++++--------- 5 files changed, 61 insertions(+), 56 deletions(-) diff --git a/1.4/Defs/ThoughtDefs/Thoughts_ate.xml b/1.4/Defs/ThoughtDefs/Thoughts_ate.xml index 0bbeb15..b8e9d60 100644 --- a/1.4/Defs/ThoughtDefs/Thoughts_ate.xml +++ b/1.4/Defs/ThoughtDefs/Thoughts_ate.xml @@ -15,12 +15,12 @@
  • - Tastes bad and stinky. + It's stinky and tastes bad. -2
  • - Tastes bad. But i liked it. + Tastes bad. But I liked it. 1
  • diff --git a/Source/RJWSexperience/Cum/Thought_AteCum.cs b/Source/RJWSexperience/Cum/Thought_AteCum.cs index d309521..79fc834 100644 --- a/Source/RJWSexperience/Cum/Thought_AteCum.cs +++ b/Source/RJWSexperience/Cum/Thought_AteCum.cs @@ -1,39 +1,17 @@ -using RimWorld; - -namespace RJWSexperience // Change in namespace will lead to save incompatibility +namespace RJWSexperience // Change in namespace will lead to save incompatibility { public class Thought_AteCum : Thought_Recordbased { - public override int CurStageIndex + protected override void UpdateCurStage() { - get + if (pawn?.health?.hediffSet?.HasHediff(VariousDefOf.CumAddiction) ?? false) { - if (pawn?.health?.hediffSet?.HasHediff(VariousDefOf.CumAddiction) ?? false) - return def.stages.Count - 1; - return base.CurStageIndex; + SetForcedStage(def.stages.Count - 1); } - } - - public override bool TryMergeWithExistingMemory(out bool showBubble) - { - ThoughtHandler thoughts = pawn.needs.mood.thoughts; - if (thoughts.memories.NumMemoriesInGroup(this) >= def.stackLimit) + else { - Thought_AteCum thought_Memory = (Thought_AteCum)thoughts.memories.OldestMemoryInGroup(this); - if (thought_Memory != null) - { - showBubble = thought_Memory.age > thought_Memory.def.DurationTicks / 2; - thought_Memory.Merged(); - return true; - } + base.UpdateCurStage(); } - showBubble = true; - return false; - } - - protected virtual void Merged() - { - age = 0; } } } diff --git a/Source/RJWSexperience/SexHistory/UI/SexStatusWindow.cs b/Source/RJWSexperience/SexHistory/UI/SexStatusWindow.cs index fedb84b..f684891 100644 --- a/Source/RJWSexperience/SexHistory/UI/SexStatusWindow.cs +++ b/Source/RJWSexperience/SexHistory/UI/SexStatusWindow.cs @@ -112,7 +112,6 @@ namespace RJWSexperience.SexHistory.UI { if (window._context.Pawn != history.ParentPawn) { - SoundDefOf.TabOpen.PlayOneShotOnCamera(); window.ChangePawn(history); } } @@ -286,7 +285,6 @@ namespace RJWSexperience.SexHistory.UI Listing_Standard listmain = new Listing_Standard(); listmain.Begin(infoRect); - //listmain.Gap(20f); if (_context.VirginLabel != null) { diff --git a/Source/RJWSexperience/Thoughts/ThoughtDefExtension_StageFromRecord.cs b/Source/RJWSexperience/Thoughts/ThoughtDefExtension_StageFromRecord.cs index 6ff0001..cfa836e 100644 --- a/Source/RJWSexperience/Thoughts/ThoughtDefExtension_StageFromRecord.cs +++ b/Source/RJWSexperience/Thoughts/ThoughtDefExtension_StageFromRecord.cs @@ -5,11 +5,51 @@ using Verse; namespace RJWSexperience { + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] public class ThoughtDefExtension_StageFromRecord : DefModExtension { - [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] public RecordDef recordDef; - [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")] public List minimumValueforStage = new List(); + + public int GetStageIndex(Pawn pawn) + { + float value = pawn?.records?.GetValue(recordDef) ?? 0f; + + for (int i = minimumValueforStage.Count - 1; i > 0; i--) + { + if (minimumValueforStage[i] < value) + { + return i; + } + } + + return 0; + } + + public override IEnumerable ConfigErrors() + { + foreach (string error in base.ConfigErrors()) + { + yield return error; + } + + if (recordDef == null) + { + yield return " is null"; + } + + if (minimumValueforStage.NullOrEmpty()) + { + yield return " should have an entry for every stage"; + } + + for (int i = 0; i < minimumValueforStage.Count - 1; i++) + { + if (minimumValueforStage[i] > minimumValueforStage[i + 1]) + { + yield return "Values in should be ordered from the lowest to the highest"; + } + } + } } } diff --git a/Source/RJWSexperience/Thoughts/Thought_Recordbased.cs b/Source/RJWSexperience/Thoughts/Thought_Recordbased.cs index 48dc19a..dd79ab4 100644 --- a/Source/RJWSexperience/Thoughts/Thought_Recordbased.cs +++ b/Source/RJWSexperience/Thoughts/Thought_Recordbased.cs @@ -1,39 +1,28 @@ using RimWorld; -using System.Collections.Generic; +using Verse; namespace RJWSexperience { /// - /// Thought class using record. + /// Thought class that uses record to select active stage /// public class Thought_Recordbased : Thought_Memory { private ThoughtDefExtension_StageFromRecord extension; + protected ThoughtDefExtension_StageFromRecord Extension => extension ?? (extension = def.GetModExtension()); - protected ThoughtDefExtension_StageFromRecord Extension + /// + /// This method is called for every thought right after the pawn is assigned + /// + public override bool TryMergeWithExistingMemory(out bool showBubble) { - get - { - if (extension == null) - extension = def.GetModExtension(); - return extension; - } + UpdateCurStage(); + return base.TryMergeWithExistingMemory(out showBubble); } - protected RecordDef RecordDef => Extension.recordDef; - protected List MinimumValueforStage => Extension.minimumValueforStage; - - public override int CurStageIndex + protected virtual void UpdateCurStage() { - get - { - float value = pawn?.records?.GetValue(RecordDef) ?? 0f; - for (int i = MinimumValueforStage.Count - 1; i > 0; i--) - { - if (MinimumValueforStage[i] < value) return i; - } - return 0; - } + SetForcedStage(Extension.GetStageIndex(pawn)); } } }