RJW-Sexperience/RJWSexperience/IdeologyAddon/Thoughts/Thought_IncreaseRecord.cs
2022-06-18 12:54:31 +05:00

70 lines
1.6 KiB
C#

using RimWorld;
using Verse;
namespace RJWSexperience
{
public class Thought_IncreaseRecord : Thought_Memory
{
private ThoughtDefExtension_IncreaseRecord extension;
protected ThoughtDefExtension_IncreaseRecord Extension
{
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)
{
ThoughtHandler thoughts = pawn.needs.mood.thoughts;
if (thoughts.memories.NumMemoriesInGroup(this) >= def.stackLimit)
{
Thought_IncreaseRecord thought_Memory = (Thought_IncreaseRecord)thoughts.memories.OldestMemoryInGroup(this);
if (thought_Memory != null)
{
showBubble = (thought_Memory.age > thought_Memory.def.DurationTicks / 2);
thought_Memory.Merged();
return true;
}
}
showBubble = true;
return false;
}
public override void Init()
{
base.Init();
recordIncrement = Increment;
}
protected virtual void Merged()
{
age = 0;
recordIncrement += Increment;
}
}
}