mirror of
https://gitgud.io/amevarashi/rjw-sexperience-ideology.git
synced 2024-08-15 00:43:19 +00:00
Optimized Thought_Opinionbased
This commit is contained in:
parent
6767feb57c
commit
3804469b3a
2 changed files with 63 additions and 16 deletions
|
@ -1,36 +1,62 @@
|
|||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace RJWSexperience
|
||||
{
|
||||
public class Thought_Opinionbased : Thought_Memory
|
||||
{
|
||||
private ThoughtDefExtension_StageFromOpinion extension;
|
||||
private List<float> minimumValueforStage;
|
||||
|
||||
protected ThoughtDefExtension_StageFromOpinion Extension
|
||||
protected List<float> MinimumValueforStage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (extension == null)
|
||||
extension = def.GetModExtension<ThoughtDefExtension_StageFromOpinion>();
|
||||
return extension;
|
||||
if (minimumValueforStage == null)
|
||||
{
|
||||
minimumValueforStage = def.GetModExtension<ThoughtDefExtension_StageFromOpinion>().minimumValueforStage;
|
||||
}
|
||||
return minimumValueforStage;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<float> MinimumValueforStage => Extension.minimumValueforStage;
|
||||
|
||||
public override int CurStageIndex
|
||||
/// <summary>
|
||||
/// This method is called for every thought right after the pawn is assigned
|
||||
/// </summary>
|
||||
public override bool TryMergeWithExistingMemory(out bool showBubble)
|
||||
{
|
||||
get
|
||||
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)
|
||||
{
|
||||
float value = 0f;
|
||||
if (otherPawn != null) value = pawn.relations?.OpinionOf(otherPawn) ?? 0f;
|
||||
for (int i = MinimumValueforStage.Count - 1; i > 0; i--)
|
||||
{
|
||||
if (MinimumValueforStage[i] < value) return i;
|
||||
}
|
||||
return 0;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue