53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
|
using RimWorld;
|
|||
|
using rjw;
|
|||
|
using rjwquirks;
|
|||
|
using rjwquirks.Modules.Shared.Events;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Verse;
|
|||
|
|
|||
|
namespace rjwquirks.Modules.Quirks.Comps
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Comp to add a quirk when <see cref="record"/> crosses <see cref="value"/>
|
|||
|
/// </summary>
|
|||
|
public class Adder_OnRecordExceeding : Adder
|
|||
|
{
|
|||
|
public RecordDef record;
|
|||
|
public float value;
|
|||
|
|
|||
|
protected override void HandleEvent(RjwEvent ev)
|
|||
|
{
|
|||
|
if (!ev.args.TryGetArg(RjwEventArgNames.Pawn, out Pawn pawn))
|
|||
|
{
|
|||
|
ModLog.Error($"{GetType()}.HandleEvent: No pawn in the event");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
float recordValue = pawn.records?.GetValue(record) ?? 0f;
|
|||
|
|
|||
|
if (recordValue >= value && !pawn.HasQuirk(parent))
|
|||
|
{
|
|||
|
AddQuirkTo(pawn);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override IEnumerable<string> ConfigErrors(QuirkDef parent)
|
|||
|
{
|
|||
|
foreach (string error in base.ConfigErrors(parent))
|
|||
|
{
|
|||
|
yield return error;
|
|||
|
}
|
|||
|
|
|||
|
if (record == null)
|
|||
|
{
|
|||
|
yield return "<record> is empty";
|
|||
|
}
|
|||
|
|
|||
|
if (value == 0f)
|
|||
|
{
|
|||
|
yield return "<value> is empty";
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|