private Tuple <int, Vector3> BestQPosition(Obj_AI_Base target, List <Obj_AI_Base> targets, HitChance hitChance) { var castPos = Vector3.Zero; var totalHits = 0; try { var enemies = targets.Where(e => e.IsValidTarget(Q.Range * 1.5f)).ToList(); var enemyPositions = new List <Tuple <Obj_AI_Base, Vector3> >(); var circle = new Geometry.Polygon.Circle(Player.Position, Player.BoundingRadius, 30).Points; foreach (var h in enemies) { var ePred = Q.GetPrediction(h); if (ePred.Hitchance >= hitChance) { circle.Add(Player.Position.Extend(ePred.UnitPosition, Player.BoundingRadius).To2D()); enemyPositions.Add(new Tuple <Obj_AI_Base, Vector3>(h, ePred.UnitPosition)); } } var targetPos = target == null ? Vector3.Zero : target.Position; if (target == null) { var possibilities = ListExtensions.ProduceEnumeration(enemyPositions).Where(p => p.Count > 0).ToList(); var count = 0; foreach (var possibility in possibilities) { var mec = MEC.GetMec(possibility.Select(p => p.Item2.To2D()).ToList()); if (mec.Radius < Q.Width && possibility.Count > count) { count = possibility.Count; targetPos = mec.Center.To3D(); } } } if (targetPos.Equals(Vector3.Zero)) { return(new Tuple <int, Vector3>(totalHits, castPos)); } circle = circle.OrderBy(c => c.Distance(targetPos)).ToList(); if (!enemyPositions.Any()) { return(new Tuple <int, Vector3>(totalHits, castPos)); } foreach (var point in circle) { var hits = 0; var containsTarget = false; var direction = Q.Range * (point.To3D() - Player.Position).Normalized().To2D(); var rect1 = new Geometry.Polygon.Rectangle( Player.Position, Player.Position.Extend(Player.Position + direction.To3D(), Q.Range), Q.Width); var rect2 = new Geometry.Polygon.Rectangle( Player.Position, Player.Position.Extend(Player.Position + direction.Rotated(QAngle).To3D(), Q.Range), Q.Width); var rect3 = new Geometry.Polygon.Rectangle( Player.Position, Player.Position.Extend(Player.Position + direction.Rotated(-QAngle).To3D(), Q.Range), Q.Width); foreach (var enemy in enemyPositions) { var bounding = new Geometry.Polygon.Circle(enemy.Item2, enemy.Item1.BoundingRadius * 0.85f); if (bounding.Points.Any(p => rect1.IsInside(p) || rect2.IsInside(p) || rect3.IsInside(p))) { hits++; if (target != null && enemy.Item1.NetworkId.Equals(target.NetworkId)) { containsTarget = true; } } } if ((containsTarget || target == null) && hits > totalHits) { totalHits = hits; castPos = Player.Position.Extend(point.To3D(), Q.Range); if (totalHits >= enemies.Count) { break; } } } } catch (Exception ex) { Global.Logger.AddItem(new LogItem(ex)); } return(new Tuple <int, Vector3>(totalHits, castPos)); }