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

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