Пример #1
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        EntityAlive leader = null;

        if (this.theEntity.Buffs.HasCustomVar("Leader"))
        {
            DisplayLog(" leader Detected.");
            int EntityID = (int)this.theEntity.Buffs.GetCustomVar("Leader");
            leader = this.theEntity.world.GetEntity(EntityID) as EntityAlive;
        }

        if (leader == null)
        {
            DisplayLog(" No leader detected.");
            return(false);
        }

        // Search in the bounds are to try to find the most appealing entity to follow.
        Bounds bb = new Bounds(this.theEntity.position, new Vector3(this.theEntity.GetSeeDistance(), 20f, this.theEntity.GetSeeDistance()));

        this.theEntity.world.GetEntitiesInBounds(typeof(EntityAlive), bb, this.NearbyEntities);
        DisplayLog(" Nearby Entities: " + this.NearbyEntities.Count);
        for (int i = this.NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAlive x = (EntityAlive)this.NearbyEntities[i];
            if (x != this.theEntity)
            {
                DisplayLog("Nearby Entity: " + x.EntityName);
                if (x.GetAttackTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);
                    return(true);
                }

                if (x.GetRevengeTarget() == leader)
                {
                    DisplayLog(" My leader is being avenged by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }

                if (x.GetDamagedTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by something that damaged it " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }
            }
        }

        return(false);
    }
Пример #2
0
    public static Entity GetAttackOrReventTarget(int EntityID)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity)
        {
            if (myEntity.GetAttackTarget() != null)
            {
                return(myEntity.GetAttackTarget());
            }
            if (myEntity.GetRevengeTarget() == null)
            {
                return(myEntity.GetRevengeTarget());
            }
        }
        return(null);
    }
Пример #3
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        EntityAlive leader = EntityUtilities.GetLeaderOrOwner(this.theEntity.entityId) as EntityAlive;

        if (!leader)
        {
            return(false);
        }

        // Search in the bounds are to try to find the most appealing entity to follow.
        Bounds bb = new Bounds(this.theEntity.position, new Vector3(this.theEntity.GetSeeDistance(), 20f, this.theEntity.GetSeeDistance()));

        //Bounds bb = new Bounds(this.theEntity.position, new Vector3(20f, 20f,20f));
        this.theEntity.world.GetEntitiesInBounds(typeof(EntityAlive), bb, this.NearbyEntities);
        DisplayLog(" Nearby Entities: " + this.NearbyEntities.Count);
        for (int i = this.NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAlive x = (EntityAlive)this.NearbyEntities[i];
            if (x != this.theEntity)
            {
                if (x.IsDead())
                {
                    continue;
                }

                DisplayLog("Nearby Entity: " + x.EntityName);
                if (x.GetAttackTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);
                    return(true);
                }

                if (x.GetRevengeTarget() == leader)
                {
                    DisplayLog(" My leader is being avenged by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }

                if (x.GetDamagedTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by something that damaged it " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }
            }
        }

        return(false);
    }
Пример #4
0
        public static void Postfix(EntityAlive __instance)
        {
            // If it's a zombie, don't do anything extra
            if (__instance.HasAnyTags(FastTags.CombineTags(FastTags.Parse("zombie"), FastTags.Parse("hostile"))))
            {
                return;
            }

            // If they have attack targets, don't interrupt them.
            if (__instance.GetAttackTarget() != null || __instance.GetRevengeTarget() != null)
            {
                return;
            }

            // Scan the area around the Entity
            List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(__instance, new Bounds(__instance.position, Vector3.one * 4f));

            if (entitiesInBounds.Count > 0)
            {
                for (int i = 0; i < entitiesInBounds.Count; i++)
                {
                    if (entitiesInBounds[i] is EntityPlayer)
                    {
                        // Check your faction relation. If you hate each other, don't stop and talk.
                        FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance, entitiesInBounds[i] as EntityAlive);
                        if (myRelationship == FactionManager.Relationship.Hate)
                        {
                            break;
                        }

                        // Give the player some space if NPC is too close.
                        if (__instance.GetDistance(entitiesInBounds[i]) < 1)
                        {
                            // Give the NPC a chance to move into position before facing the player.
                            __instance.moveHelper.SetMoveTo((entitiesInBounds[i] as EntityPlayer).GetLookVector(), false);
                            break;
                        }

                        // Turn to face the player, and stop the movement.
                        __instance.SetLookPosition(entitiesInBounds[i].getHeadPosition());
                        __instance.RotateTo(entitiesInBounds[i], 30f, 30f);
                        __instance.navigator.clearPath();
                        __instance.moveHelper.Stop();
                        break;
                    }
                }
            }
        }
Пример #5
0
    public static bool CanExecuteTask(int EntityID, EntityUtilities.Orders order)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity)
        {
            if (GetCurrentOrder(EntityID) != order)
            {
                DisplayLog("CanExecuteTask(): Current Order does not match passed in Order: " + GetCurrentOrder(EntityID));
                return(false);
            }

            Entity leader   = EntityUtilities.GetLeader(EntityID);
            float  Distance = 0f;
            if (leader)
            {
                Distance = myEntity.GetDistance(leader);
            }

            // If we have an attack or revenge target, don't execute task
            if (myEntity.GetAttackTarget() != null && myEntity.GetAttackTarget().IsAlive())
            {
                // If we have a leader and they are far away, abandon the fight and go after your leader.
                if (Distance > 20)
                {
                    DisplayLog("CanExecuteTask(): I have an Attack Target but my Leader is too far away.");
                    myEntity.SetAttackTarget(null, 0);
                    return(true);
                }

                // I have an attack target, so don't keep doing your current task
                DisplayLog("CanExecuteTask(): I have an Attack Target: " + myEntity.GetAttackTarget().ToString());
                return(false);
            }

            if (myEntity.GetRevengeTarget() != null && myEntity.GetRevengeTarget().IsAlive())
            {
                if (Distance > 20)
                {
                    DisplayLog("CanExecuteTask(): I have a Revenge Target, but my leader is too far way.");
                    myEntity.SetRevengeTarget(null);
                    return(true);
                }
                DisplayLog("CanExecuteTask(): I have a Revenge Target: " + myEntity.GetRevengeTarget().ToString());
                return(false);
            }

            if (GetCurrentOrder(EntityID) == Orders.Follow)
            {
                DisplayLog("My Current Order is Follow");
                if (Distance < 2)
                {
                    if (myEntity.moveHelper != null)
                    {
                        myEntity.moveHelper.Stop();
                        DisplayLog(" Too Close to leader. Moving to Look Vector");
                        myEntity.moveHelper.SetMoveTo((leader as EntityAlive).GetLookVector(), false);
                    }
                    return(false);
                }
            }

            return(true);
        }
        return(true);
    }
Пример #6
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        NearbyEnemies.Clear();

        EntityAlive leader = null;

        if (this.theEntity.Buffs.HasCustomVar("Leader"))
        {
            DisplayLog(" leader Detected.");
            int EntityID = (int)this.theEntity.Buffs.GetCustomVar("Leader");
            leader = this.theEntity.world.GetEntity(EntityID) as EntityAlive;
        }


        // Search in the bounds are to try to find the most appealing entity to follow.
        Bounds bb = new Bounds(this.theEntity.position, new Vector3(this.theEntity.GetSeeDistance(), 20f, this.theEntity.GetSeeDistance()));

        this.theEntity.world.GetEntitiesInBounds(typeof(EntityAlive), bb, this.NearbyEntities);
        DisplayLog(" Nearby Entities: " + this.NearbyEntities.Count);
        for (int i = this.NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAlive x = (EntityAlive)this.NearbyEntities[i];
            if (x != this.theEntity && x.IsAlive())
            {
                if (x == leader)
                {
                    continue;
                }

                DisplayLog("Nearby Entity: " + x.EntityName);
                if (CheckFactionForEnemy(x))
                {
                    NearbyEnemies.Add(x);
                }
            }

            // if one of our faction died, flee from the spot.
            if (x.factionId == this.theEntity.factionId)
            {
                if (x.GetRevengeTarget() != null)
                {
                    DisplayLog(" My Faction has a Revenge Target. I am sharing it. ");
                    this.fleeDistance = 100;
                    this.theEntity.SetRevengeTarget(x.GetRevengeTarget());
                    this.avoidEntity = x.GetRevengeTarget();
                    return(true);
                }

                if (x.IsDead())
                {
                    //DisplayLog(" One of my factions has died. Fleeing, and abandoning the herd");
                    //this.fleeDistance = 100;
                    //if (x.entityThatKilledMe != null)
                    //{
                    //    DisplayLog(" I am fleeing: " + x.entityThatKilledMe.EntityName);
                    //    this.avoidEntity = x.entityThatKilledMe;
                    //}
                    //else
                    //{
                    DisplayLog(" I don not know who killed my friend, so i am running from " + x.EntityName);
                    this.avoidEntity = x;
                    // }
                    return(true);
                }
            }
        }

        return(NearestEnemy());
    }