[HOWTO] How To: Adjust Actor's Personality Traits When Committing Deeds

Announcements, support questions, and discussion for Love/Hate.
Post Reply
User avatar
Tony Li
Posts: 22110
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Adjust Actor's Personality Traits When Committing Deeds

Post by Tony Li »

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

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);
            }
        }
    }
}
Post Reply