/// <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)); }
/// <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); }
/// <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); }
/// <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); }