[HOWTO] How To: Adjust Actor's Personality Traits When Committing Deeds
Posted: Tue Jun 04, 2024 10:05 am
Normally when Love/Hate reports a deed, it only affects the witnesses of the deed. If you also want to adjust the deed actor's personality traits when they perform a deed, you can use this subclass of DeedReporter instead of the original:
DeedReporterWithActorTraitInfluence.cs
DeedReporterWithActorTraitInfluence.cs
Code: Select all
using UnityEngine;
using PixelCrushers.LoveHate;
public class DeedReporterWithActorTraitInfluence : DeedReporter
{
private FactionMember me;
protected override void Awake()
{
base.Awake();
me = GetComponent<FactionMember>();
}
public override void ReportDeedByActor(FactionMember actor, string tag, FactionMember target)
{
base.ReportDeedByActor(actor, tag, target);
DeedTemplate deedTemplate;
if (FindDeedTemplate(tag, out deedTemplate))
{
for (int i = 0; i < deedTemplate.traits.Length; i++)
{
var adjustment = deedTemplate.traits[i] * (Mathf.Abs(deedTemplate.impact) / 100);
me.faction.traits[i] = Mathf.Clamp(me.faction.traits[i] + adjustment, -100, 100);
}
}
}
}