示例#1
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        NearbyEnemies.Clear();

        EntityAlive leader = EntityUtilities.GetLeaderOrOwner(this.theEntity.entityId) as EntityAlive;


        float originalView = this.theEntity.GetMaxViewAngle();

        this.theEntity.SetMaxViewAngle(360f);

        // Search in the bounds are to try to find the most appealing entity to follow.
        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 is EntityVehicle)
            {
                continue;
            }

            if (x.IsDead())
            {
                continue;
            }
            if (x != this.theEntity && x.IsAlive())
            {
                if (leader != null && x == leader)
                {
                    continue;
                }

                if (x.CanSee(this.theEntity.position))
                {
                    DisplayLog(" I can be seen by an enemy.");
                    if (!this.theEntity.CanSee(x.position))
                    {
                        DisplayLog(" I know an entity is there, but I can't see it: " + x.EntityName);
                        continue;
                    }
                }
                DisplayLog("Nearby Entity: " + x.EntityName);
                if (CheckFactionForEnemy(x))
                {
                    NearbyEnemies.Add(x);
                }
            }
        }

        this.theEntity.SetMaxViewAngle(originalView);
        return(NearestEnemy());
    }
    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;
        }

        float originalView = this.theEntity.GetMaxViewAngle();

        this.theEntity.SetMaxViewAngle(250f);

        // 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;
                }

                if (x.CanSee(this.theEntity.position))
                {
                    DisplayLog(" I can be seen by an enemy.");
                    if (!this.theEntity.CanSee(x.position))
                    {
                        DisplayLog(" I know an entity is there, but I can't see it: " + x.EntityName);
                        continue;
                    }
                }
                DisplayLog("Nearby Entity: " + x.EntityName);
                if (CheckFactionForEnemy(x))
                {
                    NearbyEnemies.Add(x);
                }
            }
        }

        this.theEntity.SetMaxViewAngle(originalView);
        return(NearestEnemy());
    }
示例#3
0
    // Returns false if its not within AI Range
    public static bool CheckAIRange(int EntityID, int targetEntity)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return(false);
        }
        EntityAlive myTarget = GameManager.Instance.World.GetEntity(targetEntity) as EntityAlive;

        if (myTarget == null)
        {
            return(false);
        }

        // Find the max range for the weapon
        // Example Range:  50
        //   Hold Ground Distance between 20 to 50
        //   Retreat distance is 20%, so 20
        float MaxRangeForWeapon = EffectManager.GetValue(PassiveEffects.MaxRange, myEntity.inventory.holdingItemItemValue, 60f, myEntity, null, myEntity.inventory.holdingItem.ItemTags, true, true, true, true, 1, true);

        MaxRangeForWeapon = MaxRangeForWeapon * 2;
        float HoldGroundDistance = (float)MaxRangeForWeapon * 0.80f; // minimum range to hold ground
        float RetreatDistance    = (float)MaxRangeForWeapon * 0.30f; // start retreating at this distance.
        float distanceSq         = myTarget.GetDistanceSq(myEntity);

        float MinMeleeRange = GetFloatValue(EntityID, "MinimumMeleeRange");

        if (MinMeleeRange == -1)
        {
            MinMeleeRange = 2;
        }

        DisplayLog(myEntity.EntityName + " Max Range: " + MaxRangeForWeapon + " Hold Ground: " + HoldGroundDistance + " Retreatdistance: " + RetreatDistance + " Entity Distance: " + distanceSq);


        // if they are too close, switch to melee
        if (distanceSq <= MinMeleeRange)
        {
            return(false);
        }


        // Hold your ground
        if (distanceSq > RetreatDistance && distanceSq <= HoldGroundDistance) // distance greater than 20%  of the range of the weapon
        {
            DisplayLog(myEntity.EntityName + " Stopping: Retreat: " + (distanceSq > RetreatDistance) + " Hold: " + (distanceSq <= HoldGroundDistance));
            Stop(EntityID);
        }
        // Back away!
        if (distanceSq > MinMeleeRange && distanceSq <= RetreatDistance)
        {
            BackupHelper(EntityID, myTarget.position, 40);
        }


        // if we can't see the target, move closer rather than staying at range.
        if (!myEntity.CanSee(myTarget))
        {
            DisplayLog(myEntity.EntityName + " I cannot see my target.");
            return(false);
        }


        // if the entity is half the distance away, approach
        if (distanceSq > 200)
        {
            return(false);
        }

        return(true);
    }