public WorldCombat NewCombatEvent(Entity a, Entity b)
    {
        WorldCombat combatEvent = new WorldCombat(a, b);

        CurrentWorldCombatEvents.Add(combatEvent);
        EventManager.Instance.InvokeNewEvent(combatEvent);
        Debug.Log("Entity " + a.ToString() + " is attacking " + b.ToString());
        return(combatEvent);
    }
 public bool EntityInWorldCombatEvent(Entity entity, out WorldCombat wce)
 {
     foreach (WorldCombat WC in CurrentWorldCombatEvents)
     {
         if (!WC.IsComplete)
         {
             if (WC.Team1.Contains(entity) || WC.Team2.Contains(entity))
             {
                 wce = WC;
                 return(true);
             }
         }
     }
     wce = null;
     return(false);
 }
Exemple #3
0
    public void Tick()
    {
        //If in combat, updating will be done in main update function
        if (InCombat)
        {
            //Entity.GetLoadedEntity().SpeechBubble.SetText(Entity.EntityAI.ToString());

            return;
        }
        else
        {
            Entity.GetLoadedEntity().LEPathFinder.Tick();

            //If not currently in combat, gather all near entities
            NearEntities = EntityManager.Instance.GetEntitiesNearChunk(Entity.LastChunkPosition);
            //If no near entities, then no combat loop to run
            if (NearEntities == null || NearEntities.Count == 0)
            {
                return;
            }
            //Iterate all near entities
            foreach (Entity ent in NearEntities)
            {
                //Skip this entity
                if (ent.Equals(Entity))
                {
                    continue;
                }
                //Check if we can see this entity
                if (CanSeeEntity(ent))
                {
                    if (ShouldCombat(ent))
                    {
                        Debug.Log("[EntityCombatAI] Entity " + Entity + " has seen Entity " + ent + " and is entering combat");
                        //Enter into combat
                        CurrentCombatEvent = EntityManager.Instance.NewCombatEvent(Entity, ent);
                        CurrentTarget      = ent;

                        //Store details of entity
                        LastTargetDetails = new LastTargetDetails(ent);
                    }
                }
            }
            //Update the path finder
            Debug.Log("tick?");
        }
    }
Exemple #4
0
 public override void WorldCombatEvent(WorldCombat wce)
 {
     if (CurrentCombatEvent == null || CurrentCombatEvent.IsComplete)
     {
         //If the combat event faction1 is the same as this entities faction, join the combat
         if (wce.Faction1 != null && wce.Faction1.Equals(Entity.EntityFaction))
         {
             wce.Team1.Add(Entity);
             CurrentTarget      = GameManager.RNG.RandomFromList(wce.Team2);
             CurrentCombatEvent = wce;
         }
         else //If the combat event faction1 is the same as this entities faction, join the combat
         if (wce.Faction2 != null && wce.Faction2.Equals(Entity.EntityFaction))
         {
             wce.Team2.Add(Entity);
             CurrentTarget      = GameManager.RNG.RandomFromList(wce.Team1);
             CurrentCombatEvent = wce;
         }
     }
 }
Exemple #5
0
 public void Tick()
 {
     //If in combat, updating will be done in main update function
     if (InCombat)
     {
         return;
     }
     else
     {
         //If not currently in combat, gather all near entities
         List <Entity> nearEntities = GameManager.EntityManager.GetEntitiesNearChunk(Entity.LastChunkPosition);
         //If no near entities, then no combat loop to run
         if (nearEntities == null || nearEntities.Count == 0)
         {
             return;
         }
         Entity.GetLoadedEntity().NearEntities = nearEntities;
         //Iterate all near entities
         foreach (Entity ent in nearEntities)
         {
             //Skip this entity
             if (ent.Equals(Entity))
             {
                 continue;
             }
             //Check if we can see this entity
             if (CanSeeEntity(ent))
             {
                 if (ShouldCombat(ent))
                 {
                     //Enter into combat
                     CurrentCombatEvent = GameManager.EntityManager.NewCombatEvent(Entity, ent);
                     CurrentTarget      = ent;
                 }
             }
         }
     }
 }
Exemple #6
0
    /// <summary>
    /// Instructs the parent entity <see cref="EntityCombatAI.Entity"/> to try and attack the target <paramref name="entity"/>. <br/>
    /// We check if either the parent entity or target entity are already in combat events. If so, we add the other entity to the relevent team.
    /// <br/>
    /// </summary>
    /// <param name="entity"></param>
    public void Attack(Entity entity)
    {
        WorldCombat wce = null;

        //Check for combat event related to target entity
        if (EntityManager.Instance.EntityInWorldCombatEvent(entity, out wce))
        {
            //Add parent entity to relevent team
            if (wce.Team1.Contains(entity))
            {
                wce.Team2.Add(Entity);
            }
            else
            {
                wce.Team1.Add(Entity);
            }
            //Check for combat event related to parent entity.
        }
        else if (EntityManager.Instance.EntityInWorldCombatEvent(Entity, out wce))
        {
            if (wce.Team1.Contains(Entity))
            {
                wce.Team2.Add(entity);
            }
            else
            {
                wce.Team1.Add(entity);
            }
        }
        else
        {//If no combat event is found, we create a new one
            wce = EntityManager.Instance.NewCombatEvent(entity, Entity);
        }
        //We set thecombat event and combat target.
        CurrentCombatEvent = wce;

        CurrentTarget = entity;
    }
Exemple #7
0
 public override void WorldCombatEvent(WorldCombat wce)
 {
     //Entity is passive, we do nothing on comat events
 }
Exemple #8
0
 public abstract void WorldCombatEvent(WorldCombat wce);
Exemple #9
0
    public override void WorldCombatEvent(WorldCombat wce)
    {
        //if we are already part of the combat event, we have no reaction.
        if (wce.IsParticipant(Entity))
        {
            return;
        }

        //if we are far, ignore
        if (wce.Position.QuickDistance(Entity.TilePos) > World.ChunkSize * World.ChunkSize * 9)
        {
            return;
        }

        if (CurrentCombatEvent == null || CurrentCombatEvent.IsComplete)
        {
            //If we are in the same faction as either of the sides, join accordingly
            if (Entity.EntityFaction != null && Entity.EntityFaction.Equals(wce.Faction1))
            {
                wce.Team1.Add(Entity);
                CurrentCombatEvent = wce;
                CurrentTarget      = wce.GetNearestTeam2Entity(Entity);
                return;
            }
            else if (Entity.EntityFaction != null && Entity.EntityFaction.Equals(wce.Faction2))
            {
                wce.Team2.Add(Entity);
                CurrentCombatEvent = wce;
                CurrentTarget      = wce.GetNearestTeam1Entity(Entity);
                return;
            }
            //if we are not in a faction/not related to their factions, we check friendships/family relations
            float team1RelVal = 0;
            bool  team1High   = false;

            float team2RelVal = 0;
            bool  team2High   = false;

            foreach (Entity e in wce.Team1)
            {
                float eRelVal = NPC.EntityRelationshipManager.GetEntityRelationship(e);
                //If we have a close friend/family member, take note
                if (eRelVal > 0.7f / NPC.EntityRelationshipManager.Personality.Loyalty)
                {
                    team1High = true;
                }
                team1RelVal += eRelVal;
            }

            foreach (Entity e in wce.Team2)
            {
                float eRelVal = NPC.EntityRelationshipManager.GetEntityRelationship(e);
                //If we have a close friend/family member, take note
                if (eRelVal > 0.7f / NPC.EntityRelationshipManager.Personality.Loyalty)
                {
                    team2High = true;
                }
                team2RelVal += eRelVal;
            }

            //If we have a close friend or family member, (Currently) do nothing.
            //TODO - add something here? Who knows?
            if (team1High && team2High)
            {
                return;
            }
            //If we have a family/friend on team 1, we join the combat with team 1.
            if (team1High)
            {
                //We join their team, then choose a target to fight
                wce.Team1.Add(Entity);
                CurrentCombatEvent = wce;
                CurrentTarget      = wce.GetNearestTeam2Entity(Entity);
            }
            else if (team2High)
            {
                //We join their team, then choose a target to fight
                wce.Team2.Add(Entity);
                CurrentCombatEvent = wce;
                CurrentTarget      = wce.GetNearestTeam1Entity(Entity);
            }
            else
            {
                //Check if aggression is high against RNG
                if (NPC.EntityRelationshipManager.Personality.Agression > GameManager.RNG.Random(0.6f, 0.8f))
                {
                    //Agression is between 0 and 1, we divide the team2 relationship value by this.
                    //And check against team1relval. This means higher agression requires less difference
                    //We also divide team2relval by the entities loyatly. This means that an entity with low loyalty requires a higher difference
                    if (team1RelVal > team2RelVal / (NPC.EntityRelationshipManager.Personality.Loyalty * NPC.EntityRelationshipManager.Personality.Agression))
                    {
                        wce.Team1.Add(Entity);
                        CurrentCombatEvent = wce;
                        CurrentTarget      = wce.GetNearestTeam2Entity(Entity);
                        return;
                    }
                    else if (team2RelVal < team1RelVal / (NPC.EntityRelationshipManager.Personality.Loyalty * NPC.EntityRelationshipManager.Personality.Agression))
                    {
                        wce.Team2.Add(Entity);
                        CurrentCombatEvent = wce;
                        CurrentTarget      = wce.GetNearestTeam1Entity(Entity);
                        return;
                    }
                }
                else
                {
                    Vec2i runPos = Entity.TilePos + GameManager.RNG.RandomVec2i(10, 20) * GameManager.RNG.RandomSign();
                    Entity.EntityAI?.TaskAI.SetTask(new EntityTaskGoto(Entity, runPos, priority: 10, running: true));
                }//if our agression is low, we check for
                 //If neither team has a friend/family, we
            }
        }
    }