Esempio n. 1
0
        public static void MoveToClosestTarget(MonoBehaviour caller, Dictionary <Point, List <Point> > allPaths, Unit unit, int range, Point targetUnit)
        {
            Dictionary <Point, int> adjacentTargetPoints = AIUtils.AdjacentPointsToTarget(allPaths, unit.GetPosition(), targetUnit);

            foreach (var item in adjacentTargetPoints)
            {
                //// Logcat.I($"Moving {this.Unit.GetPosition()} to closest target by adjacent tiles {item.Key} within distance {item.Value}");
                if (item.Value <= range)
                {
                    List <Point> path = allPaths[item.Key];
                    SetPathOrder(path, unit);

                    List <Point>     pathToTarget = path.Count > range + 1 ? path.GetRange(0, range + 1) : path;
                    PlacementEffects placement    = new PlacementEffects();
                    caller.StartCoroutine(placement.LerpMovementPath(caller, unit, pathToTarget));
                    return;
                }
            }
        }
Esempio n. 2
0
        public static void MoveToTarget(MonoBehaviour caller, Dictionary <Point, List <Point> > allValidPaths, Unit unit, int range, Point targetUnit)
        {
            Dictionary <Point, int> adjacentTargetPoints = AIUtils.AdjacentPointsToTarget(allValidPaths, unit.GetPosition(), targetUnit);

            if (adjacentTargetPoints.Count == 0)
            {
                return;
            }

            Point        pointTarget = adjacentTargetPoints.First().Key;
            List <Point> path        = allValidPaths[pointTarget];

            SetPathOrder(path, unit);
            //// Logcat.I($"path.Count {path.Count()} range {this.Range} distance {adjacentTargetPoints.First().Value}");
            if (path.Count() > range)
            {
                PlacementEffects placement = new PlacementEffects();
                caller.StartCoroutine(placement.LerpMovementPath(caller, unit, path.GetRange(0, range + 1)));
                //// PlacementHelper.Move(unit, path[range], new MovementActionValidator());
            }
        }