private static Vector3 GetClosestWave(CreepWaves creepWave) { var pos = new Vector3(); try { float[] distance = { float.MaxValue }; foreach (var position in creepWave.Coords) { if (!(position.Distance2D(creepWave.Position) < distance[0])) continue; distance[0] = position.Distance2D(creepWave.Position); pos = position; } return pos; } catch (Exception) { Console.WriteLine("Error GetClosestWave"); } return pos; }
private static Vector3 GetNextWave(CreepWaves creepWave) { float[] distance = { float.MaxValue }; var p = 0; var coords = creepWave.Coords.ToArray(); for (var i = 0; i < coords.Length; i++) { if (coords[i].Distance2D(creepWave.meepo.Position) < distance[0]) { distance[0] = coords[i].Distance2D(creepWave.meepo.Position); p = i + 1 < coords.Length ? i + 1 : i; } } return coords[p]; }
private static Unit GetClosestCreep(CreepWaves creepWave) { float[] distance = { float.MaxValue }; Unit closest = null; try { var creeps = creepWave.Creeps; foreach (var creep in creeps.Where(creep => creep.IsValidTarget() && distance[0] > creepWave.meepo.Distance2D(creep.Position)) ) { distance[0] = creepWave.meepo.Distance2D(creep.Position); closest = creep; } return closest ?? ObjectManager .GetEntities<Unit>( ).Where( x => x.IsAlive && x.IsVisible && x.IsValidTarget() && x.Team != me.Team && (x.ClassID == ClassID.CDOTA_BaseNPC_Barracks || x.ClassID == ClassID.CDOTA_BaseNPC_Tower || x.ClassID == ClassID.CDOTA_BaseNPC_Building ) && x.Distance2D(creepWave.Position) < 2000) .OrderBy(x => x.Distance2D(creepWave.meepo)) .DefaultIfEmpty(null) .FirstOrDefault(); } catch (Exception) { // ignore errors } return closest; }