/// <summary> /// This task (awaitable) handles the whole process to talk to a NPC to reach the list of choices /// </summary> /// <param name="npcName">Name of the NPC to interact with</param> /// <returns>boolean</returns> public static async Task<bool> TalkToNpc(string npcName) { //await Coroutines.CloseBlockingWindows(); var ret = await LibCoroutines.TalkToNpc(npcName, true); await Coroutines.LatencyWait(); await Coroutines.ReactionWait(); return ret == Results.TalkToNpcError.None; }
/// <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))); }
/// <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); }
/// <summary> /// Opens the stash at typed tab name /// </summary> /// <param name="stashTabName">If set to null or empty, first tab of the stash will be opened</param> /// <returns></returns> public static async Task <bool> OpenStashTabTask(string stashTabName = "") { //open stash if (!StashUI.IsOpened) { var isOpenedErr = await LibCoroutines.OpenStash(); await Dialog.WaitForPanel(Dialog.PanelType.Stash); if (isOpenedErr != Results.OpenStashError.None) { CommunityLib.Log.ErrorFormat("[OpenStashTab] Fail to open the stash. Error: {0}", isOpenedErr); return(false); } } if (string.IsNullOrEmpty(stashTabName)) { var isSwitchedFtErr = GoToFirstTab(); if (isSwitchedFtErr != SwitchToTabResult.None) { CommunityLib.Log.ErrorFormat("[OpenStashTab] Fail to switch to the first tab"); return(false); } await WaitForStashTabChange(); return(true); } if (StashUI.TabControl.CurrentTabName != stashTabName) { var isSwitchedErr = StashUI.TabControl.SwitchToTabMouse(stashTabName); if (isSwitchedErr != SwitchToTabResult.None) { CommunityLib.Log.ErrorFormat("[OpenStashTab] Fail to switch to the tab: {0}", isSwitchedErr); return(false); } await WaitForStashTabChange(); } return(true); }
/// <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> /// Goes to the specified area using waypoint. /// </summary> /// <param name="name">Name of the area eg "Highgate"</param> /// <param name="difficulty"></param> /// <param name="newInstance">Do you want to open new instance?</param> /// <returns></returns> public static async Task <LokiPoe.InGameState.TakeWaypointResult> TakeWaypoint(string name, Difficulty difficulty = Difficulty.Unknown, bool newInstance = false) { //We are already there if (LokiPoe.LocalData.WorldArea.Name == name && LokiPoe.LocalData.WorldArea.Difficulty == difficulty && !newInstance) { return(LokiPoe.InGameState.TakeWaypointResult.None); } //await Coroutines.CloseBlockingWindows(); // First try of fastgotohideout instead of LokiPoe.InGameState.WorldUi.GoToHideout() if (name.Equals("Hideout", StringComparison.OrdinalIgnoreCase) && (LokiPoe.Me.IsInHideout || LokiPoe.Me.IsInTown)) { await Coroutines.CloseBlockingWindows(); var res = await FastGoToHideout(); switch (res) { case Results.FastGoToHideoutResult.None: return(LokiPoe.InGameState.TakeWaypointResult.None); case Results.FastGoToHideoutResult.NoHideout: return(LokiPoe.InGameState.TakeWaypointResult.AreaNotFound); case Results.FastGoToHideoutResult.NotInGame: return(LokiPoe.InGameState.TakeWaypointResult.UiNotOpen); //if we timed out then try to use default method like below } } if (!LokiPoe.InGameState.WorldUi.IsOpened) { var opened = await LibCoroutines.OpenWaypoint(); if (opened != Results.OpenWaypointError.None) { CommunityLib.Log.ErrorFormat("[TakeWaypoint] Fail to open waypoint. Error: \"{0}\".", opened); return(LokiPoe.InGameState.TakeWaypointResult.WaypointControlNotVisible); } } if (difficulty == Difficulty.Unknown) { difficulty = LokiPoe.CurrentWorldArea.Difficulty; } //var areaId = name == "Hideout" ? "" : GetZoneId(difficulty.ToString(), name); CommunityLib.Log.InfoFormat($"[TakeWaypoint] Going to {name} at {difficulty}."); var areaHash = LokiPoe.LocalData.AreaHash; var taken = name.Equals("Hideout", StringComparison.OrdinalIgnoreCase) ? LokiPoe.InGameState.WorldUi.GoToHideout() : LokiPoe.InGameState.WorldUi.TakeWaypoint(LokiPoe.GetZoneId(difficulty.ToString(), name), newInstance, Int32.MaxValue); if (taken != LokiPoe.InGameState.TakeWaypointResult.None) { CommunityLib.Log.ErrorFormat("[TakeWaypoint] Failed to take waypoint to \"{0}\". Error: \"{1}\".", name, taken); return(taken); } var awaited = await Areas.WaitForAreaChange(areaHash); return(awaited ? LokiPoe.InGameState.TakeWaypointResult.None : LokiPoe.InGameState.TakeWaypointResult.CouldNotJoinNewInstance); }
public static async Task <Results.ClearCursorResults> ClearCursorTask(int maxTries = 3) { var cursMode = LokiPoe.InGameState.CursorItemOverlay.Mode; if (cursMode == LokiPoe.InGameState.CursorItemModes.None) { CommunityLib.Log.DebugFormat("[CommunityLib][ClearCursorTask] Nothing is on cursor, continue execution"); return(Results.ClearCursorResults.None); } if (cursMode == LokiPoe.InGameState.CursorItemModes.VirtualMove || cursMode == LokiPoe.InGameState.CursorItemModes.VirtualUse) { CommunityLib.Log.DebugFormat("[CommunityLib][ClearCursorTask] VirtualMode detected, pressing escape to clear"); LokiPoe.Input.SimulateKeyEvent(Keys.Escape, true, false, false); return(Results.ClearCursorResults.None); } var cursorhasitem = LokiPoe.InGameState.CursorItemOverlay.Item; // there is a item on the cursor let clear it int attempts = 0; while (cursorhasitem != null && attempts < maxTries) { if (attempts > maxTries) { return(Results.ClearCursorResults.MaxTriesReached); } if (!LokiPoe.InGameState.InventoryUi.IsOpened) { await LibCoroutines.OpenInventoryPanel(); await Coroutines.LatencyWait(); await Coroutines.ReactionWait(); if (!LokiPoe.InGameState.InventoryUi.IsOpened) { return(Results.ClearCursorResults.InventoryNotOpened); } } int col, row; if (!LokiPoe.InGameState.InventoryUi.InventoryControl_Main.Inventory.CanFitItem(cursorhasitem.Size, out col, out row)) { CommunityLib.Log.ErrorFormat("[CommunityLib][ClearCursorTask] Now stopping the bot because it cannot continue."); BotManager.Stop(); return(Results.ClearCursorResults.NoSpaceInInventory); } var res = LokiPoe.InGameState.InventoryUi.InventoryControl_Main.PlaceCursorInto(col, row); if (res == PlaceCursorIntoResult.None) { if (!await WaitForCursorToBeEmpty()) { CommunityLib.Log.ErrorFormat("[CommunityLib][ClearCursorTask] WaitForCursorToBeEmpty failed."); } await Coroutines.ReactionWait(); return(Results.ClearCursorResults.None); } CommunityLib.Log.DebugFormat("[CommunityLib][ClearCursorTask] Placing item into inventory failed, Err : {0}", res); switch (res) { case PlaceCursorIntoResult.ItemWontFit: return(Results.ClearCursorResults.NoSpaceInInventory); case PlaceCursorIntoResult.NoItemToMove: return(Results.ClearCursorResults.None); } await Coroutine.Sleep(3000); await Coroutines.LatencyWait(); await Coroutines.ReactionWait(); cursorhasitem = LokiPoe.InGameState.CursorItemOverlay.Item; attempts++; } return(Results.ClearCursorResults.None); }