Exemple #1
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"));
                }
            }
        }
Exemple #2
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);
        }