Exemple #1
0
        private static Vector3?GetEstimatedPath(AbstractActor actor, out List <Vector3> path)
        {
            PathNode closestNode     = null;
            var      closestNodeDist = float.MaxValue;
            var      destRadius      = GetMinWeaponRange(actor);

            path = null;

            var enemies = actor.Combat.GetAllEnemiesOf(actor);

            if (enemies.Count == 0)
            {
                Main.HBSLog?.LogWarning("FilterToAdjacentSlowestMoveNode: no enemies");
            }

            foreach (var enemy in enemies)
            {
                if (enemy.IsDead)
                {
                    continue;
                }

                var clippedEnemyPos = RegionUtil.MaybeClipMovementDestinationToStayInsideRegion(actor, enemy.CurrentPosition);

                var curPath = DynamicLongRangePathfinder.GetPathToDestination(clippedEnemyPos,
                                                                              actor.MovementCaps.MaxWalkDistance, actor, false, destRadius);
                if (curPath == null || curPath.Count == 0)
                {
                    Main.HBSLog?.LogWarning("FilterToAdjacentSlowestMoveNode: didn't get a path to unit");
                    continue;
                }

                var nodeOnCurPath = AIUtil.GetPrunedClosestValidPathNode(actor, actor.Pathing.CurrentGrid,
                                                                         actor.Combat, actor.MovementCaps.MaxWalkDistance, curPath);
                if (nodeOnCurPath == null)
                {
                    Main.HBSLog?.LogWarning("FilterToAdjacentSlowestMoveNode: didn't get a node on the current path");
                    continue;
                }

                var distanceFromEnemy = Vector3.Distance(nodeOnCurPath.Position, clippedEnemyPos);
                if (distanceFromEnemy >= closestNodeDist)
                {
                    continue;
                }

                path            = curPath;
                closestNode     = nodeOnCurPath;
                closestNodeDist = distanceFromEnemy;
            }

            return(closestNode?.Position);
        }