private bool AttackVisibleEntity(PathWithCost path, List <Entity> visibleEntities) { var isKilled = false; var map = GetMap(); map.TakeMove(path.Path, this); var possibleTarget = DijkstraPathFinder.PossibleDirections .Select(x => Position + x) .ToList(); var target = possibleTarget .Where(x => visibleEntities.Contains(map[x].Content.Entity)).Count() > 0 ? possibleTarget .Where(x => visibleEntities.Contains(map[x].Content.Entity)) .First() : possibleTarget .First(); if (monsterAttackZones.ContainsKey(Type)) { isKilled = Attack(null); } else { isKilled = Attack(target); } return(isKilled); }
public static IEnumerable <PathWithCost> GetPathsByDijkstra(Map map, IEnumerable <Point> targets, Point start) { Point?toOpen = start; var tracks = new Dictionary <Point, PathWithCost>(); tracks[start] = new PathWithCost(0, new Point[] { start }); var opened = new HashSet <Point>() { start }; var wantToVisit = new HashSet <Point?>(); var targetSet = new HashSet <Point>(targets); while (true) { if (toOpen == null) { break; } if (targetSet.Contains(toOpen.Value)) { yield return(tracks[toOpen.Value]); } OpenPoints(toOpen, map, opened, wantToVisit, tracks, targetSet); if (wantToVisit.Count == 0) { break; } toOpen = wantToVisit .OrderBy(x => tracks[x.Value].Cost) .First(); opened.Add(toOpen.Value); OpenPoints(toOpen, map, opened, wantToVisit, tracks, targetSet); } }