Example #1
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);
        }
Example #2
0
        /// <summary>
        /// This coroutine interacts with stash and waits for the stash panel to open. When called from a hideout,
        /// the stash must be in spawn range, otherwise the coroutine will fail.
        /// </summary>
        ///<param name="guild">Should the guild stash be opened?</param>
        /// <returns>An OpenStashError that describes the result.</returns>
        public static async Task <Results.OpenStashError> OpenStash(bool guild = false)
        {
            await Coroutines.CloseBlockingWindows();

            await Coroutines.FinishCurrentAction();

            var stash = Stash.DetermineStash(guild);

            if (stash == null)
            {
                if (LokiPoe.Me.IsInHideout)
                {
                    return(Results.OpenStashError.NoStash);
                }

                var mtl = await Navigation.MoveToLocation(
                    ExilePather.FastWalkablePositionFor(Actor.GuessStashLocation()), 25, 60000,
                    () => Stash.DetermineStash(guild) != null && Stash.DetermineStash(guild).Distance < 75);

                if (!mtl)
                {
                    return(Results.OpenStashError.CouldNotMoveToStash);
                }

                stash = Stash.DetermineStash(guild);
                if (stash == null)
                {
                    return(Results.OpenStashError.NoStash);
                }
            }

            if (stash.Distance > 30)
            {
                var p = stash.Position;
                if (!await Navigation.MoveToLocation(ExilePather.FastWalkablePositionFor(p), 25, 15000, () => false))
                {
                    return(Results.OpenStashError.CouldNotMoveToStash);
                }
            }

            await Coroutines.FinishCurrentAction();

            stash = Stash.DetermineStash(guild);
            if (stash == null)
            {
                return(Results.OpenStashError.NoStash);
            }

            if (!await InteractWith(stash))
            {
                return(Results.OpenStashError.InteractFailed);
            }

            if (guild)
            {
                if (!await Dialog.WaitForPanel(Dialog.PanelType.GuildStash))
                {
                    return(Results.OpenStashError.StashPanelDidNotOpen);
                }

                await Stash.WaitForStashTabChange(guild : true);
            }
            else
            {
                if (!await Dialog.WaitForPanel(Dialog.PanelType.Stash))
                {
                    return(Results.OpenStashError.StashPanelDidNotOpen);
                }

                await Stash.WaitForStashTabChange();
            }

            return(Results.OpenStashError.None);
        }