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());
 }
Exemple #2
0
        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} Slot: {flask.Index} Instant: {flask.InstantType} 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());
        }
        //It seems horribly inefficient that we're going through all this trouble to create a list and then only using FirstOrDefault() from it.
        private PlayerFlask findFlaskMatchingAnyAction(List <FlaskActions> flaskActions, Boolean?instant = null, Func <List <FlaskActions> > ignoreFlasksWithAction = null)
        {
            List <PlayerFlask> allFlasks = FlaskHelper.getAllFlaskInfo();

            if (!AreThereFlasksToUse(allFlasks))
            {
                return(null);
            }
            LogFlasks(allFlasks);

            var flaskList = GetListOfFlasksToUse(ignoreFlasksWithAction, allFlasks, flaskActions, instant);

            if (flaskList == null || !flaskList.Any())
            {
                LogNoFlasks(flaskActions);
                return(null);
            }
            LogFlaskToUse(flaskActions, flaskList);

            return(flaskList.FirstOrDefault());
        }
Exemple #4
0
        public void FlaskUi()
        {
            if (!Settings.FlaskUiEnable.Value)
            {
                return;
            }

            var allFlasks = FlaskHelper.GetAllFlaskInfo();

            if (allFlasks == null || allFlasks.Count == 0)
            {
                return;
            }

            var   x         = GameController.Window.GetWindowRectangle().Width *Settings.FlaskPositionX.Value * .01f;
            var   y         = GameController.Window.GetWindowRectangle().Height *Settings.FlaskPositionY.Value * .01f;
            var   position  = new Vector2(x, y);
            float maxWidth  = 0;
            float maxheight = 0;
            var   textColor = Color.WhiteSmoke;

            int lastIndex = 0;

            foreach (var flasks in allFlasks.OrderBy(flask => flask.Index))
            {
                if (!Settings.FlaskSettings[flasks.Index].Enabled)
                {
                    textColor = Color.Red;
                }
                else
                {
                    switch (flasks.Mods.ItemRarity)
                    {
                    case ItemRarity.Magic:
                        textColor = Color.CornflowerBlue;
                        break;

                    case ItemRarity.Unique:
                        textColor = Color.Chocolate;
                        break;

                    case ItemRarity.Normal:
                        break;

                    case ItemRarity.Rare:
                        break;

                    default:
                        textColor = Color.WhiteSmoke;
                        break;
                    }
                }

                // Flasks are returned in a list that may not contain every flask
                // We need to make sure we are drawing to the right place
                while (lastIndex++ < flasks.Index)
                {
                    var skippedSize = Graphics.DrawText("", Settings.FlaskTextSize.Value, position, textColor);
                    position.Y += skippedSize.Height;
                    maxheight  += skippedSize.Height;
                    maxWidth    = Math.Max(maxWidth, skippedSize.Width);
                }

                var size = Graphics.DrawText(flasks.Name, Settings.FlaskTextSize.Value, position, textColor);
                position.Y += size.Height;
                maxheight  += size.Height;
                maxWidth    = Math.Max(maxWidth, size.Width);
            }
            var background = new RectangleF(x, y, maxWidth, maxheight);

            Graphics.DrawFrame(background, 5, Color.Black);
            Graphics.DrawImage("lightBackground.png", background);
        }