/// <summary> /// Gets prediction result /// </summary> /// <param name="target">Target</param> /// <param name="width">Vector width</param> /// <param name="delay">Spell delay</param> /// <param name="vectorSpeed">Vector speed</param> /// <param name="range">Spell range</param> /// <param name="vectorLenght">Vector lenght</param> /// <param name="path">Waypoints of target</param> /// <param name="avgt">Average reaction time (in ms)</param> /// <param name="movt">Passed time from last movement change (in ms)</param> /// <param name="avgp">Average Path Lenght</param> /// <param name="rangeCheckFrom"></param> /// <returns>Prediction result as <see cref="VectorResult"/></returns> public static VectorResult GetPrediction(AIBaseClient target, float width, float delay, float vectorSpeed, float range, float vectorLenght, List <Vector2> path, float avgt, float movt, float avgp, Vector2 rangeCheckFrom) { var result = new VectorResult(); //auto aoe hit (2 hits with using one target as from position) if (target.Type == GameObjectType.AIHeroClient && target.IsValid) //do these calcs if champion kappa { if (ObjectManager.Player.CountEnemyHeroesInRange(range) > 0 && ObjectManager.Player.CountEnemyHeroesInRange(range + vectorLenght) > 1) //if there is at least 1 enemy in range && at least 2 enemy which laser can hit { var predPos1 = PredictionExtensions.GetFastUnitPosition(target, delay); //get target unit position after delay foreach (var enemy in GameObjects.EnemyHeroes) //loop all enemies { if (enemy.NetworkId != target.NetworkId && enemy.Distance(rangeCheckFrom) < range + vectorLenght) //if enemy is not given target and enemy is hitable by laser { var predPos2 = PredictionExtensions.GetFastUnitPosition(enemy, delay); //get enemy unit position after delay if (predPos1.Distance(rangeCheckFrom) < range) //if target is in range { var predRes = LinePrediction.GetLinePrediction(enemy, width, delay, vectorSpeed, vectorLenght, false, enemy.GetWaypoints(), enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), 360, predPos1 - (predPos1 - rangeCheckFrom).Normalized().Perpendicular() * 30, predPos1 - (predPos1 - rangeCheckFrom).Normalized().Perpendicular() * 30); //get enemy prediciton with from = target's position (a bit backward) if (predRes.HitChance >= HitChance.Low) { var f = predPos1 - (predPos1 - rangeCheckFrom).Normalized().Perpendicular() * 30; return(new VectorResult { CastSourcePosition = f, CastTargetPosition = predRes.CastPosition, UnitPosition = predRes.UnitPosition, HitChance = predRes.HitChance, CollisionResult = predRes.CollisionResult, }); } } else if (predPos2.Distance(rangeCheckFrom) < range) //if enemy is in range { var predRes = LinePrediction.GetLinePrediction(target, width, delay, vectorSpeed, vectorLenght, false, path, avgt, movt, avgp, 360, predPos2 - (predPos2 - rangeCheckFrom).Normalized().Perpendicular() * 30, predPos2 - (predPos2 - rangeCheckFrom).Normalized().Perpendicular() * 30); //get target prediction with from = enemy's position (a bit backward) if (predRes.HitChance >= HitChance.Low) { var f = predPos2 - (predPos2 - rangeCheckFrom).Normalized().Perpendicular() * 30; return(new VectorResult { CastSourcePosition = f, CastTargetPosition = predRes.CastPosition, UnitPosition = predRes.UnitPosition, HitChance = predRes.HitChance, CollisionResult = predRes.CollisionResult, }); } } } } } } var immobileFrom = rangeCheckFrom + (target.PreviousPosition.ToVector2() - rangeCheckFrom).Normalized() * range; if (path.Count <= 1) //if target is not moving, easy to hit { result.HitChance = HitChance.VeryHigh; result.CastSourcePosition = immobileFrom; result.CastTargetPosition = target.PreviousPosition.ToVector2(); result.UnitPosition = result.CastTargetPosition; result.CollisionResult = Collision.GetCollisions(immobileFrom, result.CastTargetPosition, range, width, delay, vectorSpeed); if (immobileFrom.Distance(result.CastTargetPosition) > vectorLenght - PredictionExtensions.GetArrivalTime(immobileFrom.Distance(result.CastTargetPosition), delay, vectorSpeed) * target.MoveSpeed) { result.HitChance = HitChance.OutOfRange; } return(result); } if (target is AIHeroClient hero) { if (hero.IsCastingImporantSpell()) { result.HitChance = HitChance.VeryHigh; result.CastSourcePosition = immobileFrom; result.CastTargetPosition = hero.PreviousPosition.ToVector2(); result.UnitPosition = result.CastTargetPosition; result.CollisionResult = Collision.GetCollisions(immobileFrom, result.CastTargetPosition, range, width, delay, vectorSpeed); //check if target can dodge with moving backward if (immobileFrom.Distance(result.CastTargetPosition) > range - PredictionExtensions.GetArrivalTime(immobileFrom.Distance(result.CastTargetPosition), delay, vectorSpeed) * hero.MoveSpeed) { result.HitChance = HitChance.OutOfRange; } return(result); } //to do: find a fuking logic if (avgp < 400 && movt < 100) { result.HitChance = HitChance.High; result.CastTargetPosition = hero.PreviousPosition.ToVector2(); result.CastSourcePosition = immobileFrom; result.UnitPosition = result.CastTargetPosition; result.CollisionResult = Collision.GetCollisions(immobileFrom, result.CastTargetPosition, range, width, delay, vectorSpeed); //check if target can dodge with moving backward if (immobileFrom.Distance(result.CastTargetPosition) > range - PredictionExtensions.GetArrivalTime(immobileFrom.Distance(result.CastTargetPosition), delay, vectorSpeed) * hero.MoveSpeed) { result.HitChance = HitChance.OutOfRange; } return(result); } } if (target.IsDashing()) { var dashPred = PredictionExtensions.GetDashingPrediction(target, width, delay, vectorSpeed, range, false, SpellType.Line, immobileFrom, rangeCheckFrom); return(new VectorResult { CastSourcePosition = immobileFrom, CastTargetPosition = dashPred.CastPosition, UnitPosition = dashPred.UnitPosition, HitChance = dashPred.HitChance, CollisionResult = dashPred.CollisionResult, }); } if (target.IsImmobileTarget()) { var immoPred = PredictionExtensions.GetImmobilePrediction(target, width, delay, vectorSpeed, range, false, SpellType.Line, immobileFrom, rangeCheckFrom); return(new VectorResult { CastSourcePosition = immobileFrom, CastTargetPosition = immoPred.CastPosition, UnitPosition = immoPred.UnitPosition, HitChance = immoPred.HitChance, CollisionResult = immoPred.CollisionResult, }); } for (var i = 0; i < path.Count - 1; i++) { var point = Geometry.ClosestCirclePoint(rangeCheckFrom, range, path[i]); if (path[i].Distance(ObjectManager.Player.PreviousPosition) < range) { point = path[i]; } var res = PredictionExtensions.WaypointAnlysis(target, width, delay, vectorSpeed, vectorLenght, false, SpellType.Line, path, avgt, movt, avgp, 360, point); res.Input = new PredictionInput(target, delay, vectorSpeed, width, range, false, SpellType.Line, rangeCheckFrom.ToVector3World(), rangeCheckFrom.ToVector3World()); res.Lock(); if (res.HitChance >= HitChance.Low) { return(new VectorResult { CastSourcePosition = point, CastTargetPosition = res.CastPosition, UnitPosition = res.UnitPosition, HitChance = res.HitChance, CollisionResult = res.CollisionResult, }); } } result.CastSourcePosition = immobileFrom; result.CastTargetPosition = target.PreviousPosition.ToVector2(); result.HitChance = HitChance.None; return(result); }
/// <summary> /// Gets Prediction result while unit is dashing /// </summary> /// <param name="target">Target for spell</param> /// <param name="width">Spell width</param> /// <param name="delay">Spell delay</param> /// <param name="missileSpeed">Spell missile speed</param> /// <param name="range">Spell range</param> /// <param name="collisionable">Spell collisionable</param> /// <param name="type">Spell skillshot type</param> /// <param name="from">Spell casted position</param> /// <param name="rangeCheckFrom">Spell range check from position</param> /// <returns></returns> public PredictionResult GetDashingPrediction(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, SpellType type, Vector2 from, Vector2 rangeCheckFrom) { return(PredictionExtensions.GetDashingPrediction(target, width, delay, missileSpeed, range, collisionable, type, from, rangeCheckFrom)); }
/// <summary> /// Gets Prediction result /// </summary> /// <param name="target">Target for spell</param> /// <param name="width">Spell width</param> /// <param name="delay">Spell delay</param> /// <param name="missileSpeed">Spell missile speed</param> /// <param name="range">Spell range</param> /// <param name="collisionable">Spell collisionable</param> /// <param name="path">Waypoints of target</param> /// <param name="avgt">Average reaction time (in ms)</param> /// <param name="movt">Passed time from last movement change (in ms)</param> /// <param name="avgp">Average Path Lenght</param> /// <param name="from">Spell casted position</param> /// <param name="rangeCheckFrom">Spell range check fropm</param> /// <param name="arconly">Is Arc</param> /// <returns>Prediction result as <see cref="PredictionResult"/></returns> public static PredictionResult GetPrediction(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, List <Vector2> path, float avgt, float movt, float avgp, float anglediff, Vector2 from, Vector2 rangeCheckFrom, bool arconly = true) { if (arconly) { if (target.Distance(from) < width || target.Distance(from) > range * 0.75f) { return(CirclePrediction.GetPrediction(target, width, delay, missileSpeed, range, collisionable, path, avgt, movt, avgp, anglediff, from, rangeCheckFrom)); } var pred = LinePrediction.GetLinePrediction(target, 80f, delay, missileSpeed, range, collisionable, path, avgt, movt, avgp, anglediff, from, rangeCheckFrom); if (pred.HitChance >= HitChance.Low) { pred.CastPosition = (from + (pred.CastPosition - from).Normalized() * range); var cos = (float)Math.Cos((1 - pred.UnitPosition.Distance(from) / 820f) * Math.PI / 2); var sin = (float)Math.Sin((1 - pred.UnitPosition.Distance(from) / 820f) * Math.PI / 2); var x = cos * (pred.CastPosition.X - from.X) - sin * (pred.CastPosition.Y - from.Y) + from.X; var y = sin * (pred.CastPosition.X - from.X) + cos * (pred.CastPosition.Y - from.Y) + from.Y; pred.CastPosition = new Vector2(x, y); } return(pred); } var result = new PredictionResult(); if (path.Count <= 1) //if target is not moving, easy to hit { result.HitChance = HitChance.Immobile; result.CastPosition = target.PreviousPosition.ToVector2(); result.UnitPosition = result.CastPosition; return(result); } if (target is AIHeroClient aiHero && aiHero.IsCastingImporantSpell()) { result.HitChance = HitChance.Immobile; result.CastPosition = aiHero.PreviousPosition.ToVector2(); result.UnitPosition = result.CastPosition; return(result); } if (target.IsImmobileTarget()) { return(PredictionExtensions.GetImmobilePrediction(target, width, delay, missileSpeed, range, collisionable, SpellType.Circle, from, rangeCheckFrom)); } if (target.IsDashing()) { return(PredictionExtensions.GetDashingPrediction(target, width, delay, missileSpeed, range, collisionable, SpellType.Circle, from, rangeCheckFrom)); } var targetDistance = rangeCheckFrom.Distance(target.PreviousPosition); var flyTime = 0f; if (missileSpeed != 0) { var Vt = (path[path.Count - 1] - path[0]).Normalized() * target.MoveSpeed; var Vs = (target.PreviousPosition.ToVector2() - rangeCheckFrom).Normalized() * missileSpeed; var Vr = Vs - Vt; flyTime = targetDistance / Vr.Length(); if (path.Count > 5) { flyTime = targetDistance / missileSpeed; } } var t = flyTime + delay + Game.Ping / 2000f + Program.SpellDelay / 1000f; result.HitChance = PredictionExtensions.GetHitChance(t * 1000f, avgt, movt, avgp, anglediff); //arc collision test if (result.HitChance > HitChance.Low) { for (var i = 1; i < path.Count; i++) { var senderPos = rangeCheckFrom; var testPos = path[i]; var multp = (testPos.Distance(senderPos) / 875.0f); var dianaArc = new Geometry.Polygon( ClipperWrapper.DefineArc(senderPos - new Vector2(875 / 2f, 20), testPos, (float)Math.PI * multp, 410, 200 * multp), ClipperWrapper.DefineArc(senderPos - new Vector2(875 / 2f, 20), testPos, (float)Math.PI * multp, 410, 320 * multp)); if (!dianaArc.IsOutside(target.PreviousPosition.ToVector2())) { result.HitChance = HitChance.VeryHigh; result.CastPosition = testPos; result.UnitPosition = testPos; return(result); } } } return(CirclePrediction.GetPrediction(target, width, delay, missileSpeed, range, collisionable, path, avgt, movt, avgp, anglediff, @from, rangeCheckFrom)); }