internal static void ResetMailing()
 {
     _mailingMovement     = null;
     IsMailing            = false;
     _mailobject          = null;
     _mailingSetRecipient = false;
 }
        private static async Task <bool> VendorInteraction(C_WoWObject vendor, List <C_WoWItem> items)
        {
            TreeRoot.StatusText = "Vendor Interaction Behavior";

            if (GossipHelper.IsOpen)
            {
                await Coroutine.Yield();

                if (GossipHelper.GossipOptions.All(o => o.Type != GossipEntry.GossipEntryType.Vendor))
                {
                    //Could not find Vendor Option!
                    GarrisonBase.Debug("Vendor Gossip Has No Option for Vendoring!");
                    return(false);
                }
                var gossipEntryVendor = GossipHelper.GossipOptions.FirstOrDefault(o => o.Type == GossipEntry.GossipEntryType.Vendor);

                QuestManager.GossipFrame.SelectGossipOption(gossipEntryVendor.Index);
                await CommonCoroutines.SleepForRandomUiInteractionTime();

                return(true);
            }

            if (MerchantHelper.IsOpen)
            {
                if (items.Count > 0)
                {
                    foreach (var item in items)
                    {
                        GarrisonBase.Debug("Vendoring Item {0} ({1}) Quality {2}", item.Name, item.Entry, item.Quality);
                        MerchantFrame.Instance.SellItem(item.ref_WoWItem);
                        await CommonCoroutines.SleepForRandomUiInteractionTime();

                        await Coroutine.Yield();

                        if (!MerchantHelper.IsOpen)
                        {
                            break;
                        }
                    }

                    return(true);
                }

                //No vendor items found..
                return(false);
            }

            if (StyxWoW.Me.IsMoving)
            {
                await CommonCoroutines.StopMoving();
            }
            await CommonCoroutines.SleepForLagDuration();

            vendor.Interact();
            await CommonCoroutines.SleepForRandomUiInteractionTime();

            return(true);
        }
        private static async Task <bool> MailboxInteraction(C_WoWObject mailbox, Dictionary <string, List <C_WoWItem> > items)
        {
            if (MailHelper.IsOpen)
            {
                //Click Send Mail Tab
                if (!LuaCommands.IsSendMailFrameVisible())
                {
                    LuaCommands.ClickSendMailTab();
                    await CommonCoroutines.SleepForRandomUiInteractionTime();

                    return(true);
                }

                foreach (var keypair in items)
                {
                    GarrisonBase.Log("Found {0} items to mail", keypair.Value.Count);
                    bool success = await SendMail(keypair.Key, keypair.Value);

                    if (!success)
                    {
                        GarrisonBase.Debug("Sending Mail Failed!");
                        return(false);
                    }
                    await Coroutine.Yield();

                    return(true);
                }
            }


            if (StyxWoW.Me.IsMoving)
            {
                await CommonCoroutines.StopMoving();
            }
            await CommonCoroutines.SleepForLagDuration();

            mailbox.Interact();
            await CommonCoroutines.SleepForRandomUiInteractionTime();

            return(true);
        }
        public override async Task <bool> BehaviorRoutine()
        {
            if (await base.BehaviorRoutine())
            {
                return(true);
            }
            if (IsDone)
            {
                return(false);
            }

            if (GossipHelper.IsOpen)
            {
                if (GossipHelper.GossipOptions.Count == 0)
                {
                    _failedToFindGossipEntries++;
                    if (_failedToFindGossipEntries > 3)
                    {
                        GarrisonBase.Err("Could not find any valid gossip entries!");
                        GossipFrame.Instance.Close();
                        IsDone = true;
                        return(false);
                    }

                    await Coroutine.Yield();

                    return(true);
                }

                GossipHelper.GossipOptionEntry gossipEntry = null;
                if (_gossipIndex > -1)
                {
                    gossipEntry = GossipHelper.GossipOptions[_gossipIndex];
                }
                else if (!string.IsNullOrEmpty(_gossipText))
                {
                    gossipEntry = GossipHelper.GossipOptions.FirstOrDefault(g => g.Text.ToLower().Contains(_gossipText));
                }

                if (gossipEntry == null)
                {
                    GarrisonBase.Err("Could not find any valid gossip entries index [{0}] text [{1}]", _gossipIndex, _gossipText);
                    GossipFrame.Instance.Close();
                    IsDone = true;
                    return(false);
                }

                GarrisonBase.Debug("Selecting Gossip Option {0}", gossipEntry.Index);
                var success = await CommonCoroutines.WaitForLuaEvent("GOSSIP_SHOW", 2500, null,
                                                                     () => GossipFrame.Instance.SelectGossipOption(gossipEntry.Index));


                GarrisonBase.Debug("Gossip Selection success = {0}", success);

                await CommonCoroutines.SleepForRandomUiInteractionTime();

                if (!success)
                {
                    return(false);
                }

                if (_oneTime)
                {
                    IsDone = true;
                }
                return(!_oneTime);
            }
            C_WoWObject validobj = NpcObject != null ? NpcObject:
                                   InteractionObject != null?InteractionObject:null;

            if (validobj == null || !validobj.IsValid)
            {
                GarrisonBase.Err("Could not find object {0} to interact with!", _npcId);
                IsDone = true;
                return(false);
            }
            if (_npcMovement == null)
            {
                _npcMovement = new Movement(validobj.Location, _interactDistance, name: "GossipInteract");
            }

            if (await _npcMovement.MoveTo(false))
            {
                return(true);
            }

            if (validobj.CheckDistance(_interactDistance))
            {
                if (StyxWoW.Me.IsMoving)
                {
                    await CommonCoroutines.StopMoving();
                }
                await CommonCoroutines.SleepForLagDuration();

                if (GossipHelper.IsOpen)
                {
                    //frame is displayed!
                    return(true);
                }

                validobj.Interact();
                await CommonCoroutines.SleepForRandomUiInteractionTime();

                return(true);
            }

            return(true);
        }
        internal static async Task <bool> Mailing()
        {
            if (IsMailing)
            {
                var items = GetMailItems;
                if (items.Count == 0)
                {
                    if (await Common.CloseFrames())
                    {
                        return(true);
                    }
                    ResetMailing();
                    return(true);
                }

                if (_mailobject == null)
                {
                    var mailboxes = GetMailBoxes;
                    if (mailboxes.Count > 0)
                    {
                        _mailobject = mailboxes[0];
                        GarrisonBase.Debug("Mail Behavior found mailbox object at {0}", _mailobject.Location);
                    }
                }

                if (_mailingMovement == null || _mailingMovement.CurrentMovementQueue.Count == 0)
                {
                    if (_mailobject == null)
                    {
                        var mailboxWoWPoint = MovementCache.GarrisonEntrance;
                        if (mailboxWoWPoint == WoWPoint.Zero)
                        {
                            mailboxWoWPoint = StyxWoW.Me.IsAlliance
                                ? MovementCache.AllianceGarrisonEntrance
                                : MovementCache.HordeGarrisonEntrance;
                        }

                        _mailingMovement = new Movement(new[] { mailboxWoWPoint }, 20f, "Garrison Entrance");
                    }
                    else
                    {
                        _mailingMovement = new Movement(_mailobject, _mailobject.InteractRange - 0.25f, "Mailbox Movement");
                    }
                }


                if (_mailobject != null)
                {
                    if (_mailobject.WithinInteractRange)
                    {
                        bool mailing = await MailboxInteraction(_mailobject, items);

                        if (!mailing)
                        {
                            ResetMailing();
                            return(true);
                        }

                        return(true);
                    }
                }

                if (_mailingMovement != null)
                {
                    bool movement = await MailMovement();

                    if (!movement)
                    {
                        //Failed to move?
                        GarrisonBase.Debug("Failed to move to mailbox location!");
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
Beispiel #6
0
 public Movement(C_WoWObject obj, float distance, string name = "", bool checkStuck = false)
     : this(new[] { obj.Location }, distance, name, checkStuck)
 {
     WoWObject = obj;
 }
        internal static async Task <bool> Vendoring()
        {
            if (IsVendoring)
            {
                var items = GetVendorItems;
                if (items.Count == 0)
                {
                    if (await Common.CloseFrames())
                    {
                        return(true);
                    }
                    ResetVendoring();
                    return(true);
                }

                if (_vendorobject == null)
                {
                    var vendors = GetVendors;
                    if (vendors.Count > 0)
                    {
                        _vendorobject = vendors[0];
                        GarrisonBase.Debug("Vendor Behavior Using {0} as Vendor Npc!", _vendorobject.Name);
                    }
                }


                if (_vendorMovement == null || _vendorMovement.CurrentMovementQueue.Count == 0)
                {
                    //Check for any vendors in cache..
                    //  -If none than goto safety inside garrison.
                    if (_vendorobject == null)
                    {
                        var vendorWoWPoint = MovementCache.SellRepairNpcLocation;
                        if (vendorWoWPoint == WoWPoint.Zero)
                        {
                            vendorWoWPoint = StyxWoW.Me.IsAlliance
                                ? MovementCache.AllianceSellRepairNpc
                                : MovementCache.HordeSellRepairNpc;
                        }

                        _vendorMovement = new Movement(new[] { vendorWoWPoint }, 20f, "Garrison Vendor");
                    }
                    else
                    {
                        _vendorMovement = new Movement(_vendorobject, _vendorobject.InteractRange - 0.25f, "Vendor Movement");
                    }
                }

                if (_vendorobject != null)
                {
                    if (_vendorobject.WithinInteractRange)
                    {
                        //Do Vendoring..
                        bool vendoring = await VendorInteraction(_vendorobject, items);

                        if (!vendoring)
                        {
                            ResetVendoring();
                            return(true);
                        }

                        return(true);
                    }
                }

                if (_vendorMovement != null)
                {
                    bool movement = await VendorMovement();

                    if (!movement)
                    {
                        //Failed to move?
                        GarrisonBase.Debug("Failed to move to vendor location!");
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
 internal static void ResetVendoring()
 {
     _vendorobject   = null;
     IsVendoring     = false;
     _vendorMovement = null;
 }