private static async Task <bool> SendMail(string recipient, List <C_WoWItem> items) { int count = 0; foreach (var cWoWItem in items) { if (!MailHelper.IsOpen) { GarrisonBase.Debug("Send Mail Failed due to mailbox not open!"); return(false); } if (count > 11) { break; } if (BaseSettings.CurrentSettings.MailSendItems.Any(i => i.EntryId == cWoWItem.Entry && i.OnCount > 0)) { var mailItemInfo = BaseSettings.CurrentSettings.MailSendItems.FirstOrDefault(i => i.EntryId == cWoWItem.Entry); if (mailItemInfo != null) { int excessCount = (int)cWoWItem.StackCount - mailItemInfo.OnCount; if (excessCount > 0) { GarrisonBase.Log("Send Mail Spliting Item {0} to send count {1}", cWoWItem.Name, excessCount); int freeBagIndex, freeBagSlot; bool foundFreeSpot = Character.Player.Inventory.FindFreeBagSlot(out freeBagIndex, out freeBagSlot); if (foundFreeSpot) { GarrisonBase.Log("Send Mail Split Item Moving to Bag Index {0} Slot {1}", freeBagIndex, freeBagSlot); bool success = await SplitItem(cWoWItem, excessCount, freeBagIndex, freeBagSlot); if (success) { GarrisonBase.Log("Attaching item {0} to mail", cWoWItem.Name); LuaCommands.UseContainerItem(freeBagIndex, freeBagSlot + 1); await CommonCoroutines.SleepForRandomUiInteractionTime(); await Coroutine.Sleep(StyxWoW.Random.Next(1250, 2223)); count++; } LuaCommands.ClearCursor(); continue; } } } } GarrisonBase.Log("Attaching item {0} to mail", cWoWItem.Name); LuaCommands.UseContainerItem(cWoWItem.BagIndex + 1, cWoWItem.BagSlot + 1); await CommonCoroutines.SleepForRandomUiInteractionTime(); await Coroutine.Sleep(StyxWoW.Random.Next(1250, 2223)); count++; } if (!_mailingSetRecipient) { if (!MailHelper.IsOpen) { GarrisonBase.Debug("Send Mail Failed due to mailbox not open!"); return(false); } LuaCommands.SetSendMailRecipient(recipient); _mailingSetRecipient = true; await CommonCoroutines.SleepForRandomUiInteractionTime(); } if (!MailHelper.IsOpen) { GarrisonBase.Debug("Send Mail Failed due to mailbox not open!"); _mailingSetRecipient = false; return(false); } LuaCommands.ClickSendMailButton(); await CommonCoroutines.SleepForRandomUiInteractionTime(); await Coroutine.Sleep(StyxWoW.Random.Next(1250, 2223)); _mailingSetRecipient = false; return(true); }