Page 1 of 1

How to display FactionMember PADs

Posted: Mon Apr 22, 2024 6:33 am
by dkrusenstrahle
Hello,

Is there a way to list out all the FactionMembers and their PAD values as well as how they feel about the player?
I want to display that in the UI canvas.

Thank you!

Re: How to display FactionMember PADs

Posted: Mon Apr 22, 2024 9:15 am
by Tony Li
Hi,

For quick info, you can set up a Faction Member Debugger Canvas to float atop each faction member's head. (Add a FactionMemberDebugger component to the faction member, and assign the "Faction Member Debug Canvas" prefab or "Faction Member Debug Canvas TMPro" prefab to it.)

For a more detailed report, here's an example:

Code: Select all

// Find the player's faction:
int playerFactionID = 0;
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.name == "Player")
    {
        playerFactionID = faction.id;
        break;
    }
}

// Report all faction members' states:
string s = "";
foreach (var factionMembers in FactionManager.instance.members)
{
    Faction faction = factionMembers.Key;
    List<FactionMember> members = factionMembers.Value;
    if (faction.id == playerFactionID) continue;
    s += $"Faction: {faction.name}\n";
    var affinity = FactionManager.instance.GetAffinity(faction.id, playerFactionID);
    s += $"  Affinity to player: {affinity}\n";
    foreach (var member in members)
    {
        var pad = member.pad;
        s += $"  {member.name} P={pad.pleasure} A={pad.arousal} D={pad.dominance} Happiness={pad.happiness}\n";
    }
}
Debug.Log(s);

Re: How to display FactionMember PADs

Posted: Mon Apr 22, 2024 11:39 am
by dkrusenstrahle
Works perfactly! Thank you

Re: How to display FactionMember PADs

Posted: Mon Apr 22, 2024 12:02 pm
by Tony Li
Glad to help!

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 11:06 am
by dkrusenstrahle
Another thing. It looks like this below code only fetches the FactionMembers that are currently in the scene.

FactionManager.instance.members

Is there a way to fetch all faction members regardsless of they are located on the scene?
I want to track how the "villages" behaves and feels just like Stardew valley.

Thanks!

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 11:29 am
by Tony Li
Hi,

If you're interested in relationships (e.g., affinity), they're in the faction database, which is independent of any specific scene. You can get relationship info like this:

Code: Select all

// Find the player's faction:
int playerFactionID = 0;
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.name == "Player")
    {
        playerFactionID = faction.id;
        break;
    }
}

// Report all factions' affinities to player:
string s = "";
foreach (var faction in FactionManager.instance.factionDatabase.factions)
{
    if (faction.id == playerFactionID) continue;
    var affinity = FactionManager.instance.GetAffinity(faction.id, playerFactionID);
    s += $"Faction: {faction.name} affinity to player: {affinity}\n";
}
Debug.Log(s);

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 11:30 am
by dkrusenstrahle
A perfect! Can I get their PADs somehow from here too?

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 11:43 am
by Tony Li
Not as easily. FactionMembers exist in their respective scenes.

However, if you're changing scenes using the save system (link is to DS documentation, but it's the same save system) or saving faction member data between scenes using FactionMember.SerializeToString(), you can examine the serialized string. It's a string of comma-separated values in this format:

factionID, happiness, pleasure, arousal, dominance, ...other values...

If you use the save system and FactionMemberSaver components, each faction member saves its string under its own Key. So if you know the faction member's key (e.g., "Sally"), you can get the PAD like this:

Code: Select all

string s = SaveSystem.currentSavedGameData.GetData("Sally");
string[] values = s.Split(',');
float happiness = float.Parse(values[1]);
float pleasure = float.Parse(values[2]);
float arousal = float.Parse(values[3]);
float dominance = float.Parse(values[4]);

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 11:49 am
by dkrusenstrahle
Mm, I wish there was an easier way to just get all FactionMembers. Can I get a FactionMember based upon the faction name? Or perhaps I should put all NPC hidden just outside the scene so they get counted :)

How would I model an overview about the players relationships with the village people? Right now I can get affinity which I guess is enough but I need to access other things for the NPC, for example name and avatar (I have a special script on the NPC/prefab that allows me to add this).

Re: How to display FactionMember PADs

Posted: Tue Apr 23, 2024 2:57 pm
by Tony Li
Hi,

If each faction member NPC has their own faction (which can have shared parent factions), you just go through the faction database's factions list -- for example, to get each NPC's relationships (e.g., affinity) regardless of what scene you're in.

If you have a special script on your NPC GameObject that has its name and avatar, how do you get that information when that NPC GameObject isn't present in the current scene?