예제 #1
0
파일: Player.cs 프로젝트: EasyFarm/EasyFarm
 public static void SetTarget(IMemoryAPI fface, Unit target)
 {
     if (!Config.Instance.EnableTabTargeting)
     {
         SetTargetUsingMemory(fface, target);
     }
     else
     {
         SetTargetByTabbing(fface, target);
     }
 }
예제 #2
0
        /// <summary>
        ///     Attempts to target by tabbing and on failure will target by memory.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="unit"></param>
        /// <param name="attemptCount"></param>
        /// <returns></returns>
        public static bool TargetByTabAndMemory(FFACE fface, Unit unit, int attemptCount)
        {
            if (fface == null) throw new ArgumentNullException("fface");
            if (unit == null) throw new ArgumentNullException("unit");

            // Attempt to target by tabbing first.
            if (TargetByTab(fface, unit, attemptCount)) return true;

            // Attempt to target by setting target in memory.
            // Note: always succeeds since target.ID will be overriden.
            if (TargetByMemory(fface, unit)) return true;

            return fface.Target.ID == unit.Id;
        }
예제 #3
0
        /// <summary>
        ///     Targets unit by our target in memory.
        ///     !!! Note !!!
        ///     once you override your target in memory it will be almost impossible
        ///     to determine if you are targeting the wrong target.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public static bool TargetByMemory(FFACE fface, Unit unit)
        {
            if (fface == null) throw new ArgumentNullException("fface");
            if (unit == null) throw new ArgumentNullException("unit");

            // Set target in memory.
            fface.Target.SetNPCTarget(unit.Id);

            // Face the target.
            fface.Navigator.FaceHeading(unit.Id);

            // Place cursor upon target.
            fface.Windower.SendString("/ta <t>");

            return fface.Target.ID == unit.Id;
        }
예제 #4
0
        /// <summary>
        ///     Moves to the unit without altering the current
        ///     distance tolerance.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="unit"></param>
        /// <param name="distance"></param>
        public static void MoveToUnit(FFACE fface, Unit unit, double distance)
        {
            // If the target is out of range move into range.
            if (fface.Navigator.DistanceTo(unit.Position) > distance)
            {
                // Save old tolerance
                var old = fface.Navigator.DistanceTolerance;

                // Set to max engagement distance.
                fface.Navigator.DistanceTolerance = distance;

                // Goto target at max engagement distance.
                fface.Navigator.GotoNPC(unit.Id);

                // Restore old tolerance.
                fface.Navigator.DistanceTolerance = old;
            }
        }
예제 #5
0
        /// <summary>
        ///     Targets unit by tabbing and attempts to target until the
        ///     attempt count is reached.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="unit"></param>
        /// <param name="attemptCount"></param>
        /// <returns></returns>
        public static bool TargetByTab(FFACE fface, Unit unit, int attemptCount)
        {
            if (fface == null) throw new ArgumentNullException("fface");
            if (unit == null) throw new ArgumentNullException("unit");
            if (attemptCount <= 0)
                throw new ArgumentException("attemptCount does not allow tabbing; possible logic error?");

            // Set view to first person.
            fface.Navigator.SetViewMode(ViewMode.FirstPerson);

            // Bring up cursor upon player.
            fface.Windower.SendString("/ta <t>");

            // Attempt to tab to target allowing max ten attempts.
            var count = 0;
            while (fface.Target.ID != unit.Id && count++ < attemptCount)
            {
                fface.Windower.SendKeyPress(KeyCode.TabKey);
                Thread.Sleep(30);
            }

            return fface.Target.ID == unit.Id;
        }
예제 #6
0
        /// <summary>
        ///     Filters out unusable targeted abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public static bool TargetedFilter(IMemoryAPI fface, BattleAbility action, Unit unit)
        {
            // Does not pass the base criteria for casting.
            if (!BuffingFilter(fface, action)) return false;

            // Target HP Checks Enabled.
            if (action.TargetLowerHealth != 0 || action.TargetUpperHealth != 0)
            {
                // Target Upper Health Check
                if (unit.HppCurrent > action.TargetUpperHealth) return false;

                // Target Lower Health Check
                if (unit.HppCurrent < action.TargetLowerHealth) return false;
            }

            // Target Name Checks Enabled.
            if (!string.IsNullOrWhiteSpace(action.TargetName))
            {
                // Target Name Check.
                if (!Regex.IsMatch(unit.Name, action.TargetName, RegexOptions.IgnoreCase)) return false;
            }

            return true;
        }
예제 #7
0
 /// <summary>
 /// Return the 2-D distance between the unit and a position. 
 /// </summary>
 /// <param name="mob"></param>
 /// <param name="waypoint"></param>
 /// <returns></returns>
 private static double Distance(Unit mob, Position waypoint)
 {
     return Math.Sqrt(Math.Pow(waypoint.X - mob.PosX, 2) + Math.Pow(waypoint.Z - mob.PosZ, 2));
 }
예제 #8
0
        /// <summary>
        /// Returns true if a mob is attackable by the player based on the various settings in the
        /// Config class.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="mob"></param>
        /// <returns></returns>
        public static bool MobFilter(IMemoryAPI fface, Unit mob)
        {
            // Function to use to filter surrounding mobs by. General Mob Filtering Criteria
            if (fface == null) return false;
            if (mob == null) return false;

            // Mob not active
            if (!mob.IsActive) return false;

            // INFO: fixes trying to attack dead mob problem. Mob is dead
            if (mob.IsDead) return false;

            // Mob not rendered on screen.
            if (!mob.IsRendered) return false;

            // Type is not mob
            if (!mob.NpcType.Equals(NpcType.Mob)) return false;

            // Mob is out of range
            if (!(mob.Distance < Config.Instance.DetectionDistance)) return false;

            if (mob.IsPet) return false;

            // If any unit is within the wander distance then the
            if (Config.Instance.Route.Waypoints.Any())
            {
                if (!(Config.Instance.Route.Waypoints.Any(waypoint => Distance(mob, waypoint) <= Config.Instance.WanderDistance))) return false;
            }

            // Mob too high out of reach.
            if (mob.YDifference > Config.Instance.HeightThreshold) return false;

            // User Specific Filtering

            // Performs a case insensitve match on the mob's name. If any part of the mob's name is
            // in the ignored list, we will not attack it.
            if (MatchAny(mob.Name, Config.Instance.IgnoredMobs,
                RegexOptions.IgnoreCase)) return false;

            // Kill aggro if aggro's checked regardless of target's list but follows the ignored list.
            if (mob.HasAggroed && Config.Instance.AggroFilter) return true;

            // There is a target's list but the mob is not on it.
            if (!MatchAny(mob.Name, Config.Instance.TargetedMobs, RegexOptions.IgnoreCase) &&
                Config.Instance.TargetedMobs.Any())
                return false;

            // Mob on our targets list or not on our ignore list.

            // Kill the creature if it has aggroed and aggro is checked.
            if (mob.HasAggroed && Config.Instance.AggroFilter) return true;

            // Kill the creature if it is claimed by party and party is checked.
            if (mob.PartyClaim && Config.Instance.PartyFilter) return true;

            // Kill the creature if it's not claimed and unclaimed is checked.
            if (!mob.IsClaimed && Config.Instance.UnclaimedFilter) return true;

            // Kill the creature if it's claimed and we we don't have claim but
            // claim is checked.
            //FIX: Temporary fix until player.serverid is fixed.
            if (mob.IsClaimed && Config.Instance.ClaimedFilter) return true;

            // Kill only mobs that we have claim on.
            return mob.ClaimedId == fface.PartyMember[0].ServerID;
        }
예제 #9
0
 /// <summary>
 /// Move close enough to mob to use an ability.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="action"></param>
 private void MoveIntoActionRange(Unit target, BattleAbility action)
 {
     // Move to target if out of distance.
     if (target.Distance > action.Distance)
     {
         // Move to unit at max buff distance.
         _fface.Navigator.DistanceTolerance = action.Distance;
         _fface.Navigator.GotoNPC(target.Id);
     }
 }
예제 #10
0
 /// <summary>
 /// Place cursor on unit
 /// </summary>
 /// <param name="target"></param>
 private void SetTarget(Unit target)
 {
     if (target.Id != _fface.Target.ID)
     {
         _fface.Target.SetNPCTarget(target.Id);
         _fface.Windower.SendString("/ta <t>");
     }
 }
예제 #11
0
 /// <summary>
 /// Execute a single action targeted type action.
 /// </summary>
 /// <param name="action"></param>
 /// <param name="target"></param>
 public void UseTargetedAction(BattleAbility action, Unit target)
 {
     if (target == null) throw new ArgumentNullException(nameof(target));
     if (action == null) throw new ArgumentNullException(nameof(action));
     UseTargetedActions(new List<BattleAbility> { action }, target);
 }
예제 #12
0
        /// <summary>
        /// Execute targeted actions.
        /// </summary>
        /// <param name="actions"></param>
        /// <param name="target"></param>
        public void UseTargetedActions(IEnumerable<BattleAbility> actions, Unit target)
        {
            // Logic error to call this without setting a target first.
            if (actions == null) throw new ArgumentNullException(nameof(actions));
            if (target == null) throw new ArgumentNullException(nameof(target));

            foreach (var action in actions)
            {
                MoveIntoActionRange(target, action);

                // Face unit
                _fface.Navigator.FaceHeading(target.Position);

                // Target mob if not currently targeted.
                SetTarget(target);

                if (ResourceHelper.IsSpell(action.Ability.AbilityType))
                {
                    _fface.Navigator.Reset();
                    Thread.Sleep(100);
                    _caster.CastSpell(action);
                }
                else
                {
                    _caster.CastAbility(action);
                }                

                // Increase usage count to limit number of usages.
                action.Usages++;

                // Set the recast to prevent casting before the recast period. 
                action.LastCast = DateTime.Now.AddSeconds(action.Recast);

                Thread.Sleep(Config.Instance.GlobalCooldown);
            }
        }
예제 #13
0
파일: Player.cs 프로젝트: EasyFarm/EasyFarm
 private static void SetTargetUsingMemory(IMemoryAPI fface, Unit target)
 {
     if (target.Id != fface.Target.ID)
     {
         fface.Target.SetNPCTarget(target.Id);
         fface.Windower.SendString("/ta <t>");
     }
 }
예제 #14
0
파일: Player.cs 프로젝트: EasyFarm/EasyFarm
        private static void SetTargetByTabbing(IMemoryAPI fface, Unit target)
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            while (target.Id != fface.Target.ID)
            {
                if (stopwatch.Elapsed == TimeSpan.FromSeconds(1))
                {
                    break;
                }

                fface.Windower.SendKeyPress(Keys.TAB);
                Thread.Sleep(200);
            }
        }
예제 #15
0
        /// <summary>
        ///     Execute targeted actions.
        /// </summary>
        /// <param name="actions"></param>
        /// <param name="target"></param>
        public void UseTargetedActions(IEnumerable<BattleAbility> actions, Unit target)
        {
            // Logic error to call this without setting a target first.
            if (actions == null) throw new ArgumentNullException("actions");
            if (target == null) throw new ArgumentNullException("target");

            foreach (var action in actions)
            {
                MoveIntoActionRange(target, action);

                // Face unit
                _fface.Navigator.FaceHeading(target.Position);

                // Target mob if not currently targeted.
                SetTarget(target);

                if (CompositeAbilityTypes.IsSpell.HasFlag(action.Ability.AbilityType))
                {
                    _caster.CastSpell(action);
                }
                else
                {
                    _caster.CastAbility(action);
                }

                // Increase usage count to limit number of usages.
                action.Usages++;
                Thread.Sleep(Config.Instance.GlobalCooldown);
            }
        }
예제 #16
0
        public void UseTargetedActions(IEnumerable<BattleAbility> actions, Unit target)
        {
            if (actions == null) throw new ArgumentNullException(nameof(actions));
            if (target == null) throw new ArgumentNullException(nameof(target));

            foreach (var action in actions)
            {
                MoveIntoActionRange(target, action);
                _fface.Navigator.FaceHeading(target.Position);
                Player.SetTarget(_fface, target);

                if (ResourceHelper.IsSpell(action.Ability.AbilityType))
                {
                    _fface.Navigator.Reset();
                    Thread.Sleep(100);
                    CastSpell(action);
                }
                else
                {
                    CastAbility(action);
                }

                action.Usages++;
                action.LastCast = DateTime.Now.AddSeconds(action.Recast);

                Thread.Sleep(Config.Instance.GlobalCooldown);
            }
        }
예제 #17
0
 private void MoveIntoActionRange(Unit target, BattleAbility action)
 {
     if (target.Distance > action.Distance)
     {
         _fface.Navigator.DistanceTolerance = action.Distance;
         _fface.Navigator.GotoNPC(target.Id, Config.Instance.IsObjectAvoidanceEnabled);
     }
 }