private bool CheckForCollision(Vector2 pos)
        {
            var targetCollision = CollisionSolver.CheckThickLineCollision(ClosestPoint, DashObject.StartPosition,
                                                                          LocalPlayer.Instance.MapCollision.MapCollisionRadius);

            return(targetCollision != null && targetCollision.IsColliding &&
                   targetCollision.CollisionFlags.HasFlag(CollisionFlags.LowBlock | CollisionFlags.HighBlock));
        }
        public static bool CheckCollisionToTarget(this Character localPlayer, Character target, float radius)
        {
            if (localPlayer != null && target != null)
            {
                var heading   = target.Pos() - localPlayer.Pos();
                var direction = heading.Normalized;

                var colsolver = CollisionSolver.CheckThickLineCollision(localPlayer.Pos(),
                                                                        target.Pos() + direction, radius);

                return(colsolver.IsColliding || ObjectTracker.Enemy.Obstacles.TrackedObjects.Any(o => o.BlocksProjectileTo(target, radius)));
            }
            return(false);
        }
Exemple #3
0
        public static bool IsColliding(Player localPlayer, Player target)
        {
            if (target != null && target.IsLocalPlayer)
            {
                return(false);
            }

            if (localPlayer != null && target != null) // && !target.IsLocalPlayer)
            {
                var heading   = target.WorldPosition - localPlayer.WorldPosition;
                var distance  = heading.Length();
                var direction = heading / distance;

                return(CollisionSolver.CheckThickLineCollision(localPlayer.WorldPosition,
                                                               target.WorldPosition + direction, target.MapCollisionRadius - 0.3f).IsColliding);
            }
            return(false);
        }
        /// <summary>
        /// Gets the prediction.
        /// </summary>
        /// <param name="fromPos">Position where projectile gets fired from.</param>
        /// <param name="targetUnit">The target unit.</param>
        /// <param name="range">The ability range.</param>
        /// <param name="speed">The ability speed.</param>
        /// <param name="radius">The ability radius (for collision).</param>
        /// <param name="fixedDelay">The fixed delay. If greater than 0, will use this fixed delay for calculations instead of getting normal best position prediction</param>
        /// <param name="maxEnemyReactionTime">The maximum enemy reaction time in seconds to calculate HitChance.</param>
        /// <param name="checkCollision">If set to <c>true</c> [check collision].</param>
        /// <param name="ignoreFlags">The ignore flags for collision calculations.</param>
        /// <returns>TestOutput</returns>
        public static TestOutput GetPrediction(Vector2 fromPos, InGameObject targetUnit, float range, float speed,
                                               float radius               = 0f,
                                               float fixedDelay           = 0f,
                                               float maxEnemyReactionTime = 1.75f,
                                               bool checkCollision        = false,
                                               CollisionFlags ignoreFlags = CollisionFlags.Bush | CollisionFlags.NPCBlocker)
        {
            MapGameObject         mapGameObject         = targetUnit.Get <MapGameObject>();
            NetworkMovementObject networkMovementObject = targetUnit.Get <NetworkMovementObject>();

            if (mapGameObject == null)
            {
                Logs.Error("TestPrediction: Object of name " + targetUnit.ObjectName + " has no MapGameObject model");
                return(new TestOutput()
                {
                    CanHit = false,
                    Hitchance = TestHitchance.Impossible,
                    CastPosition = Vector2.Zero,
                });
            }

            var targetPos = mapGameObject.Position;

            if (networkMovementObject == null)
            {
                Logs.Error("TestPrediction: Object of name " + targetUnit.ObjectName + " has no NetworkMovementObject model");
                return(new TestOutput()
                {
                    CanHit = targetPos.Distance(fromPos) <= range ? true : false,
                    Hitchance = targetPos.Distance(fromPos) <= range ? TestHitchance.VeryHigh : TestHitchance.OutOfRange,
                    HitchancePercentage = targetPos.Distance(fromPos) <= range ? 100f : 0f,
                    CastPosition = targetPos,
                });
            }

            var targetVelocity = networkMovementObject.Velocity;
            var targetRadius   = targetUnit.Get <SpellCollisionObject>().SpellCollisionRadius; //TODO: Check if MapCollisionRadius is better

            if (fixedDelay < float.Epsilon)                                                    //No fixed delay
            {
                var predPos = GetStandardPrediction(fromPos, targetPos, speed, targetVelocity);
                if (predPos == Vector2.Zero)
                {
                    return(new TestOutput()
                    {
                        CanHit = false,
                        Hitchance = TestHitchance.Impossible,
                        CastPosition = Vector2.Zero,
                    });
                }


                TestOutput solution = new TestOutput()
                {
                    CanHit       = true,
                    CastPosition = predPos,
                };

                var targetCollision = CollisionSolver.CheckThickLineCollision(targetPos, solution.CastPosition, targetRadius);
                if (targetCollision != null && targetCollision.IsColliding)
                {
                    solution.CastPosition = targetCollision.CollisionPoint;
                }

                if (solution.CastPosition.Distance(fromPos) > range)
                {
                    solution.CanHit    = false;
                    solution.Hitchance = TestHitchance.OutOfRange;
                }

                if (checkCollision)
                {
                    solution.CollisionResult = CollisionSolver.CheckThickLineCollision(fromPos, solution.CastPosition, radius < float.Epsilon ? 0.01f : radius, ignoreFlags);

                    if (solution.CollisionResult.IsColliding)
                    {
                        solution.CanHit    = false;
                        solution.Hitchance = TestHitchance.Collision;
                    }
                }

                solution.HitchancePercentage = GetHitchance(fromPos, solution.CastPosition, speed, maxEnemyReactionTime, false);
                solution.Hitchance           = GetHitchanceEnum(solution.HitchancePercentage);
                return(solution);
            }
            else //WITH fixed delay
            {
                var predPos = GetFixedDelayPrediction(targetPos, fixedDelay, targetVelocity);

                TestOutput solution = new TestOutput()
                {
                    CanHit       = true,
                    CastPosition = predPos,
                };

                var targetCollision = CollisionSolver.CheckThickLineCollision(targetPos, solution.CastPosition, targetRadius);
                if (targetCollision != null && targetCollision.IsColliding)
                {
                    solution.CastPosition = targetCollision.CollisionPoint;
                }

                if (solution.CastPosition.Distance(fromPos) > range)
                {
                    solution.CanHit    = false;
                    solution.Hitchance = TestHitchance.OutOfRange;
                }

                solution.HitchancePercentage = GetHitchance(fromPos, solution.CastPosition, fixedDelay, maxEnemyReactionTime, true);
                solution.Hitchance           = GetHitchanceEnum(solution.HitchancePercentage);
                return(solution);
            }
        }