Esempio n. 1
0
        public override StateStatus StateThink(float delta)
        {
            base.StateThink(delta);
            bool flag   = UnityEngine.Time.time - lastDestinationTime > 25f;
            T    entity = GetEntity();

            if ((Vector3.Distance(GetDestination(), entity.transform.position) < 2f || flag) && nextRoamPositionTime == -1f)
            {
                nextRoamPositionTime = UnityEngine.Time.time + UnityEngine.Random.Range(5f, 10f);
            }
            if (nextRoamPositionTime != -1f && UnityEngine.Time.time > nextRoamPositionTime)
            {
                AIMovePoint bestRoamPoint = brain.PathFinder.GetBestRoamPoint(GetRoamAnchorPosition(), entity.ServerPosition, GetForwardDirection(), brain.Navigator.MaxRoamDistanceFromHome, brain.Navigator.BestRoamPointMaxDistance);
                if ((bool)bestRoamPoint)
                {
                    float num = Vector3.Distance(bestRoamPoint.transform.position, entity.transform.position) / 1.5f;
                    bestRoamPoint.SetUsedBy(entity, num + 11f);
                }
                lastDestinationTime = UnityEngine.Time.time;
                Vector3 insideUnitSphere = UnityEngine.Random.insideUnitSphere;
                insideUnitSphere.y = 0f;
                insideUnitSphere.Normalize();
                Vector3 destination = ((bestRoamPoint == null) ? entity.transform.position : (bestRoamPoint.transform.position + insideUnitSphere * bestRoamPoint.radius));
                SetDestination(destination);
                nextRoamPositionTime = -1f;
            }
            return(StateStatus.Running);
        }
Esempio n. 2
0
        public override StateStatus StateThink(float delta)
        {
            base.StateThink(delta);
            if (GetEntity().currentTarget == null)
            {
                return(StateStatus.Error);
            }
            float num = Vector3.Distance(GetEntity().currentTarget.transform.position, GetEntity().transform.position);

            if (num < 5f)
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.SlowWalk);
            }
            else if (num < 10f)
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Walk);
            }
            else
            {
                GetEntity().SetDesiredSpeed(HumanNPC.SpeedType.Sprint);
            }
            if (Time.time > nextPositionUpdateTime)
            {
                Random.Range(1f, 2f);
                Vector3     position    = GetEntity().transform.position;
                AIMovePoint aIMovePoint = GetEntity().GetInformationZone(GetEntity().currentTarget.transform.position).GetBestMovePointNear(maxRange: Mathf.Min(35f, GetEntity().EngagementRange() * 0.75f), targetPosition: GetEntity().currentTarget.transform.position, fromPosition: GetEntity().transform.position, minRange: 0f, checkLOS: true, forObject: GetEntity(), returnClosest: true);
                if ((bool)aIMovePoint)
                {
                    aIMovePoint.SetUsedBy(GetEntity(), 5f);
                    position = aIMovePoint.transform.position;
                    position = GetEntity().GetRandomPositionAround(position, 0f, aIMovePoint.radius - 0.3f);
                }
                else
                {
                    position = GetEntity().GetRandomPositionAround(GetEntity().currentTarget.transform.position, 1f);
                }
                GetEntity().SetDestination(position);
                nextPositionUpdateTime = Time.time + 1f;
            }
            return(StateStatus.Running);
        }