An ability that should be used in battle. It represents both targeted and buffing abilities allowing the player to choose to cast abilities when a buff has worn.
Наследование: BindableBase
Пример #1
0
 private bool CastAbility(BattleAbility ability, Position position)
 {
     _fface.Navigator.FaceHeading(position, false);
     SendCommand(ability.Command);
     TimeWaiter.Pause(100);
     return(true);
 }
Пример #2
0
        /// <summary>
        ///     Checks whether a spell or ability can be recasted.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="ability"></param>
        /// <returns></returns>
        public static bool IsRecastable(IMemoryAPI fface, BattleAbility ability)
        {
            var recast = 0;

            // No recast time on weaponskills.
            if (ability.AbilityType == AbilityType.Weaponskill)
            {
                return(true);
            }

            // No recast for ranged attacks.
            if (AbilityType.Range == ability.AbilityType)
            {
                return(true);
            }

            // If a spell get spell recast
            if (ResourceHelper.IsSpell(ability.AbilityType))
            {
                recast = fface.Timer.GetSpellRecast(ability.Index);
            }

            // if ability get ability recast.
            if (ResourceHelper.IsAbility(ability.AbilityType))
            {
                recast = fface.Timer.GetAbilityRecast(ability.Index);
            }

            return(recast <= 0);
        }
Пример #3
0
 public static BattleAbility FindAbility()
 {
     var battleAbility = new BattleAbility();
     battleAbility.IsEnabled = true;
     battleAbility.Name = "valid";
     return battleAbility;
 }
Пример #4
0
        public static bool BuffingFilter(IMemoryAPI fface, BattleAbility action)
        {
            var units   = new UnitService(fface);
            var results = ValidateBuffingAction(fface, action, units.MobArray).ToList();
            var usable  = !results.Any(x => x.IsFailure);

            return(usable);
        }
Пример #5
0
 private void MoveIntoActionRange(IUnit target, BattleAbility action)
 {
     if (target.Distance > action.Distance)
     {
         _fface.Navigator.DistanceTolerance = action.Distance;
         _fface.Navigator.GotoNPC(target.Id, Config.Instance.IsObjectAvoidanceEnabled);
     }
 }
Пример #6
0
 private bool CastSpell(BattleAbility ability)
 {
     if (EnsureCast(ability.Command))
     {
         return(MonitorCast());
     }
     return(false);
 }
Пример #7
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);
     }
 }
Пример #8
0
        /// <summary>
        ///     Filters out unusable buffing abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static bool BuffingFilter(IMemoryAPI fface, BattleAbility action)
        {
            var actionContext = new ActionContext
            {
                MemoryAPI = fface,
                BattleAbility = action
            };

            var actionRules = new BuffingActionRules();
            return actionRules.IsValid(actionContext);
        }
Пример #9
0
        /// <summary>
        ///     Filters out unusable buffing abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static bool BuffingFilter(IMemoryAPI fface, BattleAbility action)
        {
            var actionContext = new ActionContext
            {
                MemoryAPI     = fface,
                BattleAbility = action
            };

            var actionRules = new BuffingActionRules();

            return(actionRules.IsValid(actionContext));
        }
Пример #10
0
        public void UseBuffingAction(Ability action)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));

            var baction = new BattleAbility
            {
                Name = action.English,
                IsEnabled = true,
                Ability = action
            };

            UseBuffingActions(new List<BattleAbility> { baction });
        }
Пример #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("target");
     }
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     UseTargetedActions(new List <BattleAbility> {
         action
     }, target);
 }
Пример #12
0
        /// <summary>
        /// Execute a single buffing type action.
        /// </summary>
        /// <param name="action"></param>
        public void UseBuffingAction(Ability action)
        {
            if (action == null) throw new ArgumentNullException(nameof(action));

            // Create new new ability and set its basic required information.
            var baction = new BattleAbility
            {
                Name = action.English,
                IsEnabled = true,
                Ability = action
            };

            // Convert ability to new battle ability object.
            UseBuffingActions(new List<BattleAbility> { baction });
        }
Пример #13
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(MemoryWrapper 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);
                }
            }

            // Distance Check
            if (unit.Distance > action.Distance)
            {
                return(false);
            }

            return(true);
        }
Пример #14
0
        /// <summary>
        /// Execute a single buffing type action.
        /// </summary>
        /// <param name="action"></param>
        public void UseBuffingAction(Ability action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }

            // Create new new ability and set its basic required information.
            var baction = new BattleAbility
            {
                Name      = action.English,
                IsEnabled = true,
                Ability   = action
            };

            // Convert ability to new battle ability object.
            UseBuffingActions(new List <BattleAbility> {
                baction
            });
        }
Пример #15
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;
        }
Пример #16
0
 private bool CastAbility(BattleAbility ability)
 {
     _fface.Windower.SendString(ability.Command);
     TimeWaiter.Pause(100);
     return(true);
 }
Пример #17
0
 /// <summary>
 ///     Finds the list containing the given battle ability.
 /// </summary>
 /// <param name="ability"></param>
 /// <returns></returns>
 private BattleList FindListContainingAbility(BattleAbility ability)
 {
     return Config.Instance.BattleLists
         .FirstOrDefault(x => x.Actions.Contains(ability));
 }
Пример #18
0
 private bool CastAbility(BattleAbility ability)
 {
     SendCommand(ability.Command);
     TimeWaiter.Pause(100);
     return(true);
 }
Пример #19
0
        private bool MoveIntoActionRange(EasyFarm.Context.IGameContext context, IUnit target, BattleAbility action)
        {
            if (target.Distance > action.Distance)
            {
                var path = context.NavMesh.FindPathBetween(context.API.Player.Position, context.Target.Position);
                if (path.Count > 0)
                {
                    if (path.Count > 1)
                    {
                        _fface.Navigator.DistanceTolerance = 0.5;
                    }
                    else
                    {
                        _fface.Navigator.DistanceTolerance = action.Distance;
                    }

                    while (path.Count > 0 && path.Peek().Distance(context.API.Player.Position) <= _fface.Navigator.DistanceTolerance)
                    {
                        path.Dequeue();
                    }

                    if (path.Count > 0)
                    {
                        context.API.Navigator.GotoNPC(target.Id, path.Peek(), true);
                    }
                    else
                    {
                        context.API.Navigator.Reset();
                    }
                }

                return(false);
            }

            return(true);
        }
Пример #20
0
        /// <summary>
        ///     Add an move to the currently selected list.
        /// </summary>
        private void AddAction()
        {
            // Check to see if an ability is selected. If so, find the list with which to add the 
            // new ability under. 
            if (SelectedAbility != null)
            {
                SelectedList = FindListContainingAbility(SelectedAbility);
            }

            // Now, if the user has either selected an ability or a list, 
            // add the new ability. 
            if (SelectedList != null)
            {
                var action = new BattleAbility();
                SelectedList.Actions.Add(action);
            }
        }
Пример #21
0
 /// <summary>
 ///     Casts a spell with monitoring.
 /// </summary>
 /// <param name="ability"></param>
 /// <returns></returns>
 public bool CastSpell(BattleAbility ability)
 {
     return CastSpell(ability.Ability);
 }
Пример #22
0
 /// <summary>
 ///     Execute a signle buffing type action.
 /// </summary>
 /// <param name="action"></param>
 public void UseBuffingAction(BattleAbility action)
 {
     if (action == null) throw new ArgumentNullException("action");
     UseBuffingActions(new List<BattleAbility> {action});
 }
Пример #23
0
        /// <summary>
        ///     Filters out unusable buffing abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <param name="units"></param>
        /// <returns></returns>
        public static IEnumerable <Result> ValidateBuffingAction(
            IMemoryAPI fface,
            BattleAbility action,
            ICollection <IUnit> units)
        {
            // Return if not enabled.
            if (!action.IsEnabled)
            {
                yield return(Result.Fail("Must be enabled"));
            }

            // Name Check
            if (string.IsNullOrWhiteSpace(action.Name))
            {
                yield return(Result.Fail("Must have name"));
            }

            // MP Check
            if (action.MpCost > fface.Player.MPCurrent)
            {
                yield return(Result.Fail("Not enough mp"));
            }

            // TP Check
            if (action.TpCost > fface.Player.TPCurrent)
            {
                yield return(Result.Fail("Not enough tp"));
            }

            // MP Range
            var mpReserve = new Range(action.MPReserveLow, action.MPReserveHigh);

            if (!mpReserve.InRange(fface.Player.MPPCurrent) && !mpReserve.NotSet())
            {
                yield return(Result.Fail("Outside mp reserve range"));
            }

            // TP Range
            var tpReserve = new Range(action.TPReserveLow, action.TPReserveHigh);

            if (!tpReserve.InRange(fface.Player.TPCurrent) && !tpReserve.NotSet())
            {
                yield return(Result.Fail("Outside tp reserve range"));
            }

            // Usage Limit Check.
            if (action.UsageLimit != 0)
            {
                if (action.Usages > action.UsageLimit)
                {
                    yield return(Result.Fail("Max uses reached"));
                }
            }

            // Recast Check
            if (!AbilityUtils.IsRecastable(fface, action))
            {
                yield return(Result.Fail("Not recastable"));
            }

            // Limiting Status Effect Check for Spells.
            if (ResourceHelper.IsSpell(action.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsSpell.Intersect(fface.Player.StatusEffects).Any())
                {
                    yield return(Result.Fail("Status effect blocking spell"));
                }
            }

            // Limiting Status Effect Check for Abilities.
            if (ResourceHelper.IsAbility(action.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsAbility.Intersect(fface.Player.StatusEffects).Any())
                {
                    yield return(Result.Fail("Status effect blocking ability"));
                }
            }

            // Player HP Checks Enabled.
            if (action.PlayerLowerHealth != 0 || action.PlayerUpperHealth != 0)
            {
                // Player Upper HP Check
                if (fface.Player.HPPCurrent > action.PlayerUpperHealth)
                {
                    yield return(Result.Fail("Player health too high"));
                }

                // Player Lower HP Check
                if (fface.Player.HPPCurrent < action.PlayerLowerHealth)
                {
                    yield return(Result.Fail("Player health too low"));
                }
            }

            // Status Effect Checks Enabled
            if (!string.IsNullOrWhiteSpace(action.StatusEffect))
            {
                var hasEffect = fface.Player.StatusEffects.Any(effect =>
                                                               Regex.IsMatch(effect.ToString(),
                                                                             action.StatusEffect.Replace(" ", "_"),
                                                                             RegexOptions.IgnoreCase));

                // Contains Effect Check
                if (hasEffect && !action.TriggerOnEffectPresent)
                {
                    yield return(Result.Fail("Player missing status effect"));
                }

                // Missing EFfect Check
                if (!hasEffect && action.TriggerOnEffectPresent)
                {
                    yield return(Result.Fail("Player contains status effect"));
                }
            }

            // Check if action's recast period has passed.
            if (action.Recast != 0)
            {
                if (action.LastCast > DateTime.Now)
                {
                    yield return(Result.Fail("Recast period not reached"));
                }
            }

            // Do not cast trust magic with aggro.
            var isTrustMagic = action.AbilityType == AbilityType.Trust;
            var hasAggro     = units.Any(x => x.HasAggroed);

            if (isTrustMagic && hasAggro)
            {
                yield return(Result.Fail("Cannot use trust magic with aggro"));
            }

            // Do not cast action not matching chat text.
            if (!string.IsNullOrEmpty(action.ChatEvent))
            {
                var chatEntries = fface.Chat.ChatEntries.ToList();

                List <EliteAPI.ChatEntry> matches = chatEntries
                                                    .Where(x => x.Text.ToLower().Contains(action.ChatEvent.ToLower())).ToList();

                if (!matches.Any())
                {
                    yield return(Result.Fail("Chat message has not been received"));
                }

                if (action.ChatEventPeriod.HasValue && !matches.Any(x => DateTime.Now <= x.Timestamp.Add(action.ChatEventPeriod.Value)))
                {
                    yield return(Result.Fail("No chat messages valid for the given time range"));
                }
            }
        }
Пример #24
0
 private bool CastAbility(BattleAbility ability)
 {
     return CastAbility(ability.Ability);
 }
Пример #25
0
        /// <summary>
        ///     Filters out unusable buffing abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static bool BuffingFilter(MemoryWrapper fface, BattleAbility action)
        {
            // Return if not enabled.
            if (!action.IsEnabled)
            {
                return(false);
            }

            // Name Check
            if (string.IsNullOrWhiteSpace(action.Name))
            {
                return(false);
            }

            // MP Check
            if (action.Ability.MpCost > fface.Player.MPCurrent)
            {
                return(false);
            }

            // TP Check
            if (action.Ability.TpCost > fface.Player.TPCurrent)
            {
                return(false);
            }

            // Usage Limit Check.
            if (action.UsageLimit != 0)
            {
                if (action.Usages > action.UsageLimit)
                {
                    return(false);
                }
            }

            // Recast Check
            if (!AbilityUtils.IsRecastable(fface, action.Ability))
            {
                return(false);
            }

            // Limiting Status Effect Check for Spells.
            if (ResourceHelper.IsSpell(action.Ability.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsSpell.Intersect(fface.Player.StatusEffects).Any())
                {
                    return(false);
                }
            }

            // Limiting Status Effect Check for Abilities.
            if (ResourceHelper.IsAbility(action.Ability.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsAbility.Intersect(fface.Player.StatusEffects).Any())
                {
                    return(false);
                }
            }

            // Player HP Checks Enabled.
            if (action.PlayerLowerHealth != 0 || action.PlayerUpperHealth != 0)
            {
                // Player Upper HP Check
                if (fface.Player.HPPCurrent > action.PlayerUpperHealth)
                {
                    return(false);
                }

                // Player Lower HP Check
                if (fface.Player.HPPCurrent < action.PlayerLowerHealth)
                {
                    return(false);
                }
            }

            // Status Effect Checks Enabled
            if (!string.IsNullOrWhiteSpace(action.StatusEffect))
            {
                var hasEffect = fface.Player.StatusEffects.Any(effect =>
                                                               Regex.IsMatch(effect.ToString(),
                                                                             action.StatusEffect.Replace(" ", "_"),
                                                                             RegexOptions.IgnoreCase));

                // Contains Effect Check
                if (hasEffect && !action.TriggerOnEffectPresent)
                {
                    return(false);
                }

                // Missing EFfect Check
                if (!hasEffect && action.TriggerOnEffectPresent)
                {
                    return(false);
                }
            }

            // Check if action's recast period has passed.
            if (action.Recast != 0)
            {
                if (action.LastCast > DateTime.Now)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #26
0
 private bool CastSpell(BattleAbility ability)
 {
     return CastSpell(ability.Ability);
 }
Пример #27
0
 /// <summary>
 ///     Casts a spell with monitoring.
 /// </summary>
 /// <param name="ability"></param>
 /// <returns></returns>
 public bool CastSpell(BattleAbility ability)
 {
     return(CastSpell(ability.Ability));
 }
Пример #28
0
 /// <summary>
 ///     Casts an ability with no monitoring.
 /// </summary>
 /// <param name="ability"></param>
 /// <returns></returns>
 public bool CastAbility(BattleAbility ability)
 {
     return CastAbility(ability.Ability);
 }
Пример #29
0
        /// <summary>
        ///     Ensures a list has at least one ability item in it.
        /// </summary>
        public void KeepOne()
        {
            if (SelectedList == null) return;

            // Ensure there is atleast one ability. 
            if (!SelectedList.Actions.Any())
            {
                var action = new BattleAbility();
                SelectedList.Actions.Add(action);
            }
        }
Пример #30
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);
 }
Пример #31
0
        /// <summary>
        ///     Filters out unusable buffing abilities.
        /// </summary>
        /// <param name="fface"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static bool BuffingFilter(FFACE fface, BattleAbility action)
        {
            // Return if not enabled.
            if (!action.IsEnabled) return false;

            // Name Check
            if (string.IsNullOrWhiteSpace(action.Name)) return false;

            // MP Check
            if (action.Ability.MpCost > fface.Player.MPCurrent) return false;

            // TP Check
            if (action.Ability.TpCost > fface.Player.TPCurrent) return false;

            // Usage Limit Check.
            if (action.UsageLimit != 0)
            {
                if (action.Usages > action.UsageLimit) return false;
            }

            // Recast Check
            if (!AbilityUtils.IsRecastable(fface, action.Ability)) return false;

            // Limiting Status Effect Check for Spells.
            if (CompositeAbilityTypes.IsSpell.HasFlag(action.Ability.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsSpell.Intersect(fface.Player.StatusEffects).Any())
                {
                    return false;
                }
            }

            // Limiting Status Effect Check for Abilities.
            if (CompositeAbilityTypes.IsAbility.HasFlag(action.Ability.AbilityType))
            {
                if (ProhibitEffects.ProhibitEffectsAbility.Intersect(fface.Player.StatusEffects).Any())
                {
                    return false;
                }
            }

            // Player HP Checks Enabled.
            if (action.PlayerLowerHealth != 0 || action.PlayerUpperHealth != 0)
            {
                // Player Upper HP Check
                if (fface.Player.HPPCurrent > action.PlayerUpperHealth) return false;

                // Player Lower HP Check
                if (fface.Player.HPPCurrent < action.PlayerLowerHealth) return false;
            }

            // Status Effect Checks Enabled
            if (!string.IsNullOrWhiteSpace(action.StatusEffect))
            {
                var hasEffect = fface.Player.StatusEffects.Any(effect =>
                    Regex.IsMatch(effect.ToString(),
                        action.StatusEffect.Replace(" ", "_"),
                        RegexOptions.IgnoreCase));

                // Contains Effect Check
                if (hasEffect && !action.TriggerOnEffectPresent) return false;

                // Missing EFfect Check
                if (!hasEffect && action.TriggerOnEffectPresent) return false;
            }

            return true;
        }
Пример #32
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);
     }
 }
Пример #33
0
 /// <summary>
 ///     Casts an ability with no monitoring.
 /// </summary>
 /// <param name="ability"></param>
 /// <returns></returns>
 public bool CastAbility(BattleAbility ability)
 {
     return(CastAbility(ability.Ability));
 }
Пример #34
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);
     }
 }