Exemple #1
0
    public void UpdateMovement_Patrol()
    {
        if (patrolPath == null || UnityEngine.Time.time < nextPatrolTime)
        {
            return;
        }
        nextPatrolTime = UnityEngine.Time.time + 20f;
        if ((HasPath() && !IsAtFinalDestination()) || Interface.CallHook("OnBradleyApcPatrol", this) != null)
        {
            return;
        }
        PathInterestNode    randomInterestNodeAwayFrom = patrolPath.GetRandomInterestNodeAwayFrom(base.transform.position);
        BasePathNode        closestToPoint             = patrolPath.GetClosestToPoint(randomInterestNodeAwayFrom.transform.position);
        BasePathNode        basePathNode = null;
        bool                flag         = false;
        List <BasePathNode> nodes        = Facepunch.Pool.GetList <BasePathNode>();

        if (GetEngagementPath(ref nodes))
        {
            flag         = true;
            basePathNode = nodes[nodes.Count - 1];
        }
        else
        {
            basePathNode = patrolPath.GetClosestToPoint(base.transform.position);
        }
        if (!(Vector3.Distance(finalDestination, closestToPoint.transform.position) > 2f))
        {
            return;
        }
        if (closestToPoint == basePathNode)
        {
            currentPath.Clear();
            currentPath.Add(closestToPoint.transform.position);
            currentPathIndex = -1;
            pathLooping      = false;
            finalDestination = closestToPoint.transform.position;
        }
        else
        {
            Stack <BasePathNode> path;
            float pathCost;
            if (!AStarPath.FindPath(basePathNode, closestToPoint, out path, out pathCost))
            {
                return;
            }
            currentPath.Clear();
            if (flag)
            {
                for (int i = 0; i < nodes.Count - 1; i++)
                {
                    currentPath.Add(nodes[i].transform.position);
                }
            }
            foreach (BasePathNode item in path)
            {
                currentPath.Add(item.transform.position);
            }
            currentPathIndex = -1;
            pathLooping      = false;
            finalDestination = closestToPoint.transform.position;
        }
    }