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

53 lines
1.2 KiB
C#
Raw Normal View History

2022-07-26 03:55:56 +00:00
using RimWorld;
2022-08-01 14:21:13 +00:00
using Verse;
2022-07-26 03:55:56 +00:00
namespace RJWSexperience.Ideology
2022-07-26 03:55:56 +00:00
{
public class Thought_Opinionbased : Thought_Memory
{
private ThoughtDefExtension_StageFromValue stageFromValue;
2022-07-26 03:55:56 +00:00
protected ThoughtDefExtension_StageFromValue StageFromValue
2022-07-26 03:55:56 +00:00
{
get
{
if (stageFromValue == null)
2022-08-01 14:21:13 +00:00
{
stageFromValue = def.GetModExtension<ThoughtDefExtension_StageFromValue>();
2022-08-01 14:21:13 +00:00
}
return stageFromValue;
2022-07-26 03:55:56 +00:00
}
}
2022-08-01 14:21:13 +00:00
/// <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);
}
2022-07-26 03:55:56 +00:00
2022-08-01 14:21:13 +00:00
/// <summary>
/// Called every 150 ticks
/// </summary>
public override void ThoughtInterval()
2022-07-26 03:55:56 +00:00
{
2022-08-01 14:21:13 +00:00
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;
SetForcedStage(StageFromValue.GetStageIndex(value));
2022-07-26 03:55:56 +00:00
}
}
}