Ejemplo n.º 1
0
        private async Task <bool> Interaction()
        {
            TreeRoot.StatusText = String.Format("Behavior {0} Interaction", Type.ToString());

            if (Character.Player.Inventory.TotalFreeSlots == 0)
            {
                GarrisonBase.Err("Bags are full!");
                IsDone = true;
                return(false);
            }

            RefreshInboxMailItemsCollection();

            if (InboxMailItems.Count > 0)
            {
                if (!LuaEvents.MailOpen)
                {
                    return(true);
                }

                if (LuaUI.InboxPreviousPage.IsEnabled())
                {
                    //We need to reset back to first page!
                    while (LuaUI.InboxPreviousPage.IsEnabled())
                    {
                        LuaUI.InboxPreviousPage.Click();
                        await CommonCoroutines.SleepForRandomUiInteractionTime();
                    }
                }

                int highestInboxPageIndex = 1;
                foreach (var item in InboxMailItems)
                {
                    if (item.InboxPageIndex > highestInboxPageIndex)
                    {
                        highestInboxPageIndex = item.InboxPageIndex;
                    }
                }

                if (highestInboxPageIndex > 1)
                {
                    //We want to loot mail that is not on the first page..
                    if (!LuaUI.InboxPreviousPage.IsEnabled())
                    {
                        for (int i = 1; i < highestInboxPageIndex; i++)
                        {//Click next page until we are at the correct page.
                            LuaUI.InboxNextPage.Click();
                            await CommonCoroutines.SleepForRandomUiInteractionTime();
                        }
                    }
                }

                //Now get all items on the same page.. order by highest index first (last item)
                var itemsToGet =
                    InboxMailItems.Where <InboxMailItem>(i => i.InboxPageIndex == highestInboxPageIndex)
                    .OrderByDescending(i => i.Index)
                    .ToList();

                foreach (var inboxMailItem in itemsToGet)
                {
                    //Open the mail item..
                    LuaCommands.ClickMailItemButton(inboxMailItem.RealIndex);
                    await CommonCoroutines.SleepForRandomUiInteractionTime();

                    if (LuaCommands.OpenMailFrameIsVisible())
                    {
                        //Click the attachments..
                        for (int i = 0; i < inboxMailItem.ItemCount; i++)
                        {
                            LuaCommands.ClickOpenMailAttachmentButton(i + 1);
                            await CommonCoroutines.SleepForRandomUiInteractionTime();
                        }

                        //Close the open mail frame (if visible..)
                        if (LuaCommands.OpenMailFrameIsVisible())
                        {
                            LuaUI.InboxClose.Click();
                            await CommonCoroutines.SleepForRandomUiInteractionTime();
                        }
                    }

                    //LuaCommands.AutoLootMailItem(inboxMailItem.Index);
                    //await CommonCoroutines.SleepForRandomUiInteractionTime();
                }

                return(true);
            }

            return(false);
        }