/// <summary> /// Gets a specified amount of Rotated Positions. Useful for getting safe dash positions. /// </summary> /// <param name="rotateAround">The source position</param> /// <param name="rotateTowards">The target position</param> /// <param name="degrees">It will get rotated positions from -degrees to +degrees</param> /// <param name="positionAmount">The amount of positions to get. Can be left blank</param> /// <param name="distance">Can be left blan</param> /// <returns></returns> public static List <Vector3> RotatedPositions(Vector3 rotateAround, Vector3 rotateTowards, int degrees, int positionAmount = 0, float distance = 0) { if (distance == 0) { distance = rotateAround.Distance(rotateTowards); } if (positionAmount == 0) { positionAmount = degrees / 10; } var realRotateTowards = rotateAround.Extend(rotateTowards, distance); var posList = new List <Vector3>(); var step = (degrees * 2) / positionAmount; for (var i = -degrees; i <= degrees; i += step) { var rotatedPosition = OKTRGeometry.Deviation(rotateAround.To2D(), realRotateTowards, i); posList.Add(rotatedPosition.To3D()); } return(posList); }
public static Vector3 SafeDashLogic(float range) { if (Variables.CloseEnemies().Count <= 1) { var dashPos = (Player.Instance.ServerPosition.To2D() + range * Player.Instance.Direction.To2D()).To3D(); if (!dashPos.IsUnderTurret() && (!Variables.JinxTrap(dashPos) || !Variables.CaitTrap(dashPos))) { return(dashPos); } } if (Variables.CloseAllies().Count == 0 && Variables.CloseEnemies(Player.Instance.AttackRange + range * 1.1f).Count <= 2) { if (Variables.CloseEnemies(Player.Instance.AttackRange + range * 1.1f).Any( t => t.Health + 15 < Player.Instance.GetAutoAttackDamage(t) + Player.Instance.GetSpellDamage(t, SpellSlot.Q) && t.Distance(Player.Instance) < Player.Instance.AttackRange + 80f)) { Chat.Print("1 high 1 low"); var dashPos = Player.Instance.ServerPosition.Extend( Variables.CloseEnemies() .Where(e => e.HealthPercent > 10) .OrderBy(t => t.Health) .First() .ServerPosition, range); if (!dashPos.IsUnderTurret() && (!Variables.JinxTrap(dashPos.To3D()) || !Variables.CaitTrap(dashPos.To3D()))) { return(dashPos.To3D()); } } } if (Variables.CloseAllies().Count == 0 && Variables.CloseEnemies(Player.Instance.AttackRange + range * 1.1f).Count(e => e.HealthPercent > 10) <= 2) { Chat.Print("2 high"); var dashPos = (Player.Instance.ServerPosition.To2D() + range * Player.Instance.Direction.To2D()).To3D(); if (!dashPos.IsUnderTurret() && (!Variables.JinxTrap(dashPos) || !Variables.CaitTrap(dashPos))) { return(dashPos); } } var closestEnemy = Variables.CloseEnemies() .OrderBy(e => e.Distance(Player.Instance)) .FirstOrDefault(e => e.Distance(Player.Instance) < e.AttackRange); if (closestEnemy != null && !closestEnemy.IsMelee) { if (SafeCheckTwo((Player.Instance.ServerPosition.Extend(Game.CursorPos, range).To3D()))) { return(Player.Instance.ServerPosition.Extend(Game.CursorPos, range).To3D()); } } var bestWeight = 0f; var bestPos = Player.Instance.ServerPosition.Extend(Game.CursorPos, range).To3D(); foreach ( var pos in OKTRGeometry.RotatedPositions(Player.Instance.ServerPosition, Game.CursorPos, 20, 0, range) .Where(p => !EnemyPoints().Contains(p.To2D()))) { if (pos.CountEnemiesInRange(1150) == 0 || Variables.CloseEnemies().FirstOrDefault(e => e.Distance(pos) < 1150) == null) { continue; } var enemies = EntityManager.Heroes.Enemies.Where( e => e.IsValidTarget(1200, true, pos) && e.TotalShieldHealth() > Variables.GetChampionDamage(e)).ToList(); var enemiesEx = EntityManager.Heroes.Enemies.Where(en => en.IsValidTarget(1200f, true, pos)).ToList(); var totalDistance = (enemiesEx.Count() - enemies.Count() > 1 && enemiesEx.Count() > 2) ? enemiesEx.Sum(en => en.Distance(Player.Instance.ServerPosition)) : enemies.Sum(en => en.Distance(Player.Instance.ServerPosition)); var avg = totalDistance / pos.CountEnemiesInRange(1150); var closest = Player.Instance.ServerPosition.Distance( Variables.CloseEnemies().FirstOrDefault(e => e.Distance(pos) < 1150)); var weightedAvg = closest * .4f + avg * .6f; if (!(weightedAvg > bestWeight) || !SafeCheckTwo(pos)) { continue; } bestWeight = weightedAvg; bestPos = pos; } var finalDash = (SafeCheck(bestPos) ? bestPos : Vector3.Zero); if (finalDash == Vector3.Zero) { if (Variables.CloseAllies().Any() && Variables.CloseEnemies().Any()) { var safestAlly = Variables.CloseAllies() .OrderBy(a => a.Distance(Player.Instance.ServerPosition)) .ThenByDescending(a => a.Health).FirstOrDefault(); if (safestAlly != null && safestAlly.Distance( Variables.CloseEnemies().OrderBy(e => e.Distance(Player.Instance)).FirstOrDefault()) > Player.Instance.Distance( Variables.CloseEnemies().OrderBy(e => e.Distance(Player.Instance)).FirstOrDefault())) { // ReSharper disable once PossibleNullReferenceException var dashPos = Player.Instance.ServerPosition.Extend(safestAlly.ServerPosition, range).To3D(); if (SafeCheckTwo(dashPos)) { finalDash = dashPos; } } } } if (finalDash != Vector3.Zero) { return(finalDash); } if (SafeCheck(Player.Instance.ServerPosition.Extend(Game.CursorPos, range).To3D())) { finalDash = Player.Instance.ServerPosition.Extend(Game.CursorPos, range).To3D(); } return(finalDash); }