public EntityRelationshipManager(NPC npc, EntityPersonality personality)
 {
     NPC                    = npc;
     Personality            = personality;
     EntityRelationship     = new Dictionary <int, float>();
     EntityRelationshipTags = new Dictionary <int, EntityRelationshipTag>();
 }
示例#2
0
 public void SetPersonality(EntityPersonality personality)
 {
     if (EntityRelationshipManager == null)
     {
         EntityRelationshipManager = new EntityRelationshipManager(this, personality);
     }
     else
     {
         EntityRelationshipManager.SetPersonality(personality);
     }
 }
示例#3
0
    private void GenerateNPCPersonalities(List <NPC> npcs)
    {
        //iterate all npcs
        foreach (NPC npc in npcs)
        {
            //Personality is random
            KingdomHierarchy rank    = npc.NPCKingdomData.Rank;
            float            loyalty = 1;
            float            wealth  = 0;
            if (rank == KingdomHierarchy.Monarch)
            {
                wealth  = 1;
                loyalty = 1;
            }
            else if (rank == KingdomHierarchy.Noble)
            {
                loyalty = Mathf.Clamp(GenerationRan.GaussianFloat(0.8f, 0.2f), 0, 1);
                wealth  = Mathf.Clamp(GenerationRan.GaussianFloat(0.8f, 0.2f), 0, 1);
            }
            else if (rank == KingdomHierarchy.LordLady)
            {
                loyalty = Mathf.Clamp(GenerationRan.GaussianFloat(0.7f, 0.3f), 0, 1);
                wealth  = Mathf.Clamp(GenerationRan.GaussianFloat(0.7f, 0.3f), 0, 1);
            }
            else if (rank == KingdomHierarchy.Knight || rank == KingdomHierarchy.Mayor)
            {
                loyalty = Mathf.Clamp(GenerationRan.GaussianFloat(0.7f, 0.4f), 0, 1);
                wealth  = Mathf.Clamp(GenerationRan.GaussianFloat(0.7f, 0.3f), 0, 1);
            }
            else if (rank == KingdomHierarchy.Citizen)
            {
                loyalty = Mathf.Clamp(GenerationRan.GaussianFloat(0.6f, 0.6f), 0, 1);
                wealth  = Mathf.Clamp(GenerationRan.GaussianFloat(0.5f, 0.3f), 0, 1);
            }
            else
            {
                loyalty = Mathf.Clamp(GenerationRan.GaussianFloat(0.5f, 0.5f), 0, 1);
                wealth  = Mathf.Clamp(GenerationRan.GaussianFloat(0.3f, 0.3f), 0, 1);
            }

            float kindness  = Mathf.Clamp(GenerationRan.GaussianFloat(0.6f, 0.4f), 0, 1);
            float agression = Mathf.Clamp(GenerationRan.GaussianFloat(0.6f, 0.4f), 0, 1);
            float greed     = Mathf.Clamp(GenerationRan.GaussianFloat(0.6f, 0.4f), 0, 1);

            EntityPersonality pers = new EntityPersonality(agression, kindness, loyalty, greed, wealth);
            npc.SetPersonality(pers);
        }
    }
 public void SetPersonality(EntityPersonality pers)
 {
     Personality = pers;
 }
    /// <summary>
    /// Calculates the initial/default relationship with the specified entity.
    ///
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    private float CalculateEntityRelationship(Entity entity)
    {
        //Non fixed entities - likely bandits
        if (!entity.IsFixed)
        {
            if (entity is HumanoidEntity)
            {
                if (entity is Bandit)
                {
                    return(0);
                }
            }

            return(0.5f);
        }
        else
        {
            //if the entity is fixed, the initial relationship will
            //be based on the kingdoms the entities belong to, and the two entity personality

            if (entity is NPC)
            {
                NPC otherNPC = entity as NPC;
                EntityPersonality otherPer        = otherNPC.EntityRelationshipManager.Personality;
                float             kingdomRelation = 1;
                //Subjuget is a value which is high if otherNPC is above this NPC in the kingdom heirarchy
                //It is
                float subjugetMult = 1;

                if (NPC.NPCKingdomData.KingdomID == otherNPC.NPCKingdomData.KingdomID)
                {
                    kingdomRelation = 1.5f;

                    //We modify the subjuget multiplier if the otherNPC outranks this one
                    if ((int)NPC.NPCKingdomData.Rank > (int)otherNPC.NPCKingdomData.Rank)
                    {
                        //If this NPCs loyalty is low, then they don't care as much about being outranked
                        if (Personality.Loyalty < 0.4f)
                        {
                            subjugetMult = 0.5f;
                        }
                        else
                        {
                            //High loyalty gives relationship bonus
                            subjugetMult *= (Personality.Loyalty + 0.2f);
                        }
                        if (NPC.NPCKingdomData.SettlementID == otherNPC.NPCKingdomData.SettlementID)
                        {
                            //If the NPCs are in the same settlement, the subjugation multiplier is increased
                            //Due to higher pressure
                            subjugetMult *= 1.4f;
                        }
                    }
                }
                else
                {
                    //TODO - add kingdom relations (how friendly two kingdoms are)
                    //kingdomRelation = Kingdom.GetRelation(otherNPC.NPCKingdomData.KingdomID);
                }

                //If this entity is loyal, then they will respect a +ve kingdom relationship more
                //If they are not loyal, they won't care
                float weightedKingdom = kingdomRelation * Personality.Loyalty;

                //High difference if aggression results in bad relationship
                float agresDifMult = 1 - Mathf.Abs(otherPer.Agression - Personality.Agression);

                //Two entities will not like each other if they are opposite wealth
                //Rich hate the poor, and the poor hate the rich
                float wealthDifMult = 1 - Mathf.Abs(otherPer.Wealth - Personality.Wealth);
                //Two entities of high difference in greed will result in dislike
                float greedDifMult = 1 - Mathf.Abs(otherPer.Greed - Personality.Greed);

                //We take product of all, then multiply by this entities personality.
                float totalRelation = weightedKingdom * subjugetMult * agresDifMult * wealthDifMult * greedDifMult * Personality.Kindness;
                //Clamp relationship [0,1]
                totalRelation = Mathf.Clamp(totalRelation, 0, 1);
                return(totalRelation);
            }



            //Default mid relationship
            return(0.5f);
        }
    }