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
|
@ -8,5 +8,26 @@ namespace RJWSexperience
|
|||
{
|
||||
[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 override IEnumerable<string> ConfigErrors()
|
||||
{
|
||||
foreach (string error in base.ConfigErrors())
|
||||
{
|
||||
yield return error;
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue