rjw-sexperience-ideology/Source/IdeologyAddon/Thoughts/Thought_Opinionbased.cs

63 lines
1.3 KiB
C#

using RimWorld;
using System.Collections.Generic;
using Verse;
namespace RJWSexperience
{
public class Thought_Opinionbased : Thought_Memory
{
private List<float> minimumValueforStage;
protected List<float> MinimumValueforStage
{
get
{
if (minimumValueforStage == null)
{
minimumValueforStage = def.GetModExtension<ThoughtDefExtension_StageFromOpinion>().minimumValueforStage;
}
return minimumValueforStage;
}
}
/// <summary>
/// This method is called for every thought right after the pawn is assigned
/// </summary>
public override bool TryMergeWithExistingMemory(out bool showBubble)
{
UpdateCurStage();
return base.TryMergeWithExistingMemory(out showBubble);
}
/// <summary>
/// Called every 150 ticks
/// </summary>
public override void ThoughtInterval()
{
UpdateCurStage();
base.ThoughtInterval();
}
protected void UpdateCurStage()
{
if (otherPawn == null)
{
Log.Warning($"[RSI] Thought_Opinionbased {def.defName} for pawn {pawn.NameShortColored} lacks otherPawn");
SetForcedStage(0);
}
float value = pawn.relations?.OpinionOf(otherPawn) ?? 0f;
for (int i = MinimumValueforStage.Count - 1; i > 0; i--)
{
if (MinimumValueforStage[i] < value)
{
SetForcedStage(i);
return;
}
}
SetForcedStage(0);
}
}
}