Refactor Thought_IncreaseRecord, also fix null error in it if no sexperience
This commit is contained in:
parent
75023a9d05
commit
6767feb57c
|
@ -1,4 +1,5 @@
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Verse;
|
using Verse;
|
||||||
|
|
||||||
|
@ -10,5 +11,23 @@ namespace RJWSexperience
|
||||||
public RecordDef recordDef;
|
public RecordDef recordDef;
|
||||||
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
[SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Field value loaded from XML")]
|
||||||
public float increment;
|
public float increment;
|
||||||
|
|
||||||
|
public override IEnumerable<string> ConfigErrors()
|
||||||
|
{
|
||||||
|
foreach (string error in base.ConfigErrors())
|
||||||
|
{
|
||||||
|
yield return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recordDef == null)
|
||||||
|
{
|
||||||
|
yield return "<recordDef> is empty";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (increment == 0f)
|
||||||
|
{
|
||||||
|
yield return "<increment> is empty or 0";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,70 +1,25 @@
|
||||||
using RimWorld;
|
using RimWorld;
|
||||||
using Verse;
|
|
||||||
|
|
||||||
namespace RJWSexperience
|
namespace RJWSexperience
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Increments record every time the thought is added
|
||||||
|
/// The increment is permanent
|
||||||
|
/// </summary>
|
||||||
public class Thought_IncreaseRecord : Thought_Memory
|
public class Thought_IncreaseRecord : Thought_Memory
|
||||||
{
|
{
|
||||||
private ThoughtDefExtension_IncreaseRecord extension;
|
/// <summary>
|
||||||
|
/// This method is called for every thought right after the pawn is assigned
|
||||||
protected ThoughtDefExtension_IncreaseRecord Extension
|
/// </summary>
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (extension == null)
|
|
||||||
extension = def.GetModExtension<ThoughtDefExtension_IncreaseRecord>();
|
|
||||||
return extension;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected RecordDef RecordDef => Extension.recordDef;
|
|
||||||
protected float Increment => Extension.increment;
|
|
||||||
|
|
||||||
protected float recordIncrement;
|
|
||||||
|
|
||||||
public override void ExposeData()
|
|
||||||
{
|
|
||||||
base.ExposeData();
|
|
||||||
Scribe_Values.Look(ref recordIncrement, "recordIncrement", recordIncrement, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void ThoughtInterval()
|
|
||||||
{
|
|
||||||
base.ThoughtInterval();
|
|
||||||
if (recordIncrement != 0)
|
|
||||||
{
|
|
||||||
pawn.records.AddTo(RecordDef, recordIncrement);
|
|
||||||
recordIncrement = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool TryMergeWithExistingMemory(out bool showBubble)
|
public override bool TryMergeWithExistingMemory(out bool showBubble)
|
||||||
{
|
{
|
||||||
ThoughtHandler thoughts = pawn.needs.mood.thoughts;
|
var defExtension = def.GetModExtension<ThoughtDefExtension_IncreaseRecord>();
|
||||||
if (thoughts.memories.NumMemoriesInGroup(this) >= def.stackLimit)
|
|
||||||
|
if (defExtension != null)
|
||||||
{
|
{
|
||||||
Thought_IncreaseRecord thought_Memory = (Thought_IncreaseRecord)thoughts.memories.OldestMemoryInGroup(this);
|
pawn.records.AddTo(defExtension.recordDef, defExtension.increment);
|
||||||
if (thought_Memory != null)
|
|
||||||
{
|
|
||||||
showBubble = (thought_Memory.age > thought_Memory.def.DurationTicks / 2);
|
|
||||||
thought_Memory.Merged();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
showBubble = true;
|
return base.TryMergeWithExistingMemory(out showBubble);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Init()
|
|
||||||
{
|
|
||||||
base.Init();
|
|
||||||
recordIncrement = Increment;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void Merged()
|
|
||||||
{
|
|
||||||
age = 0;
|
|
||||||
recordIncrement += Increment;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue