Exemplo n.º 1
0
    public void UpdateMovement_Hunt()
    {
        if (Interface.CallHook("OnBradleyApcHunt", this) != null || patrolPath == null)
        {
            return;
        }
        TargetInfo targetInfo = targetList[0];

        if (!targetInfo.IsValid())
        {
            return;
        }
        if (HasPath() && targetInfo.IsVisible())
        {
            if (currentPath.Count > 1)
            {
                Vector3 item = currentPath[currentPathIndex];
                ClearPath();
                currentPath.Add(item);
                finalDestination = item;
                currentPathIndex = 0;
            }
        }
        else
        {
            if (!(UnityEngine.Time.time > nextEngagementPathTime) || HasPath() || targetInfo.IsVisible())
            {
                return;
            }
            bool                flag  = false;
            BasePathNode        start = patrolPath.GetClosestToPoint(base.transform.position);
            List <BasePathNode> nodes = Facepunch.Pool.GetList <BasePathNode>();
            if (GetEngagementPath(ref nodes))
            {
                flag  = true;
                start = nodes[nodes.Count - 1];
            }
            BasePathNode        basePathNode = null;
            List <BasePathNode> nearNodes    = Facepunch.Pool.GetList <BasePathNode>();
            patrolPath.GetNodesNear(targetInfo.lastSeenPosition, ref nearNodes, 30f);
            Stack <BasePathNode> stack = null;
            float num = float.PositiveInfinity;
            float y   = mainTurretEyePos.localPosition.y;
            foreach (BasePathNode item2 in nearNodes)
            {
                Stack <BasePathNode> path = new Stack <BasePathNode>();
                float pathCost;
                if (targetInfo.entity.IsVisible(item2.transform.position + new Vector3(0f, y, 0f)) && AStarPath.FindPath(start, item2, out path, out pathCost) && pathCost < num)
                {
                    stack        = path;
                    num          = pathCost;
                    basePathNode = item2;
                }
            }
            if (stack == null && nearNodes.Count > 0)
            {
                Stack <BasePathNode> path2         = new Stack <BasePathNode>();
                BasePathNode         basePathNode2 = nearNodes[UnityEngine.Random.Range(0, nearNodes.Count)];
                float pathCost2;
                if (AStarPath.FindPath(start, basePathNode2, out path2, out pathCost2) && pathCost2 < num)
                {
                    stack        = path2;
                    basePathNode = basePathNode2;
                }
            }
            if (stack != null)
            {
                currentPath.Clear();
                if (flag)
                {
                    for (int i = 0; i < nodes.Count - 1; i++)
                    {
                        currentPath.Add(nodes[i].transform.position);
                    }
                }
                foreach (BasePathNode item3 in stack)
                {
                    currentPath.Add(item3.transform.position);
                }
                currentPathIndex = -1;
                pathLooping      = false;
                finalDestination = basePathNode.transform.position;
            }
            Facepunch.Pool.FreeList(ref nearNodes);
            Facepunch.Pool.FreeList(ref nodes);
            nextEngagementPathTime = UnityEngine.Time.time + 5f;
        }
    }