示例#1
0
        /// <summary>
        /// Gets Aoe Prediction result
        /// </summary>
        /// <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="from">Spell casted position</param>
        /// <param name="rangeCheckFrom"></param>
        /// <returns>Prediction result as <see cref="PredictionExtensions.AoeResult"/></returns>
        public static SpellAoeResult GetAoePrediction(float width, float delay, float missileSpeed, float range, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result  = new SpellAoeResult();
            var enemies = GameObjects.EnemyHeroes.Where(p => p.IsValidTarget() && PredictionExtensions.GetFastUnitPosition(p, delay, 0, from).Distance(rangeCheckFrom) < range);

            foreach (var enemy in enemies)
            {
                var prediction = GetPrediction(enemy, width, delay, missileSpeed, range, false, enemy.GetWaypoints(), enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), enemy.LastAngleDiff(), from, rangeCheckFrom);
                if (prediction.HitChance > HitChance.Medium)
                {
                    var multp = (result.CastPosition.Distance(from) / 875.0f);

                    var spellHitBox = new Geometry.Polygon(
                        ClipperWrapper.DefineArc(from - new Vector2(875 / 2f, 20), result.CastPosition, (float)Math.PI * multp, 410, 200 * multp),
                        ClipperWrapper.DefineArc(from - new Vector2(875 / 2f, 20), result.CastPosition, (float)Math.PI * multp, 410, 320 * multp));

                    var collidedEnemies = GameObjects.EnemyHeroes.AsParallel().Where(p => ClipperWrapper.IsIntersects(ClipperWrapper.MakePaths(ClipperWrapper.DefineCircle(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed), p.BoundingRadius)), ClipperWrapper.MakePaths(spellHitBox))).ToList();
                    var collisionCount  = collidedEnemies.Count;
                    if (collisionCount > result.HitCount)
                    {
                        var collisionResult = new CollisionResult(collidedEnemies.ToList <AIBaseClient>(), CollisionFlags.EnemyChampions);
                        return(new SpellAoeResult
                        {
                            CastPosition = prediction.CastPosition,
                            HitCount = collisionCount,
                            CollisionResult = collisionResult
                        });
                    }
                }
            }

            return(result);
        }
示例#2
0
            /// <summary>
            /// Stasis calculations
            /// </summary>
            /// <param name="spell">The spell.</param>
            internal void Process(Spell spell)
            {
                var arrivalT = PredictionExtensions.GetArrivalTime(spell.From.Distance(this.Unit.PreviousPosition), spell.Delay, spell.Speed) * 1000f;

                if (Variables.TickCount - this.StartTick >= this.Duration - arrivalT)
                {
                    var pred = new PredictionResult
                    {
                        Input        = new PredictionInput(this.Unit, spell.Delay, spell.Speed, spell.Width, spell.Range, spell.Collision, spell.Type, spell.From, spell.RangeCheckFrom),
                        Unit         = this.Unit,
                        CastPosition = this.Unit.PreviousPosition.ToVector2(),
                        UnitPosition = this.Unit.PreviousPosition.ToVector2(),
                        HitChance    = HitChance.VeryHigh
                    };
                    pred.Lock(false);

                    var result = new StasisResult {
                        Spell = spell, Prediction = pred
                    };

                    if (OnGuaranteedHit != null && pred.HitChance != HitChance.Collision &&
                        pred.HitChance != HitChance.OutOfRange)
                    {
                        OnGuaranteedHit(MethodBase.GetCurrentMethod().DeclaringType, result);
                    }

                    this.Processed = true;
                }
            }
        /// <summary>
        /// Gets Aoe Prediction result
        /// </summary>
        /// <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="from">Spell casted position</param>
        /// <param name="rangeCheckFrom"></param>
        /// <returns>Prediction result as <see cref="SpellAoeResult"/></returns>
        public static SpellAoeResult GetLineAoePrediction(float width, float delay, float missileSpeed, float range, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result  = new SpellAoeResult();
            var enemies = GameObjects.EnemyHeroes.Where(p => p.IsValidTarget() && PredictionExtensions.GetFastUnitPosition(p, delay, 0, from).Distance(rangeCheckFrom) < range);

            foreach (var enemy in enemies)
            {
                var prediction = GetLinePrediction(enemy, width, delay, missileSpeed, range, false, enemy.GetWaypoints(), enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), enemy.LastAngleDiff(), from, rangeCheckFrom);
                if (prediction.HitChance > HitChance.Medium)
                {
                    var to        = from + (prediction.CastPosition - from).Normalized() * range;
                    var colResult = Collision.GetCollisions(from, to, range, width, delay, missileSpeed);
                    if (colResult.Objects.HasFlag(CollisionFlags.EnemyChampions))
                    {
                        var collisionCount = colResult.Units.Count(p => p.IsEnemy && p.Type == GameObjectType.AIHeroClient && p.IsValid);
                        if (collisionCount > result.HitCount)
                        {
                            return(new SpellAoeResult
                            {
                                CastPosition = prediction.CastPosition,
                                HitCount = collisionCount,
                                CollisionResult = colResult
                            });
                        }
                    }
                }
            }
            return(result);
        }
示例#4
0
        /// <summary>
        /// Gets Aoe Prediction result
        /// </summary>
        /// <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="from">Spell casted position</param>
        /// <param name="rangeCheckFrom"></param>
        /// <returns>Prediction result as <see cref="SpellAoeResult"/></returns>
        public static SpellAoeResult GetAoePrediction(float width, float delay, float missileSpeed, float range, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result  = new SpellAoeResult();
            var enemies = GameObjects.EnemyHeroes.Where(p => p.IsValidTarget() && PredictionExtensions.GetFastUnitPosition(p, delay, 0, from).Distance(rangeCheckFrom) < range);

            foreach (var enemy in enemies)
            {
                var prediction = GetPrediction(enemy, width, delay, missileSpeed, range, false, enemy.GetWaypoints(), enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), enemy.LastAngleDiff(), from, rangeCheckFrom);
                if (prediction.HitChance > HitChance.Medium)
                {
                    var to              = from + (prediction.CastPosition - from).Normalized() * range;
                    var spellHitBox     = ClipperWrapper.DefineSector(from, to, width, range);
                    var collidedEnemies = GameObjects.EnemyHeroes.AsParallel().Where(p => !spellHitBox.IsOutside(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed, from))).ToList();
                    var collisionCount  = collidedEnemies.Count;
                    if (collisionCount > result.HitCount)
                    {
                        var collisionResult = new CollisionResult(collidedEnemies.ToList <AIBaseClient>(), CollisionFlags.EnemyChampions);
                        return(new SpellAoeResult
                        {
                            CastPosition = prediction.CastPosition,
                            HitCount = collisionCount,
                            CollisionResult = collisionResult
                        });
                    }
                }
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets Aoe Prediction result
        /// </summary>
        /// <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="from">Spell casted position</param>
        /// <param name="rangeCheckFrom"></param>
        /// <returns>Prediction result as <see cref="SpellAoeResult"/></returns>
        public static SpellAoeResult GetAoePrediction(float width, float delay, float missileSpeed, float range, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result  = new SpellAoeResult();
            var enemies = GameObjects.EnemyHeroes.Where(p => p.IsValidTarget() && PredictionExtensions.GetFastUnitPosition(p, delay, 0, from).Distance(rangeCheckFrom) < range).ToList();

            if (enemies.Count > 0)
            {
                var posSummary = Vector2.Zero;

                // ReSharper disable once AccessToModifiedClosure
                enemies.AsParallel().ForAll(p => posSummary += PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed, from));

                var   center  = posSummary / enemies.Count;
                float flyTime = 0;
                if (missileSpeed != 0)
                {
                    flyTime = from.Distance(center) / missileSpeed;
                }

                posSummary = Vector2.Zero;
                var predictionResults = new List <Tuple <PredictionResult, float> >();

                foreach (var enemy in enemies)
                {
                    var prediction = GetPrediction(enemy, width, delay + flyTime, 0, range, false, enemy.GetWaypoints(), enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), enemy.LastAngleDiff(), from, rangeCheckFrom);
                    if (prediction.HitChance > HitChance.Medium)
                    {
                        posSummary += prediction.UnitPosition;
                        predictionResults.Add(new Tuple <PredictionResult, float>(prediction, enemy.BoundingRadius));
                    }
                }

                if (predictionResults.Count > 0)
                {
                    center = posSummary / predictionResults.Count;
                    result.CastPosition = center;
                    foreach (var unused in predictionResults.Where(res => center.CircleCircleIntersection(res.Item1.UnitPosition, width, res.Item2).Length > 1))
                    {
                        result.HitCount++;
                    }
                }

                predictionResults.Clear();
                GC.Collect(GC.GetGeneration(predictionResults));
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Gets Prediction result while unit is immobile
        /// </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>
        /// <returns></returns>
        public static PredictionResult GetImmobilePrediction(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, SpellType type, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result = new PredictionResult
            {
                Input        = new PredictionInput(target, delay, missileSpeed, width, range, collisionable, type, from.ToVector3World(), rangeCheckFrom.ToVector3World()),
                Unit         = target,
                CastPosition = target.PreviousPosition.ToVector2()
            };

            result.UnitPosition = result.CastPosition;

            //calculate spell arrival time
            var t = delay + Game.Ping / 2000f;

            if (missileSpeed != 0)
            {
                t += from.Distance(target.PreviousPosition) / missileSpeed;
            }

            if (type == SpellType.Circle)
            {
                t += width / target.MoveSpeed / 2f;
            }

            if (t >= target.LeftImmobileTime())
            {
                result.HitChance = HitChance.Immobile;
                result.Lock();

                return(result);
            }

            if (target is AIHeroClient hero)
            {
                result.HitChance = PredictionExtensions.GetHitChance(t - hero.LeftImmobileTime(), hero.AvgMovChangeTime(), 0, 0, 0);
            }
            else
            {
                result.HitChance = HitChance.High;
            }

            result.Lock();

            return(result);
        }
示例#7
0
 /// <summary>
 /// Gets fast-predicted unit position
 /// </summary>
 /// <param name="target">Target</param>
 /// <param name="path">Path</param>
 /// <param name="delay">Spell delay</param>
 /// <param name="missileSpeed">Spell missile speed</param>
 /// <param name="from">Spell casted position</param>
 /// <param name="moveSpeed">Move speed</param>
 /// <param name="distanceSet"></param>
 /// <returns></returns>
 public Vector2 GetFastUnitPosition(AIBaseClient target, List <Vector2> path, float delay, float missileSpeed = 0, Vector2?from = null, float moveSpeed = 0, float distanceSet = 0)
 {
     return(PredictionExtensions.GetFastUnitPosition(target, path, delay, missileSpeed, from, moveSpeed, distanceSet));
 }
示例#8
0
 /// <summary>
 /// Gets Prediction result while unit is immobile
 /// </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>
 /// <returns></returns>
 public PredictionResult GetImmobilePrediction(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, SpellType type, Vector2 from, Vector2 rangeCheckFrom)
 {
     return(PredictionExtensions.GetImmobilePrediction(target, width, delay, missileSpeed, range, collisionable, type, from, rangeCheckFrom));
 }
示例#9
0
 /// <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="type">Spell skillshot type</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"></param>
 /// <returns>Prediction result as <see cref="PredictionResult"/></returns>
 public PredictionResult GetPrediction(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, SpellType type, List <Vector2> path, float avgt, float movt, float avgp, float anglediff, Vector2 from, Vector2 rangeCheckFrom)
 {
     return(PredictionExtensions.GetPrediction(target, width, delay, missileSpeed, range, collisionable, type, path, avgt, movt, avgp, anglediff, from, rangeCheckFrom));
 }
示例#10
0
        /// <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);
        }
示例#11
0
        /// <summary>
        /// Gets Aoe Prediction result
        /// </summary>
        /// <param name="width">Spell 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="rangeCheckFrom"></param>
        /// <returns>Prediction result as <see cref="SpellAoeResult"/></returns>
        public static VectorAoeResult GetAoePrediction(float width, float delay, float vectorSpeed, float range, float vectorLenght, Vector2 rangeCheckFrom)
        {
            var result  = new VectorAoeResult();
            var enemies = GameObjects.EnemyHeroes.Where(p => p.IsValidTarget() && PredictionExtensions.GetFastUnitPosition(p, delay, 0, rangeCheckFrom).Distance(rangeCheckFrom) < range);

            foreach (var enemy in enemies)
            {
                var path = enemy.GetWaypoints();
                if (path.Count <= 1)
                {
                    var from      = rangeCheckFrom + (enemy.PreviousPosition.ToVector2() - rangeCheckFrom).Normalized() * range;
                    var to        = from + (enemy.PreviousPosition.ToVector2() - from).Normalized() * vectorLenght;
                    var colResult = Collision.GetCollisions(from, to, range, width, delay, vectorSpeed);

                    if (colResult.Objects.HasFlag(CollisionFlags.EnemyChampions))
                    {
                        var collisionCount = colResult.Units.Count(p => p.IsEnemy && p.Type == GameObjectType.AIHeroClient && p.IsValid);
                        if (collisionCount > result.HitCount)
                        {
                            result = new VectorAoeResult
                            {
                                CastSourcePosition = from,
                                CastTargetPosition = enemy.PreviousPosition.ToVector2(),
                                HitCount           = collisionCount,
                                CollisionResult    = colResult
                            };
                        }
                    }
                }
                else
                {
                    if (!enemy.IsDashing())
                    {
                        for (var i = 0; i < path.Count - 1; i++)
                        {
                            var point      = Geometry.ClosestCirclePoint(rangeCheckFrom, range, path[i]);
                            var prediction = PredictionExtensions.GetPrediction(enemy, width, delay, vectorSpeed, vectorLenght, false, SpellType.Line, path, enemy.AvgMovChangeTime(), enemy.LastMovChangeTime(), enemy.AvgPathLenght(), enemy.LastAngleDiff(), point, rangeCheckFrom);
                            if (prediction.HitChance > HitChance.Medium)
                            {
                                var to        = point + (prediction.CastPosition - point).Normalized() * vectorLenght;
                                var colResult = Collision.GetCollisions(point, to, range, width, delay, vectorSpeed);
                                if (colResult.Objects.HasFlag(CollisionFlags.EnemyChampions))
                                {
                                    var collisionCount = colResult.Units.Count(p => p.IsEnemy && p.Type == GameObjectType.AIHeroClient && p.IsValid);
                                    if (collisionCount > result.HitCount)
                                    {
                                        result = new VectorAoeResult
                                        {
                                            CastSourcePosition = point,
                                            CastTargetPosition = prediction.CastPosition,
                                            HitCount           = collisionCount,
                                            CollisionResult    = colResult
                                        };
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
示例#12
0
        /// <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="type">Spell skillshot type</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"></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, SpellType type, List <Vector2> path, float avgt, float movt, float avgp, float anglediff, Vector2 from, Vector2 rangeCheckFrom)
        {
            var result = new PredictionResult();
            var input  = new PredictionInput(target, delay, missileSpeed, width, range, collisionable, type, from.ToVector3World(), rangeCheckFrom.ToVector3World());

            result.Input = input;
            result.Unit  = target;

            try
            {
                if (type == SpellType.Circle)
                {
                    range += width;
                }

                //to do: hook logic ? by storing average movement direction etc
                if (path.Count <= 1 && movt > 100 && (Environment.TickCount - PathTracker.EnemyInfo[target.NetworkId].LastAATick > 300 || !Program.CheckAAWindUp)) //if target is not moving, easy to hit (and not aaing)
                {
                    result.HitChance    = HitChance.VeryHigh;
                    result.CastPosition = target.PreviousPosition.ToVector2();
                    result.UnitPosition = result.CastPosition;
                    result.Lock();

                    return(result);
                }

                if (target is AIHeroClient hero)
                {
                    if (hero.IsCastingImporantSpell())
                    {
                        result.HitChance    = HitChance.VeryHigh;
                        result.CastPosition = hero.PreviousPosition.ToVector2();
                        result.UnitPosition = result.CastPosition;
                        result.Lock();

                        return(result);
                    }

                    if (Environment.TickCount - PathTracker.EnemyInfo[hero.NetworkId].LastAATick < 300 && Program.CheckAAWindUp)
                    {
                        if (hero.AttackCastDelay * 1000 + PathTracker.EnemyInfo[hero.NetworkId].AvgOrbwalkTime + avgt - width / 2f / hero.MoveSpeed >= PredictionExtensions.GetArrivalTime(hero.PreviousPosition.ToVector2().Distance(from), delay, missileSpeed))
                        {
                            result.HitChance    = HitChance.High;
                            result.CastPosition = hero.PreviousPosition.ToVector2();
                            result.UnitPosition = result.CastPosition;
                            result.Lock();

                            return(result);
                        }
                    }

                    //to do: find a fuking logic
                    if (avgp < 400 && movt < 100 && path.PathLength() <= avgp)
                    {
                        result.HitChance    = HitChance.High;
                        result.CastPosition = path.Last();
                        result.UnitPosition = result.CastPosition;
                        result.Lock();

                        return(result);
                    }
                }

                if (target.IsDashing()) //if unit is dashing
                {
                    return(GetDashingPrediction(target, width, delay, missileSpeed, range, collisionable, type, from, rangeCheckFrom));
                }

                if (target.IsImmobileTarget()) //if unit is immobile
                {
                    return(GetImmobilePrediction(target, width, delay, missileSpeed, range, collisionable, type, from, rangeCheckFrom));
                }

                result       = WaypointAnlysis(target, width, delay, missileSpeed, range, collisionable, type, path, avgt, movt, avgp, anglediff, from);
                result.Input = input;

                var d = result.CastPosition.Distance(target.PreviousPosition.ToVector2());
                if (d >= (avgt - movt) * target.MoveSpeed && d >= avgp)
                {
                    result.HitChance = HitChance.Medium;
                }

                result.Lock();

                return(result);
            }
            finally
            {
                //check if movement changed while prediction calculations
                if (!target.GetWaypoints().SequenceEqual(path))
                {
                    result.HitChance = HitChance.Medium;
                }
            }
        }
示例#13
0
        /// <summary>
        /// Calculates cast position with target's path
        /// </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="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>
        /// <returns></returns>
        public static PredictionResult WaypointAnlysis(AIBaseClient target, float width, float delay, float missileSpeed, float range, bool collisionable, SpellType type, List <Vector2> path, float avgt, float movt, float avgp, float anglediff, Vector2 from, float moveSpeed = 0, bool isDash = false)
        {
            if (moveSpeed == 0)
            {
                moveSpeed = target.MoveSpeed;
            }

            var result = new PredictionResult {
                Unit = target
            };

            var flyTimeMax = 0f;

            if (missileSpeed != 0) //skillshot with a missile
            {
                flyTimeMax = range / missileSpeed;
            }

            var tMin       = delay + Game.Ping / 2000f + Program.SpellDelay / 1000f;
            var tMax       = flyTimeMax + delay + Game.Ping / 1000f + Program.SpellDelay / 1000f;
            var pathTime   = 0f;
            var pathBounds = new[] { -1, -1 };

            //find bounds
            for (var i = 0; i < path.Count - 1; i++)
            {
                var t = path[i + 1].Distance(path[i]) / moveSpeed;

                if (pathTime <= tMin && pathTime + t >= tMin)
                {
                    pathBounds[0] = i;
                }

                if (pathTime <= tMax && pathTime + t >= tMax)
                {
                    pathBounds[1] = i;
                }

                if (pathBounds[0] != -1 && pathBounds[1] != -1)
                {
                    break;
                }

                pathTime += t;
            }

            //calculate cast & unit position
            if (pathBounds[0] != -1 && pathBounds[1] != -1)
            {
                for (var k = pathBounds[0]; k <= pathBounds[1]; k++)
                {
                    var direction = (path[k + 1] - path[k]).Normalized();
                    var distance  = width;
                    var extender  = target.BoundingRadius;

                    if (type == SpellType.Line)
                    {
                        extender = width;
                    }

                    var steps = (int)Math.Floor(path[k].Distance(path[k + 1]) / distance);
                    //split & anlyse current path
                    for (var i = 1; i < steps - 1; i++)
                    {
                        var pCenter = path[k] + (direction * distance * i);
                        var pA      = pCenter - (direction * extender);
                        var pB      = pCenter + (direction * extender);

                        var flytime = missileSpeed != 0 ? from.Distance(pCenter) / missileSpeed : 0f;
                        var t       = flytime + delay + Game.Ping / 2000f + Program.SpellDelay / 1000f;

                        var currentPosition = target.PreviousPosition.ToVector2();

                        var arriveTimeA = currentPosition.Distance(pA) / moveSpeed;
                        var arriveTimeB = currentPosition.Distance(pB) / moveSpeed;

                        if (Math.Min(arriveTimeA, arriveTimeB) <= t && Math.Max(arriveTimeA, arriveTimeB) >= t)
                        {
                            result.HitChance    = PredictionExtensions.GetHitChance(t, avgt, movt, avgp, anglediff);
                            result.CastPosition = pCenter;
                            result.UnitPosition = pCenter; //+ (direction * (t - Math.Min(arriveTimeA, arriveTimeB)) * moveSpeed);
                            return(result);
                        }
                    }
                }
            }

            result.HitChance    = HitChance.None;
            result.CastPosition = target.PreviousPosition.ToVector2();

            return(result);
        }
示例#14
0
        /// <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));
        }
示例#15
0
        /// <summary>
        /// Gets collided units & flags
        /// </summary>
        /// <param name="from">Start position</param>
        /// <param name="to">End position</param>
        /// <param name="range"></param>
        /// <param name="width">Rectangle scale</param>
        /// <param name="delay">Spell delay</param>
        /// <param name="missileSpeed">Spell missile speed</param>
        /// <param name="isArc"></param>
        /// <returns>Collision result as <see cref="CollisionResult"/></returns>
        public static CollisionResult GetCollisions(Vector2 from, Vector2 to, float range, float width, float delay, float missileSpeed = 0, bool isArc = false)
        {
            var collidedUnits = new List <AIBaseClient>();
            var spellHitBox   = ClipperWrapper.MakePaths(ClipperWrapper.DefineRectangle(from, to.Extend(from, -width), width));

            if (isArc)
            {
                spellHitBox = ClipperWrapper.MakePaths(new Geometry.Polygon(
                                                           ClipperWrapper.DefineArc(from - new Vector2(900 / 2f, 20), to, (float)Math.PI * (to.Distance(from) / 900), 410, 200 * (to.Distance(from) / 900)),
                                                           ClipperWrapper.DefineArc(from - new Vector2(900 / 2f, 20), to, (float)Math.PI * (to.Distance(from) / 900), 410, 320 * (to.Distance(from) / 900))));
            }
            var _colFlags       = CollisionFlags.None;
            var collidedMinions = GameObjects.GetMinions(range + 100).AsParallel().Where(p => ClipperWrapper.IsIntersects(ClipperWrapper.MakePaths(ClipperWrapper.DefineCircle(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed), p.BoundingRadius + 15)), spellHitBox)).ToList();
            var collidedJungles = GameObjects.GetJungles(range + 100).AsParallel().Where(p => ClipperWrapper.IsIntersects(ClipperWrapper.MakePaths(ClipperWrapper.DefineCircle(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed), p.BoundingRadius + 15)), spellHitBox)).ToList();
            var collidedEnemies = GameObjects.EnemyHeroes.AsParallel().Where(p => ClipperWrapper.IsIntersects(ClipperWrapper.MakePaths(ClipperWrapper.DefineCircle(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed), p.BoundingRadius)), spellHitBox)).ToList();
            var collidedAllies  = GameObjects.AllyHeroes.AsParallel().Where(p => ClipperWrapper.IsIntersects(ClipperWrapper.MakePaths(ClipperWrapper.DefineCircle(PredictionExtensions.GetFastUnitPosition(p, delay, missileSpeed), p.BoundingRadius)), spellHitBox)).ToList();

            if (collidedMinions.Count != 0)
            {
                collidedUnits.AddRange(collidedMinions);
                _colFlags |= CollisionFlags.Minions;
            }

            if (collidedJungles.Count != 0)
            {
                collidedUnits.AddRange(collidedJungles);
                _colFlags |= CollisionFlags.Minions;
            }

            if (collidedEnemies.Count != 0)
            {
                collidedUnits.AddRange(collidedEnemies);
                _colFlags |= CollisionFlags.EnemyChampions;
            }

            if (collidedAllies.Count != 0)
            {
                collidedUnits.AddRange(collidedAllies);
                _colFlags |= CollisionFlags.AllyChampions;
            }

            if (CheckWallCollision(from, to))
            {
                _colFlags |= CollisionFlags.Wall;
            }

            if (CheckYasuoWallCollision(from, to, width))
            {
                _colFlags |= CollisionFlags.YasuoWall;
            }

            return(new CollisionResult(collidedUnits, _colFlags));
        }
示例#16
0
 private void CheckOutofRange(bool checkDodge)
 {
     if (this.Input.RangeCheckFrom.ToVector2().Distance(this.CastPosition) > this.Input.SpellRange - (checkDodge ? PredictionExtensions.GetArrivalTime(this.Input.From.ToVector2().Distance(this.CastPosition), this.Input.SpellDelay, this.Input.SpellMissileSpeed) * this.Unit.MoveSpeed * (100 - Program.MaxRangeIgnore) / 100f : 0))
     {
         this.HitChance = HitChance.OutOfRange;
     }
 }