Beispiel #1
0
        /// <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>
        /// <returns></returns>
        public static PredictionResult GetDashingPrediction(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
            };

            if (target.IsDashing())
            {
                var dashInfo = target.GetDashInfo();
                result.CastPosition = GetFastUnitPosition(target, dashInfo.Path, delay, missileSpeed, from, dashInfo.Speed);
                result.HitChance    = HitChance.Dash;

                result.Lock(false);
            }
            else
            {
                result = GetPrediction(target, width, delay, missileSpeed, range, collisionable, type, target.GetWaypoints(), 0, 0, 0, 0, from, rangeCheckFrom);
                result.Lock(false);
            }
            return(result);
        }
Beispiel #2
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;
                }
            }
        }
Beispiel #3
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);
        }
Beispiel #4
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));
        }