示例#1
0
        public virtual List <GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition)
        {
            bool disableFriendlyFire  = PlayerPrefs.GetInt("DisableFriendlyFire", 0) == 1;
            bool confusedArentFriends = PlayerPrefs.GetInt("TargetTurnedEnemies", 0) == 1;
            List <GameObject> list    = new List <GameObject>();
            float             num     = this.AdjustedBlastRadius;
            float             num2    = num;

            if (this.ValidTargets == AttackBase.TargetType.All && this.BlastRadius < this.AdjustedBlastRadius)
            {
                num = this.BlastRadius;
            }
            foreach (Faction current in Faction.ActiveFactionComponents)
            {
                if (!(current == null))
                {
                    if (!(current.gameObject == base.Owner) || this.DamageAngleDegrees <= 0f || this.DamageAngleDegrees >= 360f)
                    {
                        Vector3 vector       = current.transform.position - hitPosition;
                        float   sqrMagnitude = vector.sqrMagnitude;
                        if (!this.ExcludeTarget || sqrMagnitude > 1.401298E-45f)
                        {
                            float   cachedRadius = current.CachedRadius;
                            float   num3         = (num + cachedRadius) * (num + cachedRadius);
                            float   num4         = (num2 + cachedRadius) * (num2 + cachedRadius);
                            Vector3 vector2      = vector.normalized;
                            if (this.TargetAngle > 0f)
                            {
                                vector2 = Quaternion.Euler(0f, this.TargetAngle, 0f) * vector2;
                            }
                            float num5  = Vector3.Angle(parentForward, vector2);
                            bool  flag  = num5 <= this.DamageAngleDegrees * 0.5f;
                            bool  flag2 = sqrMagnitude < 1.401298E-45f || (flag && sqrMagnitude <= num4);
                            bool  flag3 = sqrMagnitude < 1.401298E-45f || (flag && sqrMagnitude <= num3);
                            if (flag2 && GameUtilities.LineofSight(hitPosition, current.gameObject.transform.position, 1f, false, true))
                            {
                                if ((this.ValidTargets == TargetType.Friendly || this.ValidTargets == TargetType.FriendlyIncludingCharmed) && !base.IsValidTarget(current.gameObject, caster, AttackBase.TargetType.Hostile) && base.IsValidTarget(current.gameObject, caster))
                                {
                                    if (confusedArentFriends)
                                    {
                                        Faction casterFaction = caster.GetComponent <Faction>();
                                        var     aiController  = GameUtilities.FindActiveAIController(current.gameObject);
                                        if (aiController == null ||
                                            aiController.GetOriginalTeam().GetRelationship(casterFaction.CurrentTeam) != Faction.Relationship.Hostile)
                                        {
                                            list.Add(current.gameObject);
                                        }
                                    }
                                    else
                                    {
                                        list.Add(current.gameObject);
                                    }
                                }
                                else if (
                                    (this.ValidTargets == AttackBase.TargetType.Hostile && !base.IsValidTarget(current.gameObject, caster)) || (!flag3 && this.ValidTargets == TargetType.All && !base.IsValidTarget(current.gameObject, caster, TargetType.Hostile)))
                                {
                                    if (IsValidTarget(current.gameObject, caster, TargetType.All) && confusedArentFriends)
                                    {
                                        Faction casterFaction = caster.GetComponent <Faction>();
                                        var     aiController  = GameUtilities.FindActiveAIController(current.gameObject);
                                        if (aiController != null &&
                                            aiController.GetOriginalTeam().GetRelationship(casterFaction.CurrentTeam) == Faction.Relationship.Hostile)
                                        {
                                            list.Add(current.gameObject);
                                        }
                                    }
                                }

                                else if (this.ValidTargets == AttackBase.TargetType.All && base.IsValidTarget(current.gameObject, caster, AttackBase.TargetType.Hostile))
                                {
                                    Faction casterFaction = caster.GetComponent <Faction>();

                                    if (disableFriendlyFire)
                                    {
                                        if (!(current.isPartyMember || casterFaction.IsFriendly(current)))
                                        {
                                            list.Add(current.gameObject);
                                        }
                                    }
                                    else
                                    {
                                        list.Add(current.gameObject);
                                    }
                                }
                                else if (flag3 && base.IsValidTarget(current.gameObject, caster))
                                {
                                    if (disableFriendlyFire)
                                    {
                                        if (this.ValidTargets == TargetType.All)
                                        {
                                            Faction casterFaction = caster.GetComponent <Faction>();

                                            if (!(current.isPartyMember || casterFaction.IsFriendly(current)))
                                            {
                                                list.Add(current.gameObject);
                                            }
                                        }
                                        else
                                        {
                                            list.Add(current.gameObject);
                                        }
                                    }
                                    else
                                    {
                                        list.Add(current.gameObject);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            int num6 = list.IndexOf(base.Owner);

            if (num6 > 0)
            {
                list[num6] = list[0];
                list[0]    = base.Owner;
            }
            return(list);
        }
示例#2
0
        public virtual List <GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition)
        {
            /*
             *      The purpose of this method is to return a collection of the targets of a given area attack, according to the rules of the game.
             */
            bool disableFriendlyFire = IEModOptions.DisableFriendlyFire;

            ;
            bool  confusedArentFriends = IEModOptions.TargetTurnedEnemies;
            var   list        = new List <GameObject>();
            float blastRadius = AdjustedBlastRadius;
            //note that ajdBlastRadius is the wider blast radius.
            float adjBlastRadius = blastRadius;

            if (ValidTargets == TargetType.All && BlastRadius < AdjustedBlastRadius)
            {
                blastRadius = BlastRadius;
            }
            foreach (Faction current in Faction.ActiveFactionComponents)
            {
                if (current == null)
                {
                    continue;
                }
                if (current.gameObject == Owner && !(DamageAngleDegrees <= 0f) && !(DamageAngleDegrees >= 360f))
                {
                    continue;
                }
                Vector3 vector       = current.transform.position - hitPosition;
                float   sqrMagnitude = vector.sqrMagnitude;
                if (ExcludeTarget && !(sqrMagnitude > float.Epsilon))
                {
                    continue;
                }
                float   cachedRadius          = current.CachedRadius;
                float   sqrBlastRadiusPlus    = (blastRadius + cachedRadius) * (blastRadius + cachedRadius);
                float   sqrAdjBlastRadiusPlus = (adjBlastRadius + cachedRadius) * (adjBlastRadius + cachedRadius);
                Vector3 vector2 = vector.normalized;
                if (TargetAngle > 0f)
                {
                    vector2 = Quaternion.Euler(0f, TargetAngle, 0f) * vector2;
                }
                bool isWithinAngle      = Vector3.Angle(parentForward, vector2) <= DamageAngleDegrees * 0.5f;
                bool isWithinAdjRadius  = sqrMagnitude < float.Epsilon || (isWithinAngle && sqrMagnitude <= sqrAdjBlastRadiusPlus);
                bool isWithinPureRadius = sqrMagnitude < float.Epsilon || (isWithinAngle && sqrMagnitude <= sqrBlastRadiusPlus);
                if (!isWithinAdjRadius || !GameUtilities.LineofSight(hitPosition, current.gameObject.transform.position, 1f, false, true))
                {
                    //if the target isn't even within the adj (wider) radius OR isn't within line of sight (there is cover)
                    //it's not in the target list.
                    continue;
                }
                Faction casterFaction = caster.GetComponent <Faction>();
                //if isValidForHostile, that means that the target is valid when it is hostile. This means that the AOE is a negative effect
                var isValidForHostile = IsValidTarget(current.gameObject, caster, TargetType.Hostile);
                var isValidTarget     = IsValidTarget(current.gameObject, caster);
                var isCurrentFriendly = (current.isPartyMember || casterFaction.IsFriendly(current));

                //I tried organizing the code by setting the whole FindActiveAIController thing into a variable, but in some situations it throws NullReferenceExceptions.
                //these situations seem to be avoided by doing it like this.
                if ((ValidTargets == TargetType.Friendly || ValidTargets == TargetType.FriendlyIncludingCharmed) &&
                    !isValidForHostile &&
                    isValidTarget)
                {
                    if (!confusedArentFriends || (GameUtilities.FindActiveAIController(current.gameObject) ? GameUtilities.FindActiveAIController(current.gameObject).GetOriginalTeam()?.GetRelationship(casterFaction.CurrentTeam) : null) != Faction.Relationship.Hostile)
                    {
                        list.Add(current.gameObject);
                    }
                }
                else if (
                    (ValidTargets == TargetType.Hostile && !isValidTarget) ||
                    (!isWithinPureRadius && ValidTargets == TargetType.All &&
                     !isValidForHostile))
                {
                    if (IsValidTarget(current.gameObject, caster, TargetType.All) && confusedArentFriends && (GameUtilities.FindActiveAIController(current.gameObject) ? GameUtilities.FindActiveAIController(current.gameObject).GetOriginalTeam()?.GetRelationship(casterFaction.CurrentTeam) : null) == Faction.Relationship.Hostile)
                    {
                        list.Add(current.gameObject);
                    }
                }
                else if (ValidTargets == TargetType.All && isValidForHostile)
                {
                    if (!disableFriendlyFire || !isCurrentFriendly)
                    {
                        list.Add(current.gameObject);
                    }
                }
                else if (isWithinPureRadius && isValidTarget)
                {
                    //in this case,
                    if (!disableFriendlyFire || ValidTargets != TargetType.All || !isCurrentFriendly)
                    {
                        list.Add(current.gameObject);
                    }
                }
            }
            int num6 = list.IndexOf(Owner);

            if (num6 > 0)
            {
                list[num6] = list[0];
                list[0]    = Owner;
            }
            return(list);
        }
示例#3
0
        private GameObject ScanForTargetToAttackImproved(List <GameObject> potentialTargets, GameObject owner, AIController aiController)
        {
            Faction ownerFaction = owner.GetComponent <Faction>();

            if (ownerFaction == null)
            {
                Debug.LogError(owner.name + " doesn't have a faction.", owner);
                return(null);
            }
            float perceptionDistance = aiController.PerceptionDistance;

            if (aiController.InCombat)
            {
                perceptionDistance *= 2;                 // was += 6f;
            }

            var targets          = new List <GameObject>(potentialTargets.Count);
            var targetDistances  = new List <float>(potentialTargets.Count);
            var targetStaminas   = new List <float>(potentialTargets.Count);
            var targetIsEngageds = new List <bool>(potentialTargets.Count);
            var maxStamina       = float.MinValue;

            for (int i = 0; i < potentialTargets.Count; i++)
            {
                GameObject potentialTarget = potentialTargets[i];
                if (ownerFaction.IsHostile(potentialTarget))
                {
                    Health targetHealth = potentialTarget.GetComponent <Health>();
                    if (!(targetHealth == null) && targetHealth.Targetable)
                    {
                        AIController targetAI = potentialTarget.GetComponent <AIController>();
                        if (!(targetAI == null))
                        {
                            CharacterStats targetStats = potentialTarget.GetComponent <CharacterStats>();
                            if (!(targetStats == null))
                            {
                                float targetDistance = GameUtilities.V3Distance2D(owner.transform.position, potentialTarget.transform.position);
                                bool  isValid        = false;
                                if (targetStats.NoiseLevelRadius > targetDistance)
                                {
                                    isValid = true;
                                    GameState.InStealthMode = false;
                                }
                                else if (targetDistance <= perceptionDistance && GameUtilities.LineofSight(owner.transform.position, targetAI.transform.position, 1f, false))
                                {
                                    isValid = true;
                                }

                                if (isValid)
                                {
                                    targets.Add(potentialTarget);
                                    targetDistances.Add(targetDistance);
                                    targetStaminas.Add(targetHealth.CurrentStamina);
                                    targetIsEngageds.Add(aiController.HasEngaged(potentialTarget));
                                    maxStamina = Math.Max(targetHealth.CurrentStamina, maxStamina);
                                }
                            }
                        }
                    }
                }
            }

            if (GameState.InStealthMode)
            {
                return(null);
            }

            const float DISTANCE_WEIGHT       = 1f;
            const float STAMINA_WEIGHT        = 1f;
            const float FICKLENESS_WEIGHT     = 0.5f;
            const float ENGAGED_WEIGHT        = -10f;      // must be more than the other weights combined
            const float CURRENT_TARGET_WEIGHT = 2f;
            var         bestWeight            = float.MaxValue;
            GameObject  result = null;

            for (int i = 0; i < targets.Count; ++i)
            {
                var distanceValue      = (targetDistances[i] / perceptionDistance) * DISTANCE_WEIGHT;
                var staminaValue       = (targetStaminas[i] / maxStamina) * STAMINA_WEIGHT;           // targets with less stamina are more attractive
                var isCurrentTarget    = ((Mod_AI_PreTargetScanner)(object)this).DeprioritizeCurrentTarget && (targets[i] == aiController.CurrentTarget);
                var currentTargetValue = isCurrentTarget ? CURRENT_TARGET_WEIGHT : 0;
                var engagedValue       = (targetIsEngageds[i] ? 1 : 0) * ENGAGED_WEIGHT;
                var fickleValue        = Random.Range(0f, 1f) * FICKLENESS_WEIGHT;           // a little randomness is useful

                var value = distanceValue + staminaValue + currentTargetValue + engagedValue + fickleValue;
                if (value < bestWeight)
                {
                    bestWeight = value;
                    result     = targets[i];
                }
            }

            return(result);
        }
示例#4
0
        public virtual List <GameObject> FindAoeTargetsNew(GameObject caster, Vector3 parentForward, Vector3 hitPosition, bool forUi)
        {
            bool flag;
            bool flag1;
            List <GameObject> gameObjects         = new List <GameObject>();
            float             adjustedBlastRadius = this.AdjustedBlastRadius;
            float             single = adjustedBlastRadius;

            if (this.ValidTargets == AttackBase.TargetType.All && this.BlastRadius < this.AdjustedBlastRadius)
            {
                adjustedBlastRadius = this.BlastRadius;
            }
            foreach (Faction activeFactionComponent in Faction.ActiveFactionComponents)
            {
                if (activeFactionComponent != null)
                {
                    if (!(activeFactionComponent.gameObject == base.Owner) || this.DamageAngleDegrees <= 0f || this.DamageAngleDegrees >= 360f)
                    {
                        Vector3 vector3 = activeFactionComponent.transform.position - hitPosition;
                        float   single1 = vector3.sqrMagnitude;
                        if (this.ExcludeTarget && single1 <= 1.401298E-45f)
                        {
                            continue;
                        }
                        float   cachedRadius = activeFactionComponent.CachedRadius;
                        float   single2      = (adjustedBlastRadius + cachedRadius) * (adjustedBlastRadius + cachedRadius);
                        float   single3      = (single + cachedRadius) * (single + cachedRadius);
                        Vector3 vector31     = vector3.normalized;
                        if (this.TargetAngle > 0f)
                        {
                            vector31 = Quaternion.Euler(0f, this.TargetAngle, 0f) * vector31;
                        }
                        float single4            = Vector3.Angle(parentForward, vector31);
                        bool  damageAngleDegrees = single4 <= this.DamageAngleDegrees * 0.5f;
                        if (single1 < 1.401298E-45f)
                        {
                            flag = true;
                        }
                        else
                        {
                            flag = (!damageAngleDegrees ? false : single1 <= single3);
                        }
                        bool flag2 = flag;
                        if (single1 < 1.401298E-45f)
                        {
                            flag1 = true;
                        }
                        else
                        {
                            flag1 = (!damageAngleDegrees ? false : single1 <= single2);
                        }
                        bool flag3 = flag1;
                        if (!flag2 || !GameUtilities.LineofSight(hitPosition, activeFactionComponent.gameObject.transform.position, 1f, false, true))
                        {
                            continue;
                        }
                        if (this.ValidTargets != AttackBase.TargetType.All || !base.IsValidTarget(activeFactionComponent.gameObject, caster, AttackBase.TargetType.Hostile))
                        {
                            if (!flag3 || !base.IsValidTarget(activeFactionComponent.gameObject, caster))
                            {
                                continue;
                            }

                            var casterFaction = caster.GetComponent <Faction>();
                            if (IEModOptions.DisableFriendlyFire && ValidTargets == TargetType.All && mod_AttackBase.FriendlyRightNowAndAlsoWhenConfused(activeFactionComponent.gameObject, caster))
                            {
                                continue;
                            }

                            gameObjects.Add(activeFactionComponent.gameObject);
                        }
                        else
                        {
                            gameObjects.Add(activeFactionComponent.gameObject);
                        }
                    }
                }
            }
            int num = gameObjects.IndexOf(base.Owner);

            if (num > 0)
            {
                gameObjects[num] = gameObjects[0];
                gameObjects[0]   = base.Owner;
            }
            return(gameObjects);
        }
示例#5
0
        protected GameObject ScanForTargetToAttackNew(List <GameObject> potentialTargets, GameObject owner, AIController aiController)
        {
            if (IEModOptions.ImprovedAI)             // added this if statement
            {
                return(ScanForTargetToAttackImproved(potentialTargets, owner, aiController));
            }

            float      num       = 3.40282347E+38f;
            GameObject result    = null;
            Faction    component = owner.GetComponent <Faction>();

            if (component == null)
            {
                Debug.LogError(owner.name + " doesn't have a faction.", owner);
                return(null);
            }
            float num2 = aiController.PerceptionDistance;

            if (aiController.InCombat)
            {
                num2 += 6f;
            }
            for (int i = 0; i < potentialTargets.Count; i++)
            {
                GameObject gameObject = potentialTargets[i];
                if (component.IsHostile(gameObject))
                {
                    Health component2 = gameObject.GetComponent <Health>();
                    if (!(component2 == null) && component2.Targetable)
                    {
                        AIController component3 = gameObject.GetComponent <AIController>();
                        if (!(component3 == null))
                        {
                            CharacterStats component4 = gameObject.GetComponent <CharacterStats>();
                            if (!(component4 == null))
                            {
                                float num3 = GameUtilities.V3Distance2D(owner.transform.position, gameObject.transform.position);
                                float num4 = num2;
                                if (component4.NoiseLevelRadius > num3)
                                {
                                    result = gameObject;
                                    GameState.InStealthMode = false;
                                }
                                if (num3 <= num4)
                                {
                                    if (GameUtilities.LineofSight(owner.transform.position, component3.transform.position, 1f, false))
                                    {
                                        float num5 = 0f;
                                        num5 += num3 / num4 * 2f;
                                        num5 += component2.CurrentStamina / component2.MaxStamina * 0.5f;
                                        num5 += ((!aiController.HasEngaged(gameObject)) ? 0f : -3f);
                                        if (num5 < num && !GameState.InStealthMode)
                                        {
                                            num    = num5;
                                            result = gameObject;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }