private List <PlayerFlask> GetFlasksWithValidActions(List <PlayerFlask> enabledFlasks, List <FlaskActions> validActions, List <FlaskActions> ignoreActions)
 {
     return(enabledFlasks.Where(x =>
                                (validActions.Contains(x.Action1) || validActions.Contains(x.Action2)) && // Find any flask that matches the actions sent in
                                (ignoreActions == null || !ignoreActions.Contains(x.Action1) && !ignoreActions.Contains(x.Action2)) && // Do not choose ignored flask types
                                FlaskHelper.canUsePotion(x, Settings.FlaskSettings[x.Index].ReservedUses) // Do not return flasks we can't use
                                ).ToList());
 }
        private PlayerFlask findFlaskMatchingAnyAction(List <FlaskActions> flaskActions, Boolean?instant = null, Boolean ignoreBuffs = false, Func <List <FlaskActions> > ignoreFlasksWithAction = null, Boolean isCleansing = false)
        {
            var allFlasks = FlaskHelper.getAllFlaskInfo();

            // We have no flasks or settings for flasks?
            if (allFlasks == null || Settings.FlaskSettings == null)
            {
                if (Settings.Debug)
                {
                    if (allFlasks == null)
                    {
                        LogMessage(PluginName + ": No flasks to match against.", 5);
                    }
                    else if (Settings.FlaskSettings == null)
                    {
                        LogMessage(PluginName + ": Flask settings were null. Hopefully doesn't happen frequently.", 5);
                    }
                }

                return(null);
            }

            if (Settings.Debug)
            {
                foreach (var flask in allFlasks)
                {
                    LogMessage(PluginName + ": Flask: " + flask.Name + " Instant: " + flask.InstantType.ToString() + " Action1: " + flask.Action1 + " Action2: " + flask.Action2, 5);
                }
            }

            List <FlaskActions> ignoreFlaskActions = ignoreFlasksWithAction == null ? null : ignoreFlasksWithAction();

            var flaskList = allFlasks
                            .Where(x =>
                                   Settings.FlaskSettings[x.Index].Enabled &&
                                   flaskHasAvailableAction(flaskActions, ignoreFlaskActions, x) &&
                                   FlaskHelper.canUsePotion(x, Settings.FlaskSettings[x.Index].ReservedUses, isCleansing) &&
                                   FlaskMatchesInstant(x, instant) &&
                                   (ignoreBuffs || MissingFlaskBuff(x))
                                   ).OrderByDescending(x => flaskActions.Contains(x.Action1)).ThenByDescending(x => x.TotalUses - Settings.FlaskSettings[x.Index].ReservedUses).ToList();


            if (flaskList == null || !flaskList.Any())
            {
                if (Settings.Debug)
                {
                    LogError(PluginName + ": No flasks found for action: " + flaskActions[0], 1);
                }
                return(null);
            }

            if (Settings.Debug)
            {
                LogMessage(PluginName + ": Flask(s) found for action: " + flaskActions[0] + " Flask Count: " + flaskList.Count(), 1);
            }

            return(flaskList.FirstOrDefault());
        }