Change Faction Based on Deeds

Announcements, support questions, and discussion for Love/Hate.
Post Reply
Garry
Posts: 4
Joined: Thu Nov 29, 2018 12:24 pm

Change Faction Based on Deeds

Post by Garry »

Hello everyone,
So I have been looking and I don't see a similar question nor answers to this question.

I am prototyping an Alignment system similar to the one you would find in D&D. I have setup the FactionDB as I would expect and I am using the OCEAN personality traits in order to assign values to the 9 different alignments. However it does not appear that doing deeds against or for anyone alignment raises or lowers a value so that your alignment could change over time.

So for example if I am a Lawful Good alignment and I do good things for the Chaotic Evil alignment then eventually I want my alignment to fall towards the Evil Chaotic scale. I attached an export from my LoveHate DB and also included a spreadsheet on how I see the alignments working on a -100 to 100 scale.

Is this possible with Love Hate?

Thanks,
Garry
Attachments
LoveHate.zip
(7.9 KiB) Downloaded 115 times
User avatar
Tony Li
Posts: 20723
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Faction Based on Deeds

Post by Tony Li »

Hi Garry,

Love/Hate doesn't include any automated way to flip a faction member to a different faction, but it's possible with a small bit of scripting (or visual scripting such as PlayMaker).

Each faction member should have its own personal faction. Each personal faction will have one of the alignment factions (Lawful Evil, Chaotic Good, etc.) as a parent faction.

First tick the Faction Manager's Can Witness Self checkbox, and increase the faction member's Impressionability value. When a faction member witnesses a deed committed by a friend (including itself if Can Witness Self is ticked), it will start to align its personal faction's personality traits with the deed's personality traits. Impressionability affects the degree to which it aligns to the deed's personality traits. Zero means personality traits will never change; 100 means it will immediately adjust its current personality by the full value of the deed's traits.

Then you just need to check the faction member's personality traits against the alignment factions' personality traits. The first step is to be notified when the faction member updates its faction's personality traits. To do this, add a Faction Member Events component to the faction member and assign a script method to the OnWitnessDeed() event, or add a script that implements IWitnessDeedEventHandler. Faction Member Events is described on page 36 of the manual, and IWitnessDeedHandler on page 37.

In the script method, loop through all nine alignment factions. Use the function Traits.Alignment() to identify the closest alignment faction. Then use FactionManager.RemoveFactionParent and AddFactionParent to change the faction member's parent faction.

Here's a rough idea of what I'm talking about:

Code: Select all

using UnityEngine;
using PixelCrushers.LoveHate;

public class UpdateAlignmentAfterWitnessingDeed : MonoBehaviour, IWitnessDeedEventHandler
{
    void OnWitnessDeed(Rumor rumor)
    {
        UpdateAlignment();
    }

    void UpdateAlignment()
    {
        // Find the alignment faction that most closely matches my personality:
        Faction myFaction = GetComponent<FactionMember>().faction;
        int currentParentID = myFaction.parents[0]; // Assume first parent is alignment faction.
        int newParentID = currentParentID;
        float highestMatchValue = -1;
        for (int i = 0; i < 9; i++) // Assumes alignment factions have IDs 0-8.
        {
            int alignmentFactionID = i;
            Faction alignmentFaction = FactionManager.instance.GetFaction(alignmentFactionID);
            float matchValue = Traits.Alignment(alignmentFaction.traits, myFaction.traits);
            if (matchValue > highestMatchValue)
            {
                highestMatchValue = matchValue;
                newParentID = alignmentFactionID;
            }
        }
        
        // If different, switch alignments:
        if (newParentID != currentParentID)
        {
            FactionManager.instance.RemoveFactionParent(myFaction.id, currentParentID, true);
            FactionManager.instance.AddFactionParent(myFaction.id, newParentID);
        }
    }
}
I just typed that into the reply, so typos are possible.
Garry
Posts: 4
Joined: Thu Nov 29, 2018 12:24 pm

Re: Change Faction Based on Deeds

Post by Garry »

Tony,
Thank you for the quick reply as always and I will play with the script today. One more question. After playing with my Alignment Calcs I am thinking it will be necessary to add weights to the various factions as they will value or devalue certain traits differently. See the attached pic for an example of what I am talking about. Is there away to accomplish this as well?
Weights.PNG
Weights.PNG (8.81 KiB) Viewed 1535 times
Also when setting up deeds for this scenario would I have a positive and a negative for each type of deed towards a faction as obviously what faction you are currently in and what type of deed you perform against a certain faction will have different value changes. Not fully understanding on how to implement this piece.
Deeds.PNG
Deeds.PNG (18.83 KiB) Viewed 1533 times
Thanks as always,
Garry
User avatar
Tony Li
Posts: 20723
Joined: Thu Jul 18, 2013 1:27 pm

Re: Change Faction Based on Deeds

Post by Tony Li »

Hi Garry,

Weights
Regarding weights, I'm not sure I understand your pic. At what point do the weights come into play? When a character judges a deed? Or when checking if a character has flipped to a different alignment?

If it's when a character judges a deed, you can add a script that assigns a replacement function for FactionMember.GetTraitAlignment.

Faction databases don't have an extra slot for weights, but you can define some extra, fake factions to record the weights. For example, if the alignments are factions 0-8, then their weights could be 9-17. Then your replacement might look something like this:
WeightedTraitAlignment.cs

Code: Select all

[RequireComponent(typeof(FactionMember))]
public class WeightedTraitAlignment : MonoBehaviour 
{
    private FactionMember factionMember;
    private float[] weightedTraits; // (Allocate once to avoid garbage collection.)
    
    void Start()
    {
        factionMember = GetComponent<FactionMember>();
        factionMember.GetTraitAlignment = GetWeightedTraitAlignment;
        float[] weightedTraits = new float[factionMember.faction.traits.Length];
    }
    
    void GetWeightedTraitAlignment(float[] traits)
    {
        // Get the weights "faction" for the character's current alignment:
        int parentFactionID = factionMember.faction.parents[0];
        int weightsFactionID = parentFactionID + 9;
        Faction weightsFaction = FactionManager.instance.GetFaction(weightsFactionID);
        
        // Generate weighted traits:
        for (int i = 0; i < traits.Length; i++)
        {
            weightedTraits[i] = traits[i] * weightsFaction.traits[i];
        }
        
        return factionMember.DefaultGetTraitAlignment(weightedTraits);
    }
}

Deeds
It's possible to use separate deeds, but I think you can use a single deed. For example, say the deed is "Punch Target". Then the deed's values might be:
  • Impact: -20 (bad, but not as bad as stabbing them)
  • Aggression: 50
  • Openness: 25
  • Conscientiousness: -50, etc
Impact is the most important value. This is a negative deed. Let's say Frodo punches Sam.

Pippin likes Sam, so he disapproves of the deed. Pippin is not aggressive; the trait misalignment means he disapproves to an even greater degree. So Pippin loses affinity for Frodo.

Gollum hates hobbitses. Since he already has a negative affinity to Sam and Frodo, he approves of the deed. He's also aggressive, so he approves to a greater degree. Gollum gains affinity for Frodo, since he wants to see more of this kind of behavior.

Frodo witnesses himself commit this deed. He loses some affinity for himself for hurting his friend (assuming he starts with positive affinity for Sam). And, if his Impressionability is nonzero, he aligns his personality traits more closely with Punch Target's traits (aggression, lack of conscience, etc.).
Post Reply