Esempio n. 1
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (TrainerFrame.Instance == null || !TrainerFrame.Instance.IsVisible || !ObjectManager.Me.GotTarget ||
             (ObjectManager.Me.GotTarget && ObjectManager.Me.CurrentTarget.Entry != NpcEntry))
         {
             WoWPoint movetoPoint = _loc;
             WoWUnit  unit        = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == NpcEntry).
                                    OrderBy(o => o.Distance).FirstOrDefault();
             if (unit != null)
             {
                 movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, unit.Location, 3);
             }
             else if (movetoPoint == WoWPoint.Zero)
             {
                 movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NpcByID, NpcEntry);
             }
             if (movetoPoint != WoWPoint.Zero && ObjectManager.Me.Location.Distance(movetoPoint) > 4.5)
             {
                 Util.MoveTo(movetoPoint);
             }
             else if (unit != null)
             {
                 if (Me.IsMoving)
                 {
                     WoWMovement.MoveStop();
                 }
                 unit.Target();
                 unit.Interact();
             }
             if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible &&
                 GossipFrame.Instance.GossipOptionEntries != null)
             {
                 foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                 {
                     if (ge.Type == GossipEntry.GossipEntryType.Trainer)
                     {
                         GossipFrame.Instance.SelectGossipOption(ge.Index);
                         return(RunStatus.Success);
                     }
                 }
             }
             return(RunStatus.Success);
         }
         if (!_concludingStopWatch.IsRunning)
         {
             Lua.DoString("SetTrainerServiceTypeFilter('available', 1) BuyTrainerService(0) ");
             _concludingStopWatch.Start();
         }
         else if (_concludingStopWatch.ElapsedMilliseconds >= 3000)
         {
             _concludingStopWatch.Reset();
             Professionbuddy.Log("Training Completed ");
             IsDone = true;
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 2
0
 /// <summary>
 ///  Returns number items with a matching id that player has in personal bank
 /// </summary>
 /// <param name="itemID"></param>
 /// <returns></returns>
 public static int GetBankItemCount(uint itemID)
 {
     try
     {
         return((int)(ObjectManager.GetObjectsOfType <WoWItem>().
                      Sum(i => i != null && i.IsValid && i.Entry == itemID ? i.StackCount : 0) - GetCarriedItemCount(itemID)));
     }
     catch { return(0); }
 }
Esempio n. 3
0
 private WoWUnit GetUnitByWoWID(string unitID)
 {
     if (Lua.GetReturnValues("return UnitExists(\"{0}\")", unitID)[0].ToString() == "1")
     {
         string str = Lua.GetReturnVal <string>(
             String.Format("return UnitGUID(\"{0}\")", unitID),
             0).Replace("0x", "");
         return(ObjectManager.GetObjectByGuid <WoWUnit>(ulong.Parse(str, System.Globalization.NumberStyles.HexNumber)));
     }
     return(null);
 }
Esempio n. 4
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         WoWObject obj = null;
         if (InteractType == InteractActionType.NPC)
         {
             if (Entry != 0)
             {
                 obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.Entry == Entry).OrderBy(u => u.Distance).FirstOrDefault();
             }
             else if (ObjectManager.Me.GotTarget)
             {
                 obj = ObjectManager.Me.CurrentTarget;
             }
         }
         else if (InteractType == InteractActionType.GameObject)
         {
             obj = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(u => (Entry > 0 && u.Entry == Entry) || (u.SubType == GameObjectType &&
                                                                                                                   (GameObjectType != WoWGameObjectType.SpellFocus || (GameObjectType == WoWGameObjectType.SpellFocus && u.SpellFocus == SpellFocus))))
                   .OrderBy(u => u.Distance).FirstOrDefault();
         }
         if (obj != null)
         {
             if (!obj.WithinInteractRange)
             {
                 Util.MoveTo(WoWMathHelper.CalculatePointFrom(me.Location, obj.Location, 3));
             }
             else
             {
                 if (InteractDelay > 0 && (!interactSw.IsRunning || interactSw.ElapsedMilliseconds < InteractDelay))
                 {
                     interactSw.Start();
                 }
                 else
                 {
                     interactSw.Reset();
                     obj.Interact();
                     IsDone = true;
                 }
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Running);
         }
     }
     return(RunStatus.Failure);
 }
        void MovetoAuctioneer()
        {
            WoWPoint movetoPoint = _loc;
            WoWUnit  auctioneer;

            if (AutoFindAh || movetoPoint == WoWPoint.Zero)
            {
                auctioneer = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.IsAuctioneer && o.IsAlive)
                             .OrderBy(o => o.Distance).FirstOrDefault();
            }
            else
            {
                auctioneer = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.IsAuctioneer &&
                                                                              o.Location.Distance(_loc) < 5)
                             .OrderBy(o => o.Distance).FirstOrDefault();
            }
            if (auctioneer != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, auctioneer.Location, 3);
            }
            else if (movetoPoint == WoWPoint.Zero)
            {
                movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestAH, 0);
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                Logging.Write("Unable to location Auctioneer, Maybe he's dead?");
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
            {
                Util.MoveTo(movetoPoint);
            }
            else if (auctioneer != null)
            {
                auctioneer.Interact();
            }
        }
        static public WoWPoint GetLocationFromType(MoveToType type, uint entry)
        {
            WoWObject obj = null;

            if (entry != 0)
            {
                obj = ObjectManager.ObjectList.FirstOrDefault(o => o.Entry == entry);
            }
            if (obj == null)
            {
                switch (type)
                {
                case MoveToType.NearestAH:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsAuctioneer && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestBanker:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsBanker && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestFlight:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsFlightMaster && u.IsFriendly && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestGB:
                    obj = ObjectManager.ObjectList.Where(u => {
                        if (u is WoWUnit)
                        {
                            var un = (WoWUnit)u;
                            if (un.IsGuildBanker)
                            {
                                return(true);
                            }
                        }
                        else if (u is WoWGameObject)
                        {
                            var go = (WoWGameObject)u;
                            if (go.SubType == WoWGameObjectType.GuildBank)
                            {
                                return(true);
                            }
                        }
                        return(false);
                    }).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestMailbox:
                    obj = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(u => u.SubType == WoWGameObjectType.Mailbox).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestReagentVendor:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsReagentVendor && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestRepair:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsRepairMerchant && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;

                case MoveToType.NearestVendor:
                    obj = ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.IsAnyVendor && u.IsAlive).OrderBy(u => u.Distance).FirstOrDefault();
                    break;
                }
            }
            if (obj != null)
            {
                if (obj is WoWUnit && (!ObjectManager.Me.GotTarget || ObjectManager.Me.CurrentTarget != obj))
                {
                    ((WoWUnit)obj).Target();
                }
                return(obj.Location);
            }
            return(WoWPoint.Zero);
        }
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (MoveType != MoveToType.Location)
         {
             _loc = GetLocationFromType(MoveType, Entry);
             if (_loc == WoWPoint.Zero)
             {
                 if (_locationDb == WoWPoint.Zero)
                 {
                     _locationDb = GetLocationFromDB(MoveType, Entry);
                 }
                 _loc = _locationDb;
             }
             if (_loc == WoWPoint.Zero)
             {
                 Professionbuddy.Err("MoveToAction Failed.. Unable to find location from Database");
                 IsDone = true;
                 return(RunStatus.Failure);
             }
         }
         if (Entry > 0 && (!ObjectManager.Me.GotTarget || ObjectManager.Me.CurrentTarget.Entry != Entry))
         {
             WoWUnit unit = ObjectManager.GetObjectsOfType <WoWUnit>(true).FirstOrDefault(u => u.Entry == Entry);
             if (unit != null)
             {
                 unit.Target();
             }
         }
         float speed = ObjectManager.Me.MovementInfo.CurrentSpeed;
         Navigator.PathPrecision = speed > 7 ? (SpeedModifer * speed) / 7f : SpeedModifer;
         if (ObjectManager.Me.Location.Distance(_loc) > Navigator.PathPrecision)
         {
             if (Pathing == NavigationType.ClickToMove)
             {
                 WoWMovement.ClickToMove(_loc);
             }
             else
             {
                 Util.MoveTo(_loc);
             }
         }
         else
         {
             if (!_concludingSw.IsRunning)
             {
                 _concludingSw.Start();
             }
             else if (_concludingSw.ElapsedMilliseconds >= 2000)
             {
                 IsDone = true;
                 Professionbuddy.Log("MoveTo Action completed for type {0}", MoveType);
                 _concludingSw.Stop();
                 _concludingSw.Reset();
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 8
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         WoWPoint movetoPoint = loc;
         if (MailFrame.Instance == null || !MailFrame.Instance.IsVisible)
         {
             if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
             {
                 _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox)
                            .OrderBy(o => o.Distance).FirstOrDefault();
             }
             else
             {
                 _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox &&
                                                                                   o.Location.Distance(loc) < 10)
                            .OrderBy(o => o.Distance).FirstOrDefault();
             }
             if (_mailbox != null)
             {
                 movetoPoint = WoWMathHelper.CalculatePointFrom(me.Location, _mailbox.Location, 3);
             }
             if (movetoPoint == WoWPoint.Zero)
             {
                 return(RunStatus.Failure);
             }
             if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
             {
                 Util.MoveTo(movetoPoint);
             }
             else if (_mailbox != null)
             {
                 _mailbox.Interact();
             }
             return(RunStatus.Running);
         }
         else
         {
             List <WoWItem> ItemList = BuildItemList();
             if (ItemList == null || ItemList.Count == 0)
             {
                 IsDone = true;
                 return(RunStatus.Failure);
             }
             using (new FrameLock()) {
                 MailFrame.Instance.SwitchToSendMailTab();
                 foreach (WoWItem item in ItemList)
                 {
                     item.UseContainerItem();
                 }
                 Lua.DoString(string.Format("SendMail ('{0}',' ','');SendMailMailButton:Click();", CharacterSettings.Instance.MailRecipient.ToFormatedUTF8()));
             }
             if (IsDone)
             {
                 Professionbuddy.Log("Done sending {0} via mail",
                                     UseCategory ? string.Format("Items that belong to category {0} and subcategory {1}", Category, SubCategory) :
                                     string.Format("Items that match Id of {0}", ItemID));
             }
             else
             {
                 return(RunStatus.Running);
             }
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 9
0
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
                {
                    WoWPoint movetoPoint = loc;
                    WoWUnit  unit        = null;
                    if (_entry == 0)
                    {
                        _entry = NpcEntry;
                    }
                    if (_entry == 0)
                    {
                        MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestVendor, 0);
                        var npcResults = NpcQueries.GetNearestNpc(ObjectManager.Me.FactionTemplate, ObjectManager.Me.MapId,
                                                                  ObjectManager.Me.Location, UnitNPCFlags.Vendor);
                        _entry      = (uint)npcResults.Entry;
                        movetoPoint = npcResults.Location;
                    }
                    unit = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == _entry).
                           OrderBy(o => o.Distance).FirstOrDefault();
                    if (unit != null)
                    {
                        movetoPoint = unit.Location;
                    }
                    else if (movetoPoint == WoWPoint.Zero)
                    {
                        movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NpcByID, NpcEntry);
                    }
                    if (movetoPoint != WoWPoint.Zero && ObjectManager.Me.Location.Distance(movetoPoint) > 4.5)
                    {
                        Util.MoveTo(movetoPoint);
                    }
                    else if (unit != null)
                    {
                        unit.Target();
                        unit.Interact();
                    }

                    if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible &&
                        GossipFrame.Instance.GossipOptionEntries != null)
                    {
                        foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                        {
                            if (ge.Type == GossipEntry.GossipEntryType.Vendor)
                            {
                                GossipFrame.Instance.SelectGossipOption(ge.Index);
                                return(RunStatus.Running);
                            }
                        }
                    }
                }
                else
                {
                    if (SellItemType == SellItemActionType.Specific)
                    {
                        List <uint> idList  = new List <uint>();
                        string[]    entries = ItemID.Split(',');
                        if (entries != null && entries.Length > 0)
                        {
                            foreach (var entry in entries)
                            {
                                uint temp = 0;
                                uint.TryParse(entry.Trim(), out temp);
                                idList.Add(temp);
                            }
                        }
                        else
                        {
                            Professionbuddy.Err("No ItemIDs are specified");
                            IsDone = true;
                            return(RunStatus.Failure);
                        }
                        List <WoWItem> itemList = ObjectManager.Me.BagItems.Where(u => idList.Contains(u.Entry)).Take((int)Count).ToList();
                        if (itemList != null)
                        {
                            using (new FrameLock()) {
                                foreach (WoWItem item in itemList)
                                {
                                    item.UseContainerItem();
                                }
                            }
                        }
                    }
                    else
                    {
                        List <WoWItem>        itemList  = null;
                        IEnumerable <WoWItem> itemQuery = from item in me.BagItems
                                                          where !Pb.ProtectedItems.Contains(item.Entry)
                                                          select item;
                        switch (SellItemType)
                        {
                        case SellItemActionType.Greys:
                            itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Poor).ToList();
                            break;

                        case SellItemActionType.Whites:
                            itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Common).ToList();
                            break;

                        case SellItemActionType.Greens:
                            itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Uncommon).ToList();
                            break;
                        }
                        if (itemList != null)
                        {
                            using (new FrameLock()) {
                                foreach (WoWItem item in itemList)
                                {
                                    item.UseContainerItem();
                                }
                            }
                        }
                    }
                    Professionbuddy.Log("SellItemAction Completed for {0}", ItemID);
                    IsDone = true;
                }
                return(RunStatus.Running);
            }
            return(RunStatus.Failure);
        }
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                if (!TimeoutSW.IsRunning)
                {
                    TimeoutSW.Start();
                }
                if (TimeoutSW.ElapsedMilliseconds > 300000)
                {
                    IsDone = true;
                }
                WoWPoint movetoPoint = loc;
                if (MailFrame.Instance == null || !MailFrame.Instance.IsVisible)
                {
                    if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
                    {
                        mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox)
                                  .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    else
                    {
                        mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox &&
                                                                                         o.Location.Distance(loc) < 10)
                                  .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    if (mailbox != null)
                    {
                        movetoPoint = WoWMathHelper.CalculatePointFrom(me.Location, mailbox.Location, 3);
                    }
                    if (movetoPoint == WoWPoint.Zero)
                    {
                        return(RunStatus.Failure);
                    }
                    if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
                    {
                        Util.MoveTo(movetoPoint);
                    }
                    else if (mailbox != null)
                    {
                        mailbox.Interact();
                    }
                    return(RunStatus.Running);
                }
                else
                {
                    if (_idList == null)
                    {
                        _idList = BuildItemList();
                    }
                    if (!_refreshInboxSW.IsRunning)
                    {
                        _refreshInboxSW.Start();
                    }
                    if (!WaitForContentToShowSW.IsRunning)
                    {
                        WaitForContentToShowSW.Start();
                    }
                    if (WaitForContentToShowSW.ElapsedMilliseconds < 3000)
                    {
                        return(RunStatus.Running);
                    }
                    uint freeslots = ObjectManager.Me.FreeNormalBagSlots;

                    if (!ConcludingSW.IsRunning)
                    {
                        if (_refreshInboxSW.ElapsedMilliseconds < 61000)
                        {
                            if (GetMailType == GetMailActionType.AllItems)
                            {
                                string lua = string.Format("local totalItems,numItems = GetInboxNumItems() local foundMail=0 for index=1,numItems do local _,_,sender,subj,gold,cod,_,itemCnt,_,_,hasText=GetInboxHeaderInfo(index) if sender ~= nil and cod == 0 and itemCnt == nil and gold == 0 and hasText == nil then DeleteInboxItem(index) end if cod == 0 and ((itemCnt and itemCnt >0) or (gold and gold > 0)) then AutoLootMailItem(index) foundMail = foundMail + 1 break end end local beans = BeanCounterMail and BeanCounterMail:IsVisible() if foundMail == 0 {0}and totalItems == numItems and beans ~= 1 then return 1 else return 0 end ",
                                                           CheckNewMail ? "and HasNewMail() == nil " : "");
                                //freeslots / 2 >= MinFreeBagSlots ? (freeslots - MinFreeBagSlots) / 2 : 1);
                                if (Lua.GetReturnValues(lua)[0] == "1" || ObjectManager.Me.FreeNormalBagSlots <= MinFreeBagSlots)
                                {
                                    ConcludingSW.Start();
                                }
                            }
                            else
                            {
                                for (int i = 0; i < _idList.Count; i++)
                                {
                                    string lua = string.Format("local totalItems,numItems = GetInboxNumItems() local foundMail=0 for index=1,numItems do local _,_,sender,subj,gold,cod,_,itemCnt,_,_,hasText=GetInboxHeaderInfo(index) if sender ~= nil and cod == 0 and itemCnt == nil and gold == 0 and hasText == nil then DeleteInboxItem(index) end if cod == 0 and itemCnt and itemCnt >0  then for i2=1, ATTACHMENTS_MAX_RECEIVE do local itemlink = GetInboxItemLink(index, i2) if itemlink ~= nil and string.find(itemlink,'{0}') then foundMail = foundMail + 1 TakeInboxItem(index, i2) break end end end end if (foundMail == 0 {1})  or (foundMail == 0 and (numItems == 50 and totalItems >= 50)) then return 1 else return 0 end ",
                                                               //, Entry, freeslots / 2 >= MinFreeBagSlots ? (freeslots - MinFreeBagSlots) / 2 : 1);
                                                               _idList[i], CheckNewMail ? "and HasNewMail() == nil " : "");

                                    if (Lua.GetReturnValues(lua)[0] == "1" || ObjectManager.Me.FreeNormalBagSlots <= MinFreeBagSlots)
                                    {
                                        _idList.RemoveAt(i);
                                    }
                                }
                                if (_idList.Count == 0)
                                {
                                    ConcludingSW.Start();
                                }
                            }
                        }
                        else
                        {
                            _refreshInboxSW.Reset();
                            MailFrame.Instance.Close();
                        }
                    }
                    if (ConcludingSW.ElapsedMilliseconds > 2000)
                    {
                        IsDone = true;
                    }
                    if (IsDone)
                    {
                        Professionbuddy.Log("Mail retrieval of items:{0} finished", GetMailType);
                    }
                    else
                    {
                        return(RunStatus.Running);
                    }
                }
            }
            return(RunStatus.Failure);
        }
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                WoWPoint movetoPoint = _loc;
                if (MailFrame.Instance == null || !MailFrame.Instance.IsVisible)
                {
                    if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
                    {
                        _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox)
                                   .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    else
                    {
                        _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox &&
                                                                                          o.Location.Distance(_loc) < 10)
                                   .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    if (_mailbox != null)
                    {
                        movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, _mailbox.Location, 3);
                    }
                    if (movetoPoint == WoWPoint.Zero)
                    {
                        Professionbuddy.Err("Unable To find Mailbox");
                        IsDone = true;
                        return(RunStatus.Failure);
                    }
                    if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
                    {
                        Util.MoveTo(movetoPoint);
                    }
                    else if (_mailbox != null)
                    {
                        _mailbox.Interact();
                    }
                    return(RunStatus.Success);
                }
                // Mail Frame is open..
                // item split in proceess
                if (_itemSplitSW.IsRunning && _itemSplitSW.ElapsedMilliseconds <= 2000)
                {
                    return(RunStatus.Success);
                }
                if (_itemList == null)
                {
                    _itemList = BuildItemList();
                }
                if (_itemList.Count == 0)
                {
                    //Professionbuddy.Debug("Sending any remaining items already in SendMail item slots. Mail subject will be: {0} ",_mailSubject);
                    Lua.DoString("for i=1,ATTACHMENTS_MAX_SEND do if GetSendMailItem(i) ~= nil then SendMail (\"{0}\",\"{1}\",'') end end ",
                                 CharacterSettings.Instance.MailRecipient.ToFormatedUTF8(), _mailSubject != null?_mailSubject.ToFormatedUTF8(): " ");
                    //Professionbuddy.Debug("Done sending mail");
                    IsDone = true;
                    return(RunStatus.Failure);
                }

                MailFrame.Instance.SwitchToSendMailTab();
                uint    itemID = _itemList.Keys.FirstOrDefault();
                WoWItem item   = Me.BagItems.FirstOrDefault(i => i.Entry == itemID);
                _mailSubject = item != null ? item.Name : " ";
                if (string.IsNullOrEmpty(_mailSubject))
                {
                    _mailSubject = " ";
                }
                Professionbuddy.Debug("MailItem: sending {0}", itemID);
                int ret = MailItem(itemID, _itemList[itemID]);
                // we need to wait for item split to finish if ret == 0
                // format indexs are MailRecipient=0, Mail subject=1
                string mailToLua    = string.Format(MailItemsFormat, CharacterSettings.Instance.MailRecipient.ToFormatedUTF8(), _mailSubject.ToFormatedUTF8());
                var    mailItemsRet = Lua.GetReturnVal <int>(mailToLua, 0);
                if (ret == 0 || mailItemsRet == 1)
                {
                    _itemSplitSW.Reset();
                    _itemSplitSW.Start();
                    return(RunStatus.Success);
                }
                _itemList[itemID] = ret == -1 ? 0 : _itemList[itemID] - ret;

                bool done = _itemList[itemID] <= 0;
                if (done)
                {
                    _itemList.Remove(itemID);
                }
                if (IsDone)
                {
                    Professionbuddy.Log("Done sending {0} via mail",
                                        UseCategory ? string.Format("Items that belong to category {0} and subcategory {1}", Category, SubCategory) :
                                        string.Format("Items that match Id of {0}", ItemID));
                }
                else
                {
                    return(RunStatus.Success);
                }
            }
            return(RunStatus.Failure);
        }
Esempio n. 12
0
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                if (!_timeoutSW.IsRunning)
                {
                    _timeoutSW.Start();
                }
                if (_timeoutSW.ElapsedMilliseconds > 300000)
                {
                    IsDone = true;
                }
                WoWPoint movetoPoint = _loc;
                if (MailFrame.Instance == null || !MailFrame.Instance.IsVisible)
                {
                    if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
                    {
                        _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox)
                                   .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    else
                    {
                        _mailbox = ObjectManager.GetObjectsOfType <WoWGameObject>().Where(o => o.SubType == WoWGameObjectType.Mailbox &&
                                                                                          o.Location.Distance(_loc) < 10)
                                   .OrderBy(o => o.Distance).FirstOrDefault();
                    }
                    if (_mailbox != null)
                    {
                        movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, _mailbox.Location, 3);
                    }
                    if (movetoPoint == WoWPoint.Zero)
                    {
                        return(RunStatus.Failure);
                    }
                    if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
                    {
                        Util.MoveTo(movetoPoint);
                    }
                    else if (_mailbox != null)
                    {
                        _mailbox.Interact();
                    }
                    return(RunStatus.Success);
                }
                // mail frame is open.
                if (_idList == null)
                {
                    _idList = BuildItemList();
                }
                if (!_refreshInboxSW.IsRunning)
                {
                    _refreshInboxSW.Start();
                }
                if (!_waitForContentToShowSW.IsRunning)
                {
                    _waitForContentToShowSW.Start();
                }
                if (_waitForContentToShowSW.ElapsedMilliseconds < 3000)
                {
                    return(RunStatus.Success);
                }

                if (!_concludingSW.IsRunning)
                {
                    if (_refreshInboxSW.ElapsedMilliseconds < 64000)
                    {
                        if (MinFreeBagSlots > 0 && Me.FreeNormalBagSlots - MinFreeBagSlots <= 4)
                        {
                            if (!_throttleSW.IsRunning)
                            {
                                _throttleSW.Start();
                            }
                            if (_throttleSW.ElapsedMilliseconds < 4000 - (Me.FreeNormalBagSlots - MinFreeBagSlots) * 1000)
                            {
                                return(RunStatus.Success);
                            }
                            _throttleSW.Reset();
                            _throttleSW.Start();
                        }
                        if (GetMailType == GetMailActionType.AllItems)
                        {
                            string lua = string.Format(MailFormat, CheckNewMail ? 1 : 0);
                            if (Me.FreeNormalBagSlots <= MinFreeBagSlots || Lua.GetReturnValues(lua)[0] == "1")
                            {
                                _concludingSW.Start();
                            }
                        }
                        else
                        {
                            if (_idList.Count > 0 && Me.FreeNormalBagSlots > MinFreeBagSlots)
                            {
                                string lua = string.Format(MailByIdFormat, _idList[0], CheckNewMail ? 1 : 0);

                                if (Lua.GetReturnValues(lua)[0] == "1")
                                {
                                    _idList.RemoveAt(0);
                                }
                            }
                            else
                            {
                                _concludingSW.Start();
                            }
                        }
                    }
                    else
                    {
                        _refreshInboxSW.Reset();
                        MailFrame.Instance.Close();
                    }
                }
                if (_concludingSW.ElapsedMilliseconds > 2000)
                {
                    IsDone = true;
                }
                if (IsDone)
                {
                    Professionbuddy.Log("Mail retrieval of items:{0} finished", GetMailType);
                }
                else
                {
                    return(RunStatus.Success);
                }
            }
            return(RunStatus.Failure);
        }