Optimized Ate Cum thought

This commit is contained in:
amevarashi 2023-04-17 14:17:07 +05:00
parent cdc79acfa3
commit 8a48d2e463
5 changed files with 61 additions and 56 deletions

View File

@ -15,12 +15,12 @@
</li>
<li>
<label>ate cum</label>
<description>Tastes bad and stinky.</description>
<description>It's stinky and tastes bad.</description>
<baseMoodEffect>-2</baseMoodEffect>
</li>
<li>
<label>ate cum</label>
<description>Tastes bad. But i liked it.</description>
<description>Tastes bad. But I liked it.</description>
<baseMoodEffect>1</baseMoodEffect>
</li>
<li>

View File

@ -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;
}
}
}

View File

@ -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)
{

View File

@ -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<float> minimumValueforStage = new List<float>();
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<string> ConfigErrors()
{
foreach (string error in base.ConfigErrors())
{
yield return error;
}
if (recordDef == null)
{
yield return "<recordDef> is null";
}
if (minimumValueforStage.NullOrEmpty())
{
yield return "<minimumValueforStage> 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 <minimumValueforStage> should be ordered from the lowest to the highest";
}
}
}
}
}

View File

@ -1,39 +1,28 @@
using RimWorld;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience
{
/// <summary>
/// Thought class using record.
/// Thought class that uses record to select active stage
/// </summary>
public class Thought_Recordbased : Thought_Memory
{
private ThoughtDefExtension_StageFromRecord extension;
protected ThoughtDefExtension_StageFromRecord Extension => extension ?? (extension = def.GetModExtension<ThoughtDefExtension_StageFromRecord>());
protected ThoughtDefExtension_StageFromRecord Extension
/// <summary>
/// This method is called for every thought right after the pawn is assigned
/// </summary>
public override bool TryMergeWithExistingMemory(out bool showBubble)
{
get
{
if (extension == null)
extension = def.GetModExtension<ThoughtDefExtension_StageFromRecord>();
return extension;
}
UpdateCurStage();
return base.TryMergeWithExistingMemory(out showBubble);
}
protected RecordDef RecordDef => Extension.recordDef;
protected List<float> 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));
}
}
}