Beispiel #1
0
        /// <summary>
        ///     Checks if the target unit is valid.
        /// </summary>
        /// <param name="unit">
        ///     The Unit
        /// </param>
        /// <param name="range">
        ///     The Range
        /// </param>
        /// <param name="checkTeam">
        ///     Checks if the target is an enemy from the Player's side
        /// </param>
        /// <param name="from">
        ///     Check From
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public static bool IsValidTarget(
            this AttackableUnit unit,
            float range    = float.MaxValue,
            bool checkTeam = true,
            Vector3 from   = default(Vector3))
        {
            if (unit == null || !unit.IsValid || unit.IsDead || !unit.IsVisible || !unit.IsTargetable ||
                unit.IsInvulnerable)
            {
                return(false);
            }

            if (!unit.IsTargetableToTeam(GameObjects.Player.Team))
            {
                return(false);
            }

            if (checkTeam && GameObjects.Player.Team == unit.Team)
            {
                return(false);
            }

            var @base = unit as AIBaseClient;

            if (@base != null && [email protected])
            {
                return(false);
            }

            var unitPosition = @base?.Position ?? unit.Position;

            return(@from.IsValid()
                       ? @from.DistanceSquared(unitPosition) < range * range
                       : GameObjects.Player.DistanceSquared(unitPosition) < range * range);
        }