public static bool SampleCircleWaterDepthOnly(NavPointSampler.SampleCount sampleCount, Vector3 center, float radius, NavPointSampler.SampleScoreParams scoreParams, ref List <NavPointSample> samples)
        {
            if (scoreParams.Agent == null || scoreParams.Agent.GetNavAgent == null)
            {
                return(false);
            }
            float single = 90f;

            if (sampleCount == NavPointSampler.SampleCount.Eight)
            {
                single = 45f;
            }
            else if (sampleCount == NavPointSampler.SampleCount.Sixteen)
            {
                single = 22.5f;
            }
            for (float i = 0f; i < 360f; i += single)
            {
                NavPointSample navPointSample = NavPointSampler.SamplePointWaterDepthOnly(NavPointSampler.GetPointOnCircle(center, radius, i), 2f);
                if (navPointSample.Score > 0f)
                {
                    samples.Add(navPointSample);
                }
            }
            if (samples.Count > 0)
            {
                samples.Sort(NavPointSampler.NavPointSampleComparer);
            }
            return(samples.Count > 0);
        }
Beispiel #2
0
        private static bool NavigateInDirOfBestSample(
            BaseContext c,
            NavPointSampler.SampleCount sampleCount,
            float radius,
            NavPointSampler.SampleFeatures features,
            float minRange,
            float maxRange)
        {
            List <NavPointSample> navPointSampleList1 = c.AIAgent.RequestNavPointSamplesInCircle(sampleCount, radius, features);

            if (navPointSampleList1 == null)
            {
                return(false);
            }
            foreach (NavPointSample navPointSample1 in navPointSampleList1)
            {
                Vector3        vector3         = Vector3.op_Subtraction(navPointSample1.Position, c.Position);
                Vector3        normalized      = ((Vector3) ref vector3).get_normalized();
                NavPointSample navPointSample2 = NavPointSampler.SamplePoint(Vector3.op_Addition(c.Position, Vector3.op_Addition(Vector3.op_Multiply(normalized, minRange), Vector3.op_Multiply(normalized, (maxRange - minRange) * Random.get_value()))), new NavPointSampler.SampleScoreParams()
                {
                    WaterMaxDepth = c.AIAgent.GetStats.MaxWaterDepth,
                    Agent         = c.AIAgent,
                    Features      = features
                });
                if (!Mathf.Approximately(navPointSample2.Score, 0.0f))
                {
                    NavigateToOperator.MakeUnstuck(c);
                    Vector3 position = navPointSample2.Position;
                    c.AIAgent.Destination = position;
                    c.AIAgent.SetTargetPathStatus(0.05f);
                    return(true);
                }
            }
            float num = 2f;
            List <NavPointSample> navPointSampleList2 = c.AIAgent.RequestNavPointSamplesInCircleWaterDepthOnly(sampleCount, radius, num);

            if (navPointSampleList2 == null)
            {
                return(false);
            }
            foreach (NavPointSample navPointSample1 in navPointSampleList2)
            {
                Vector3        vector3         = Vector3.op_Subtraction(navPointSample1.Position, c.Position);
                Vector3        normalized      = ((Vector3) ref vector3).get_normalized();
                NavPointSample navPointSample2 = NavPointSampler.SamplePointWaterDepthOnly(Vector3.op_Addition(c.Position, Vector3.op_Addition(Vector3.op_Multiply(normalized, minRange), Vector3.op_Multiply(normalized, (maxRange - minRange) * Random.get_value()))), num);
                if (!Mathf.Approximately(navPointSample2.Score, 0.0f))
                {
                    NavigateToOperator.MakeUnstuck(c);
                    Vector3 position = navPointSample2.Position;
                    c.AIAgent.Destination = position;
                    c.AIAgent.SetTargetPathStatus(0.05f);
                    return(true);
                }
            }
            return(false);
        }
        public static float FlankPointValue(Vector3 point, IAIAgent agent)
        {
            if (Object.op_Equality((Object)agent.AttackTarget, (Object)null))
            {
                return(0.0f);
            }
            float num = 0.0f;

            return(!NavPointSampler.PointDirectnessToTarget(point, agent.Entity.ServerPosition, agent.AttackTarget.ServerPosition, out num) || (double)num < -0.100000001490116 || (double)num > 0.100000001490116 ? 0.0f : 1f);
        }
        public static bool SampleCircle(
            NavPointSampler.SampleCount sampleCount,
            Vector3 center,
            float radius,
            NavPointSampler.SampleScoreParams scoreParams,
            ref List <NavPointSample> samples)
        {
            if (scoreParams.Agent == null || Object.op_Equality((Object)scoreParams.Agent.GetNavAgent, (Object)null))
            {
                return(false);
            }
            float num1 = 90f;

            switch (sampleCount)
            {
            case NavPointSampler.SampleCount.Eight:
                num1 = 45f;
                break;

            case NavPointSampler.SampleCount.Sixteen:
                num1 = 22.5f;
                break;
            }
            float num2 = 2f + (float)NavPointSampler.GetFeatureCount((int)scoreParams.Features);

            for (float degrees = 0.0f; (double)degrees < 360.0; degrees += num1)
            {
                NavPointSample navPointSample = NavPointSampler.SamplePoint(NavPointSampler.GetPointOnCircle(center, radius, degrees), scoreParams);
                if ((double)navPointSample.Score > 0.0)
                {
                    samples.Add(navPointSample);
                    if ((double)navPointSample.Score >= (double)num2)
                    {
                        break;
                    }
                }
            }
            if (samples.Count == 0)
            {
                for (float degrees = 0.0f; (double)degrees < 360.0; degrees += num1)
                {
                    NavPointSample navPointSample = NavPointSampler.SamplePointWaterDepthOnly(NavPointSampler.GetPointOnCircle(center, radius, degrees), 2f);
                    if ((double)navPointSample.Score > 0.0)
                    {
                        samples.Add(navPointSample);
                    }
                }
            }
            if (samples.Count > 0)
            {
                samples.Sort((IComparer <NavPointSample>)NavPointSampler.NavPointSampleComparer);
            }
            return(samples.Count > 0);
        }
        public static NavPointSample SamplePoint(
            Vector3 pos,
            NavPointSampler.SampleScoreParams scoreParams)
        {
            if (Object.op_Inequality((Object)TerrainMeta.HeightMap, (Object)null))
            {
                pos.y = (__Null)(double)TerrainMeta.HeightMap.GetHeight(pos);
            }
            float num = NavPointSampler._WaterDepth(pos, scoreParams.WaterMaxDepth) * 2f;

            if ((double)num > 0.0 && NavPointSampler._SampleNavMesh(ref pos, scoreParams.Agent))
            {
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.DiscourageSharpTurns) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler._DiscourageSharpTurns(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromTarget) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.RetreatPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.ApproachTarget) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.ApproachPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.FlankTarget) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.FlankPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromDirection) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.RetreatFromDirection(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromExplosive) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.RetreatPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.TopologyPreference) > NavPointSampler.SampleFeatures.None)
                {
                    num += NavPointSampler.TopologyPreference(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RangeFromSpawn) > NavPointSampler.SampleFeatures.None)
                {
                    num *= NavPointSampler.RangeFromHome(pos, scoreParams.Agent);
                }
            }
            return(new NavPointSample()
            {
                Position = pos,
                Score = num
            });
        }
        public static NavPointSample SamplePointWaterDepthOnly(Vector3 pos, float depth)
        {
            if (TerrainMeta.HeightMap != null)
            {
                pos.y = TerrainMeta.HeightMap.GetHeight(pos);
            }
            float single = NavPointSampler._WaterDepth(pos, 2f) * 2f;

            return(new NavPointSample()
            {
                Position = pos,
                Score = single
            });
        }
        public static float ApproachPointValue(Vector3 point, IAIAgent agent)
        {
            if (Object.op_Equality((Object)agent.AttackTarget, (Object)null))
            {
                return(0.0f);
            }
            float num = 0.0f;

            if (!NavPointSampler.PointDirectnessToTarget(point, agent.Entity.ServerPosition, agent.AttackTarget.ServerPosition, out num) || (double)num < 0.5)
            {
                return(0.0f);
            }
            return(num);
        }
        public static NavPointSample SamplePointWaterDepthOnly(Vector3 pos, float depth)
        {
            if (Object.op_Inequality((Object)TerrainMeta.HeightMap, (Object)null))
            {
                pos.y = (__Null)(double)TerrainMeta.HeightMap.GetHeight(pos);
            }
            float num = NavPointSampler._WaterDepth(pos, 2f) * 2f;

            return(new NavPointSample()
            {
                Position = pos,
                Score = num
            });
        }
        public static NavPointSample SamplePoint(Vector3 pos, NavPointSampler.SampleScoreParams scoreParams)
        {
            if (TerrainMeta.HeightMap != null)
            {
                pos.y = TerrainMeta.HeightMap.GetHeight(pos);
            }
            float single = NavPointSampler._WaterDepth(pos, scoreParams.WaterMaxDepth) * 2f;

            if (single > 0f && NavPointSampler._SampleNavMesh(ref pos, scoreParams.Agent))
            {
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.DiscourageSharpTurns) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler._DiscourageSharpTurns(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromTarget) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.RetreatPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.ApproachTarget) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.ApproachPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.FlankTarget) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.FlankPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromDirection) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.RetreatFromDirection(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RetreatFromExplosive) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.RetreatPointValue(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.TopologyPreference) > NavPointSampler.SampleFeatures.None)
                {
                    single += NavPointSampler.TopologyPreference(pos, scoreParams.Agent);
                }
                if ((scoreParams.Features & NavPointSampler.SampleFeatures.RangeFromSpawn) > NavPointSampler.SampleFeatures.None)
                {
                    single *= NavPointSampler.RangeFromHome(pos, scoreParams.Agent);
                }
            }
            return(new NavPointSample()
            {
                Position = pos,
                Score = single
            });
        }
        public static float RetreatPointValueExplosive(Vector3 point, IAIAgent agent)
        {
            BaseContext context = agent.GetContext(Guid.Empty) as BaseContext;

            if (context == null || context.DeployedExplosives.Count == 0 || (Object.op_Equality((Object)context.DeployedExplosives[0], (Object)null) || context.DeployedExplosives[0].IsDestroyed))
            {
                return(0.0f);
            }
            float num = 0.0f;

            if (!NavPointSampler.PointDirectnessToTarget(point, agent.Entity.ServerPosition, context.DeployedExplosives[0].ServerPosition, out num) || (double)num > -0.5)
            {
                return(0.0f);
            }
            return(num * -1f);
        }
        private static bool NavigateInDirOfBestSample(NPCHumanContext c, NavPointSampler.SampleCount sampleCount, float radius, NavPointSampler.SampleFeatures features, float minRange, float maxRange)
        {
            bool flag;
            List <NavPointSample> navPointSamples = c.AIAgent.RequestNavPointSamplesInCircle(sampleCount, radius, features);

            if (navPointSamples == null)
            {
                return(false);
            }
            List <NavPointSample> .Enumerator enumerator = navPointSamples.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Vector3 position = (enumerator.Current.Position - c.Position).normalized;
                    Vector3 vector3  = c.Position + (position * minRange) + (position * ((maxRange - minRange) * UnityEngine.Random.@value));
                    if (c.AIAgent.AttackTarget != null && !NavPointSampler.IsValidPointDirectness(vector3, c.Position, c.EnemyPosition))
                    {
                        continue;
                    }
                    NavPointSampler.SampleScoreParams sampleScoreParam = new NavPointSampler.SampleScoreParams()
                    {
                        WaterMaxDepth = c.AIAgent.GetStats.MaxWaterDepth,
                        Agent         = c.AIAgent,
                        Features      = features
                    };
                    NavPointSample navPointSample = NavPointSampler.SamplePoint(vector3, sampleScoreParam);
                    if (Mathf.Approximately(navPointSample.Score, 0f) || Mathf.Approximately(navPointSample.Position.sqrMagnitude, 0f))
                    {
                        continue;
                    }
                    HumanNavigateToOperator.MakeUnstuck(c);
                    vector3 = navPointSample.Position;
                    c.AIAgent.GetNavAgent.destination = vector3;
                    c.Human.SetTargetPathStatus(0.05f);
                    c.AIAgent.SetFact(NPCPlayerApex.Facts.IsMoving, 1, true, false);
                    flag = true;
                    return(flag);
                }
                return(false);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(flag);
        }
        public static float FlankPointValue(Vector3 point, IAIAgent agent)
        {
            if (agent.AttackTarget == null)
            {
                return(0f);
            }
            float single = 0f;

            if (!NavPointSampler.PointDirectnessToTarget(point, agent.Entity.ServerPosition, agent.AttackTarget.ServerPosition, out single))
            {
                return(0f);
            }
            if (single >= -0.1f && single <= 0.1f)
            {
                return(1f);
            }
            return(0f);
        }
        public static float RetreatPointValueExplosive(Vector3 point, IAIAgent agent)
        {
            BaseContext context = agent.GetContext(Guid.Empty) as BaseContext;

            if (context == null || context.DeployedExplosives.Count == 0 || context.DeployedExplosives[0] == null || context.DeployedExplosives[0].IsDestroyed)
            {
                return(0f);
            }
            float single = 0f;

            if (!NavPointSampler.PointDirectnessToTarget(point, agent.Entity.ServerPosition, context.DeployedExplosives[0].ServerPosition, out single))
            {
                return(0f);
            }
            if (single > -0.5f)
            {
                return(0f);
            }
            return(single * -1f);
        }
        private static bool NavigateInDirOfBestSample(BaseContext c, NavPointSampler.SampleCount sampleCount, float radius, NavPointSampler.SampleFeatures features, float minRange, float maxRange)
        {
            Vector3 position;
            bool    flag;
            List <NavPointSample> navPointSamples = c.AIAgent.RequestNavPointSamplesInCircle(sampleCount, radius, features);

            if (navPointSamples == null)
            {
                return(false);
            }
            foreach (NavPointSample navPointSample in navPointSamples)
            {
                position = navPointSample.Position - c.Position;
                Vector3 vector3   = position.normalized;
                Vector3 position1 = c.Position + (vector3 * minRange) + (vector3 * ((maxRange - minRange) * UnityEngine.Random.@value));
                NavPointSampler.SampleScoreParams sampleScoreParam = new NavPointSampler.SampleScoreParams()
                {
                    WaterMaxDepth = c.AIAgent.GetStats.MaxWaterDepth,
                    Agent         = c.AIAgent,
                    Features      = features
                };
                NavPointSample navPointSample1 = NavPointSampler.SamplePoint(position1, sampleScoreParam);
                if (Mathf.Approximately(navPointSample1.Score, 0f))
                {
                    continue;
                }
                NavigateToOperator.MakeUnstuck(c);
                position1             = navPointSample1.Position;
                c.AIAgent.Destination = position1;
                c.AIAgent.SetTargetPathStatus(0.05f);
                flag = true;
                return(flag);
            }
            float single = 2f;

            navPointSamples = c.AIAgent.RequestNavPointSamplesInCircleWaterDepthOnly(sampleCount, radius, single);
            if (navPointSamples == null)
            {
                return(false);
            }
            List <NavPointSample> .Enumerator enumerator = navPointSamples.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    position = enumerator.Current.Position - c.Position;
                    Vector3        vector31        = position.normalized;
                    Vector3        position2       = c.Position + (vector31 * minRange) + (vector31 * ((maxRange - minRange) * UnityEngine.Random.@value));
                    NavPointSample navPointSample2 = NavPointSampler.SamplePointWaterDepthOnly(position2, single);
                    if (Mathf.Approximately(navPointSample2.Score, 0f))
                    {
                        continue;
                    }
                    NavigateToOperator.MakeUnstuck(c);
                    position2             = navPointSample2.Position;
                    c.AIAgent.Destination = position2;
                    c.AIAgent.SetTargetPathStatus(0.05f);
                    flag = true;
                    return(flag);
                }
                return(false);
            }
            finally
            {
                ((IDisposable)enumerator).Dispose();
            }
            return(flag);
        }