public async Task <bool> TurnInAndHandOver(uint index, BagSlot bagSlot, byte attempts = 20, ushort interval = 200) { var result = SendActionResult.None; var requestAttempts = 0; while (result != SendActionResult.Success && !Request.IsOpen && requestAttempts++ < attempts && Behaviors.ShouldContinue) { result = TurnIn(index); if (result == SendActionResult.InjectionError) { await Behaviors.Sleep(interval); } await Behaviors.Wait(interval, () => Request.IsOpen); } if (requestAttempts > attempts) { return(false); } await Behaviors.Sleep(interval); // Try waiting half of the overall set time, up to 3 seconds if (!Request.IsOpen) { if (!await Coroutine.Wait(Math.Min(3000, (interval * attempts) / 2), () => Request.IsOpen)) { Logger.Instance.Warn( Localization.Localization.MasterPieceSupply_CollectabilityValueNotEnough, bagSlot.Collectability, bagSlot.EnglishName); return(false); } } requestAttempts = 0; while (Request.IsOpen && requestAttempts++ < attempts && Behaviors.ShouldContinue && bagSlot.Item != null) { bagSlot.Handover(); await Behaviors.Wait(interval, () => Request.HandOverButtonClickable); Request.HandOver(); await Behaviors.Wait(interval, () => !Request.IsOpen || SelectYesno.IsOpen); } if (SelectYesno.IsOpen) { Logger.Instance.Warn(Localization.Localization.MasterPieceSupply_FullScrips, bagSlot.EnglishName); return(false); } return(!Request.IsOpen); }
public async Task <bool> FCWorkshop() { Navigator.NavigationProvider = new ServiceNavigationProvider(); Navigator.PlayerMover = new SlideMover(); if (!SubmarinePartsMenu.Instance.IsOpen) { Logging.Write("Trying to open window"); if (!await OpenFCCraftingStation()) { Logging.Write("Nope failed opening FC Workshop window"); return(false); } } if (!SubmarinePartsMenu.Instance.IsOpen) { Logging.Write("Nope failed"); return(false); } // List<LisbethOrder> outList = new List<LisbethOrder>(); var id = 0; var counts = SubmarinePartsMenu.Instance.GetItemAvailCount(); var done = SubmarinePartsMenu.Instance.GetTurninsDone(); foreach (var item in SubmarinePartsMenu.Instance.GetCraftingTurninItems()) { var needed = item.Qty * item.TurnInsRequired - item.Qty * done[id]; var itemCount = (int)DataManager.GetItem((uint)item.ItemId).ItemCount(); var turnInsAvail = itemCount / item.Qty; Logging.Write($"{item}"); Logging.Write($"Player has {itemCount} and {needed} are still needed and can do {turnInsAvail} turnins"); var turnInsNeeded = item.TurnInsRequired - done[id]; if (turnInsNeeded >= 1) { if (turnInsAvail >= 1) { for (var i = 0; i < Math.Min(turnInsAvail, turnInsNeeded); i++) { BagSlot bagSlot = null; if (HqItemCount(item.ItemId) >= item.Qty) { bagSlot = InventoryManager.FilledSlots.First(slot => slot.RawItemId == item.ItemId && slot.IsHighQuality && slot.Count >= item.Qty); Logging.Write($"Have HQ {bagSlot.Name}"); // continue; } else if (ItemCount(item.ItemId) >= item.Qty) { bagSlot = InventoryManager.FilledSlots.FirstOrDefault(slot => slot.RawItemId == item.ItemId && !slot.IsHighQuality && slot.Count >= item.Qty); if (bagSlot == null) { await CloseFCCraftingStation(); await LowerQualityAndCombine(item.ItemId); // var nqSlot = InventoryManager.FilledSlots.FirstOrDefault(slot => slot.RawItemId == item.ItemId && slot.IsHighQuality && slot.Count < item.Qty); await OpenFCCraftingStation(); bagSlot = InventoryManager.FilledSlots.FirstOrDefault(slot => slot.RawItemId == item.ItemId && !slot.IsHighQuality && slot.Count >= item.Qty); Logging.Write($"Need To Lower Quality {bagSlot.Name}"); } else { Logging.Write($"Have NQ {bagSlot.Name}"); } } else { Logging.Write($"Something went wrong {ItemCount(item.ItemId)}"); } if (bagSlot != null) { Logging.Write($"Turn in {bagSlot.Name} HQ({bagSlot.IsHighQuality})"); await Coroutine.Sleep(500); SubmarinePartsMenu.Instance.ClickItem(id); await Coroutine.Wait(5000, () => Request.IsOpen); var isHQ = bagSlot.IsHighQuality; bagSlot.Handover(); await Coroutine.Wait(5000, () => Request.HandOverButtonClickable); if (Request.HandOverButtonClickable) { Request.HandOver(); await Coroutine.Sleep(500); await Coroutine.Wait(5000, () => SelectYesno.IsOpen); if (SelectYesno.IsOpen) { SelectYesno.Yes(); } await Coroutine.Sleep(700); if (!isHQ) { continue; } await Coroutine.Wait(5000, () => SelectYesno.IsOpen); if (SelectYesno.IsOpen) { SelectYesno.Yes(); } await Coroutine.Sleep(700); } else { Logging.Write("HandOver Stuck"); return(false); } } else { Logging.Write("Bagslot is null"); } } } else { Logging.Write($"No Turn ins available {turnInsAvail}"); } } else { Logging.Write($"turnInsNeeded {turnInsNeeded}"); } Logging.Write("--------------"); id++; } await CloseFCCraftingStation(); return(true); }