Exemple #1
0
        /// <summary>
        /// Return the InventoryControlWrapper for an item and its class
        /// </summary>
        /// <param name="condition"></param>
        /// <returns>StashItem</returns>
        public static CachedItemObject FindItemInStashTab(CommunityLib.FindItemDelegate condition)
        {
            //If it's regular tab then it's rather simple
            if (!StashUI.StashTabInfo.IsPremiumCurrency)
            {
                // Gather the first item matching the condition
                var item = StashUI.InventoryControl.Inventory.Items.FirstOrDefault(d => condition(d));
                // Return it if this one is not null
                if (item != null)
                {
                    return(new CachedItemObject(StashUI.InventoryControl, item, StashUI.TabControl.CurrentTabName));
                }
            }

            //Premium stash tab
            else
            {
                var wrapper = StashUI.CurrencyTabInventoryControls.FirstOrDefault(d => d.CurrencyTabItem != null && condition(d.CurrencyTabItem));
                var item    = wrapper?.CurrencyTabItem;
                if (item != null)
                {
                    return(new CachedItemObject(wrapper, item, StashUI.TabControl.CurrentTabName));
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Find items in a stash tab matching a condition
        /// </summary>
        /// <param name="condition">Condition to pass item through</param>
        /// <returns>List of CachedItemObjects</returns>
        public static List <CachedItemObject> FindItemsInStashTab(CommunityLib.FindItemDelegate condition)
        {
            var ret = new List <CachedItemObject>();

            //If it's regular tab then it's rather simple
            if (!StashUI.StashTabInfo.IsPremiumCurrency)
            {
                // Gather the first item matching the condition
                var items = StashUI.InventoryControl.Inventory.Items.Where(d => condition(d)).ToList();
                foreach (var item in items)
                {
                    ret.Add(new CachedItemObject(StashUI.InventoryControl, item, StashUI.TabControl.CurrentTabName));
                }
            }

            //Premium stash tab
            else
            {
                var wrappers = StashUI.CurrencyTabInventoryControls.Where(d => d.CurrencyTabItem != null && condition(d.CurrencyTabItem)).ToList();
                foreach (var wrapper in wrappers)
                {
                    var item = wrapper?.CurrencyTabItem;
                    if (item != null)
                    {
                        ret.Add(new CachedItemObject(wrapper, item, StashUI.TabControl.CurrentTabName));
                    }
                }
            }

            return(ret);
        }
Exemple #3
0
        /// <summary>
        /// Function that returns a specific item matching condition (Main inventory only !)
        /// </summary>
        /// <param name="condition">condition to pass item through</param>
        /// <returns>Item</returns>
        public static async Task <Item> FindItem(CommunityLib.FindItemDelegate condition)
        {
            //Open Inventory panel
            if (!LokiPoe.InGameState.InventoryUi.IsOpened)
            {
                await LibCoroutines.OpenInventoryPanel();

                await Coroutines.ReactionWait();
            }

            return(LokiPoe.InGameState.InventoryUi.InventoryControl_Main.Inventory.Items.FirstOrDefault(d => condition(d)));
        }
Exemple #4
0
        /// <summary>
        /// Finds the item in inventory or in Stash
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static async Task <Tuple <Results.FindItemInTabResult, CachedItemObject> > SearchForItem(CommunityLib.FindItemDelegate condition)
        {
            //Open Inventory panel
            if (!LokiPoe.InGameState.InventoryUi.IsOpened)
            {
                await LibCoroutines.OpenInventoryPanel();

                await Coroutines.ReactionWait();
            }

            var item = LokiPoe.InGameState.InventoryUi.InventoryControl_Main.Inventory.Items.FirstOrDefault(d => condition(d));

            if (item != null)
            {
                return(new Tuple <Results.FindItemInTabResult, CachedItemObject>
                       (
                           Results.FindItemInTabResult.None,
                           new CachedItemObject(LokiPoe.InGameState.InventoryUi.InventoryControl_Main, item)
                       ));
            }

            //Now let's look in Stash
            return(await Stash.FindTabContainingItem(condition));
        }
Exemple #5
0
        /// <summary>
        /// This function iterates through the stash to find an item by name
        /// If a tab is reached and the item is found, GUI will be stopped on this tab so you can directly interact with it.
        /// </summary>
        /// <param name="condition">Condition to pass item through</param>
        /// <returns></returns>
        public static async Task <Tuple <Results.FindItemInTabResult, CachedItemObject> > FindTabContainingItem(CommunityLib.FindItemDelegate condition)
        {
            // If stash isn't opened, abort this and return
            if (!await OpenStashTabTask())
            {
                return(new Tuple <Results.FindItemInTabResult, CachedItemObject>(Results.FindItemInTabResult.GuiNotOpened, null));
            }

            // If we fail to go to first tab, return
            // if (GoToFirstTab() != SwitchToTabResult.None)
            //     return new Tuple<Results.FindItemInTabResult, StashItem>(Results.FindItemInTabResult.GoToFirstTabFailed, null);

            foreach (var tabName in StashUI.TabControl.TabNames)
            {
                // If the item has no occurences in this tab, switch to the next one
                var it = FindItemInStashTab(condition);
                if (it == null)
                {
                    // On last tab? break execution
                    if (StashUI.TabControl.IsOnLastTab)
                    {
                        break;
                    }

                    int switchAttemptsPerTab = 0;
                    while (true)
                    {
                        // If we tried 3 times to switch and failed, return
                        if (switchAttemptsPerTab > 2)
                        {
                            return(new Tuple <Results.FindItemInTabResult, CachedItemObject>(Results.FindItemInTabResult.SwitchToTabFailed, null));
                        }

                        var switchTab = StashUI.TabControl.SwitchToTabMouse(tabName);

                        // If the switch went fine, keep searching
                        if (switchTab == SwitchToTabResult.None)
                        {
                            break;
                        }

                        switchAttemptsPerTab++;
                        await Coroutines.LatencyWait();

                        await Coroutines.ReactionWait();
                    }

                    // Keep searching...
                    await Coroutines.LatencyWait();

                    await Coroutines.ReactionWait();

                    continue;
                }

                // We Found a tab, return informations
                return(new Tuple <Results.FindItemInTabResult, CachedItemObject>(Results.FindItemInTabResult.None, it));
            }

            return(new Tuple <Results.FindItemInTabResult, CachedItemObject>(Results.FindItemInTabResult.ItemNotFoundInTab, null));
        }