Esempio n. 1
0
        public EnsoulSharp.SDK.PredictionOutput GetPrediction(EnsoulSharp.SDK.PredictionInput input, bool ft, bool checkCollision)
        {
            var ChangeInput = new Sebby.PredictionInput()
            {
                From             = input.From,
                RangeCheckFrom   = input.RangeCheckFrom,
                Aoe              = input.Aoe,
                Collision        = input.Collision,
                CollisionObjects = input.CollisionObjects ?? new CollisionObjects[1],
                Delay            = input.Delay,
                Radius           = input.Radius,
                Range            = input.Range,
                Speed            = input.Speed,
                Type             = input.Type,
                Unit             = input.Unit,
                Source           = ObjectManager.Player,
            };

            var GetPred = Sebby.Prediction.GetPrediction(ChangeInput, ft, checkCollision);

            var OutPut = new EnsoulSharp.SDK.PredictionOutput()
            {
                AoeTargetsHitCount = GetPred.AoeTargetsHitCount,
                AoeTargetsHit      = GetPred.AoeTargetsHit,
                Hitchance          = (EnsoulSharp.SDK.HitChance)GetPred.Hitchance,
                CastPosition       = GetPred.CastPosition,
                UnitPosition       = GetPred.UnitPosition,
                CollisionObjects   = GetPred.CollisionObjects,
            };

            return(OutPut);
        }
Esempio n. 2
0
        /// <summary>
        ///     Returns Calculated Prediction based off given data values.
        /// </summary>
        /// <param name="input">
        ///     <see cref="PredictionInput" /> input
        /// </param>
        /// <param name="ft">Add Delay</param>
        /// <param name="checkCollision">Check Collision</param>
        /// <returns>
        ///     <see cref="PredictionOutput" /> output
        /// </returns>
        internal static PredictionOutput GetPrediction(PredictionInput input, bool ft, bool checkCollision)
        {
            PredictionOutput result = null;

            if (!input.Unit.IsValidTarget(float.MaxValue, false))
            {
                return(new PredictionOutput());
            }

            if (ft)
            {
                // Increase the delay due to the latency and server tick:
                input.Delay += (Game.Ping / 2000f) + 0.06f;

                if (input.AoE)
                {
                    return(Cluster.GetAoEPrediction(input));
                }
            }

            // Target too far away.
            if (Math.Abs(input.Range - float.MaxValue) > float.Epsilon &&
                input.Unit.DistanceSquared(input.RangeCheckFrom) > Math.Pow(input.Range * 1.5, 2))
            {
                return(new PredictionOutput {
                    Input = input
                });
            }

            // Unit is dashing.
            if (input.Unit.IsDashing())
            {
                result = GetDashingPrediction(input);
            }
            else
            {
                // Unit is immobile.
                var remainingImmobileT = UnitIsImmobileUntil(input.Unit);
                if (remainingImmobileT >= 0d)
                {
                    result = GetImmobilePrediction(input, remainingImmobileT);
                }
            }

            // Normal prediction
            if (result == null)
            {
                result = GetAdvancedPrediction(input);
            }

            // Check if the unit position is in range
            if (Math.Abs(input.Range - float.MaxValue) > float.Epsilon)
            {
                if (result.Hitchance >= HitChance.High &&
                    input.RangeCheckFrom.DistanceSquared(input.Unit.Position)
                    > Math.Pow(input.Range + (input.RealRadius * 3 / 4), 2))
                {
                    result.Hitchance = HitChance.Medium;
                }

                if (input.RangeCheckFrom.DistanceSquared(result.UnitPosition)
                    > Math.Pow(input.Range + (input.Type == SkillshotType.SkillshotCircle ? input.RealRadius : 0), 2))
                {
                    result.Hitchance = HitChance.OutOfRange;
                }

                if (input.RangeCheckFrom.DistanceSquared(result.CastPosition) > Math.Pow(input.Range, 2))
                {
                    if (result.Hitchance != HitChance.OutOfRange)
                    {
                        result.CastPosition = input.RangeCheckFrom
                                              + (input.Range
                                                 * (result.UnitPosition - input.RangeCheckFrom).Normalized().SetZ());
                    }
                    else
                    {
                        result.Hitchance = HitChance.OutOfRange;
                    }
                }
            }

            // Check for collision
            if (checkCollision && input.Collision)
            {
                var positions = new List <Vector3> {
                    result.UnitPosition, result.CastPosition, input.Unit.Position
                };
                var originalUnit = input.Unit;
                result.CollisionObjects = Collision.GetCollision(positions, input);
                result.CollisionObjects.RemoveAll(x => x.NetworkId == originalUnit.NetworkId);
                result.Hitchance = result.CollisionObjects.Count > 0 ? HitChance.Collision : result.Hitchance;
            }

            return(result);
        }