Exemplo n.º 1
0
        /// <summary>
        /// Opens the stash and the stash tab of this item.
        /// <para>If the item is in inventory then it opens the inventory</para>
        /// </summary>
        /// <returns></returns>
        public async Task <bool> GoTo()
        {
            if (!string.IsNullOrEmpty(TabName))
            {
                return(await Stash.OpenStashTabTask(TabName));
            }

            //TabName is empty, so it's inventory
            if (!LokiPoe.InGameState.InventoryUi.IsOpened)
            {
                return(await LibCoroutines.OpenInventoryPanel());
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Forces the update of a specific tab
        /// It first removes the items that were in this one last check
        /// Then just reparse the whole tab
        /// Note : This function doesn't take care about the ItemInStashAlreadyCached var
        /// </summary>
        /// <param name="tabName">Tab name to be re-parsed</param>
        /// <returns>true if everything went well</returns>
        public static async Task <bool> UpdateSpecificTab(string tabName)
        {
            if (string.IsNullOrEmpty(tabName))
            {
                return(false);
            }

            if (!await Stash.OpenStashTabTask(tabName))
            {
                return(false);
            }

            // Then process the tab
            if (!LokiPoe.IsInGame)
            {
                CommunityLib.Log.ErrorFormat("[CommunityLib][UpdateSpecificTab] Disconnected?");
                return(false);
            }

            //Stash not opened
            if (!LokiPoe.InGameState.StashUi.IsOpened)
            {
                CommunityLib.Log.InfoFormat("[CommunityLib][UpdateSpecificTab] Stash not opened... returning false");
                return(false);
            }

            // Handling of Public & RemoveOnly tabs for caching (we don't want to cache diz
            if (LokiPoe.InGameState.StashUi.StashTabInfo.IsPublic)
            {
                CommunityLib.Log.Error($"[CommunityLib][UpdateSpecificTab] The tab \"{LokiPoe.InGameState.StashUi.TabControl.CurrentTabName}\" is Public and is not gonna be cached");
                return(false);
            }

            if (LokiPoe.InGameState.StashUi.StashTabInfo.IsRemoveOnly)
            {
                CommunityLib.Log.Error($"[CommunityLib][UpdateSpecificTab] The tab \"{LokiPoe.InGameState.StashUi.TabControl.CurrentTabName}\" is RemoveOnly and is not gonna be cached");
                return(false);
            }

            // Stash should be open, processing cached data in this tab
            // First remove every item in that one
            CachedItemsInStash.RemoveAll(i => i.TabName.Equals(tabName));

            if (LokiPoe.InGameState.StashUi.StashTabInfo.IsPremiumCurrency)
            {
                foreach (var wrapper in LokiPoe.InGameState.StashUi.CurrencyTabInventoryControls
                         .Where(wrp => wrp.CurrencyTabItem != null))
                {
                    CachedItemsInStash.Add(
                        new CachedItemObject(wrapper, wrapper.CurrencyTabItem,
                                             LokiPoe.InGameState.StashUi.TabControl.CurrentTabName)
                        );
                }
            }
            else
            {
                foreach (var item in LokiPoe.InGameState.StashUi.InventoryControl.Inventory.Items)
                {
                    CachedItemsInStash.Add(
                        new CachedItemObject(LokiPoe.InGameState.StashUi.InventoryControl, item,
                                             LokiPoe.InGameState.StashUi.TabControl.CurrentTabName)
                        );
                }
            }

            //Await here is not wanted if we'll want to make fast re-caching the updated stash
            //It's only re-caching, not item usage so no need to use it.
            //await Coroutines.LatencyWait(2);
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Goes to stash, parse every file and save's it in the CachedItemsInStash. It can be runned only once per area change. Other tries will not work (to save time)
        /// </summary>
        /// <param name="force">You can force updating. Use at your own risk!</param>
        /// <returns></returns>
        public static async Task <bool> UpdateItemsInStash(bool force = false)
        {
            //No need to do it again
            if (ItemsInStashAlreadyCached && !force)
            {
                return(true);
            }

            if (CommunityLibSettings.Instance.CacheTabsCollection.Any(d => !string.IsNullOrEmpty(d.Name)))
            {
                var joined = string.Join(", ", CommunityLibSettings.Instance.CacheTabsCollection.Select(d => d.Name));
                CommunityLib.Log.Debug($"[CommunityLib][UpdateItemsInStash] Tabs to cache: {joined}");
                return(await UpdateItemsInStash(CommunityLibSettings.Instance.CacheTabsCollection.Where(d => !string.IsNullOrEmpty(d.Name))));
            }

            // If stash isn't opened, abort this and return
            if (!await Stash.OpenStashTabTask())
            {
                return(false);
            }

            //Delete current stuff
            CachedItemsInStash.Clear();

            while (true)
            {
                //Making sure we can count
                if (!LokiPoe.IsInGame)
                {
                    CommunityLib.Log.ErrorFormat("[CommunityLib][UpdateItemsInStash] Disconnected?");
                    return(false);
                }

                //Stash not opened
                if (!LokiPoe.InGameState.StashUi.IsOpened)
                {
                    CommunityLib.Log.InfoFormat("[CommunityLib][UpdateItemsInStash] Stash not opened? Trying again.");
                    return(await UpdateItemsInStash(force));
                }

                if (LokiPoe.InGameState.StashUi.StashTabInfo.IsPublic)
                {
                    CommunityLib.Log.Info($"[CommunityLib][UpdateItemsInStash] The tab \"{LokiPoe.InGameState.StashUi.TabControl.CurrentTabName}\" is Public and is not gonna be cached");
                    goto NextTab;
                }

                if (LokiPoe.InGameState.StashUi.StashTabInfo.IsRemoveOnly)
                {
                    CommunityLib.Log.Info($"[CommunityLib][UpdateItemsInStash] The tab \"{LokiPoe.InGameState.StashUi.TabControl.CurrentTabName}\" is RemoveOnly and is not gonna be cached");
                    goto NextTab;
                }

                //Different handling for currency tabs
                if (LokiPoe.InGameState.StashUi.StashTabInfo.IsPremiumCurrency)
                {
                    foreach (var wrapper in LokiPoe.InGameState.StashUi.CurrencyTabInventoryControls
                             .Where(wrp => wrp.CurrencyTabItem != null))
                    {
                        CachedItemsInStash.Add(
                            new CachedItemObject(wrapper, wrapper.CurrencyTabItem,
                                                 LokiPoe.InGameState.StashUi.TabControl.CurrentTabName)
                            );
                    }
                }
                else
                {
                    foreach (var item in LokiPoe.InGameState.StashUi.InventoryControl.Inventory.Items)
                    {
                        CachedItemsInStash.Add(
                            new CachedItemObject(LokiPoe.InGameState.StashUi.InventoryControl, item,
                                                 LokiPoe.InGameState.StashUi.TabControl.CurrentTabName)
                            );
                    }
                }

                CommunityLib.Log.Debug("[CommunityLib][UpdateItemsInStash] Parsed items in the stash tab.");

NextTab:
                if (LokiPoe.InGameState.StashUi.TabControl.IsOnLastTab)
                {
                    CommunityLib.Log.DebugFormat("[CommunityLib][UpdateItemsInStash] We're on the last tab: \"{0}\". Finishing.",
                                                 LokiPoe.InGameState.StashUi.TabControl.CurrentTabName);
                    break;
                }

                CommunityLib.Log.DebugFormat("[CommunityLib][UpdateItemsInStash] Switching tabs. Current tab: \"{0}\"",
                                             LokiPoe.InGameState.StashUi.TabControl.CurrentTabName);
                var lastId = LokiPoe.InGameState.StashUi.StashTabInfo.InventoryId;
                if (LokiPoe.InGameState.StashUi.TabControl.NextTabKeyboard() != SwitchToTabResult.None)
                {
                    await Coroutines.ReactionWait();

                    CommunityLib.Log.ErrorFormat("[CommunityLib][UpdateItemsInStash] Failed to switch tabs.");
                    return(false);
                }

                //Sleep to not look too bottish
                if (!await Stash.WaitForStashTabChange(lastId))
                {
                    CommunityLib.Log.ErrorFormat("[CommunityLib][UpdateItemsInStash] Failed to wait for stash tab to change");
                }
                //await Coroutines.LatencyWait(2);
            }

            ItemsInStashAlreadyCached = true;
            return(true);
        }