Esempio n. 1
0
        private List <AuctionEntry> BuildScanItemList()
        {
            var tmpItemlist = new List <AuctionEntry>();
            Dictionary <uint, string> myAucs = GetMyAuctions();

            if (UseCategory)
            {
                using (new FrameLock())
                {
                    foreach (var aucKV in myAucs)
                    {
                        ItemInfo info = ItemInfo.FromId(aucKV.Key);
                        if (info != null)
                        {
                            if (info.ItemClass == Category && SubCategoryCheck(info.SubClassId))
                            {
                                tmpItemlist.Add(new AuctionEntry(aucKV.Value, aucKV.Key, 0, 0));
                            }
                        }
                        else
                        {
                            Professionbuddy.Err("item cache of {0} is null", aucKV.Value);
                        }
                    }
                }
            }
            else
            {
                if (ItemID == "0" || ItemID == "")
                {
                    tmpItemlist.AddRange(myAucs.Select(kv => new AuctionEntry(kv.Value, kv.Key, 0, 0)));
                }
                else
                {
                    string[] entries = ItemID.Split(',');
                    if (entries.Length > 0)
                    {
                        foreach (string entry in entries)
                        {
                            uint id;
                            uint.TryParse(entry.Trim(), out id);
                            if (myAucs.ContainsKey(id))
                            {
                                tmpItemlist.Add(new AuctionEntry(myAucs[id], id, 0, 0));
                            }
                        }
                    }
                }
            }
            return(tmpItemlist);
        }
Esempio n. 2
0
 protected virtual bool CanRun(object context)
 {
     try
     {
         return(CanRunDelegate(context));
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             Professionbuddy.Err("If Condition: {0} ,Err:{1}", Condition, ex);
         }
         return(false);
     }
 }
Esempio n. 3
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (_sub == null)
         {
             if (!GetSubRoutine())
             {
                 Professionbuddy.Err("{0}: {1}.", Pb.Strings["Error_SubroutineNotFound"], SubRoutineName);
                 IsDone = true;
             }
         }
         if (!_ranonce)
         {
             // make sure all actions within the subroutine are reset before we start.
             if (_sub != null)
             {
                 _sub.Reset();
             }
             _ranonce = true;
         }
         if (_sub != null)
         {
             if (!_sub.IsRunning)
             {
                 _sub.Start(SubRoutineName);
             }
             try
             {
                 _sub.Tick(SubRoutineName);
             }
             catch (ThreadAbortException)
             {
                 return(RunStatus.Success);
             }
             catch
             {
             }
             IsDone = _sub.IsDone;
             // we need to reset so calls to the sub from other places can
             if (!IsDone)
             {
                 return(RunStatus.Success);
             }
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 4
0
 protected virtual bool CanRun(object context)
 {
     try
     {
         return(CanRunDelegate(context));
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             Professionbuddy.Err("{0}: {1}\nErr:{2}", Professionbuddy.Instance.Strings["FlowControl_If_LongName"],
                                 Condition, ex);
         }
         return(false);
     }
 }
Esempio n. 5
0
        private List <AuctionEntry> BuildScanItemList()
        {
            var            tmpItemlist = new List <AuctionEntry>();
            List <WoWItem> itemList;

            if (UseCategory)
            {
                itemList = ObjectManager.Me.BagItems.
                           Where(i => !i.IsSoulbound && !i.IsConjured && !i.IsDisabled &&
                                 !Pb.ProtectedItems.Contains(i.Entry) &&
                                 i.ItemInfo.ItemClass == Category && SubCategoryCheck(i)).ToList();
                foreach (WoWItem item in itemList)
                {
                    if (!_containsItem(item, tmpItemlist))
                    {
                        tmpItemlist.Add(new AuctionEntry(item.Name, item.Entry, 0, 0));
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint id;
                        uint.TryParse(entry.Trim(), out id);
                        itemList =
                            ObjectManager.Me.BagItems.Where(i => !i.IsSoulbound && !i.IsConjured && i.Entry == id).
                            ToList();
                        if (itemList.Count > 0)
                        {
                            tmpItemlist.Add(new AuctionEntry(itemList[0].Name, itemList[0].Entry, 0, 0));
                        }
                    }
                }
                else
                {
                    Professionbuddy.Err(Pb.Strings["Error_NoItemEntries"]);
                    IsDone = true;
                }
            }
            return(tmpItemlist);
        }
        Dictionary <uint, int> BuildItemList()
        {
            Dictionary <uint, int> itemList    = new Dictionary <uint, int>();
            IEnumerable <WoWItem>  tmpItemlist = from item in me.BagItems
                                                 where !item.IsConjured && !item.IsSoulbound && !item.IsDisabled
                                                 select item;

            if (UseCategory)
            {
                foreach (WoWItem item in tmpItemlist)
                {
                    if (!Pb.ProtectedItems.Contains(item.Entry) && item.ItemInfo.ItemClass == Category &&
                        subCategoryCheck(item) && !itemList.ContainsKey(item.Entry))
                    {
                        itemList.Add(item.Entry, Amount);
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries != null && entries.Length > 0)
                {
                    foreach (var entry in entries)
                    {
                        uint temp = 0;
                        uint.TryParse(entry.Trim(), out temp);
                        itemList.Add(temp, Amount);
                    }
                }
                else
                {
                    Professionbuddy.Err("No ItemIDs are specified");
                    IsDone = true;
                }
            }
            Professionbuddy.Debug("List of items to deposit to bank");
            foreach (var item in itemList)
            {
                Professionbuddy.Debug("Item:{0} Amount:{1}", item.Key, item.Value);
            }
            Professionbuddy.Debug("End of list");
            return(itemList);
        }
Esempio n. 7
0
        private Dictionary <uint, int> BuildItemList()
        {
            var itemList = new Dictionary <uint, int>();
            IEnumerable <WoWItem> tmpItemlist = from item in Me.BagItems
                                                where !item.IsConjured && !item.IsSoulbound && !item.IsDisabled
                                                select item;

            if (UseCategory)
            {
                foreach (WoWItem item in tmpItemlist)
                {
                    if (!Pb.ProtectedItems.Contains(item.Entry) && item.ItemInfo.ItemClass == Category &&
                        SubCategoryCheck(item) && !itemList.ContainsKey(item.Entry))
                    {
                        itemList.Add(item.Entry, Mail == DepositWithdrawAmount.Amount
                                                     ? Amount
                                                     : Util.GetCarriedItemCount(item.Entry));
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint itemID;
                        uint.TryParse(entry.Trim(), out itemID);
                        itemList.Add(itemID, Mail == DepositWithdrawAmount.Amount
                                                 ? Amount
                                                 : Util.GetCarriedItemCount(itemID));
                    }
                }
                else
                {
                    Professionbuddy.Err("No ItemIDs are specified");
                    IsDone = true;
                }
            }
            return(itemList);
        }
        void MoveToBanker()
        {
            WoWPoint  movetoPoint = loc;
            WoWObject bank        = GetLocalBanker();

            if (bank != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(me.Location, bank.Location, 3);
            }
            // search the database
            else if (movetoPoint == WoWPoint.Zero)
            {
                if (Bank == BankType.Personal)
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestBanker, NpcEntry);
                }
                else
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestGB, NpcEntry);
                }
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                IsDone = true;
                Professionbuddy.Err("Unable to find bank");
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4)
            {
                Util.MoveTo(movetoPoint);
            }
            // since there are many personal bank replacement addons I can't just check if frame is open and be generic.. using events isn't reliable
            else if (bank != null)
            {
                bank.Interact();
            }
            else
            {
                IsDone = true;
                Logging.Write(System.Drawing.Color.Red, "Unable to find a banker at location. aborting");
            }
        }
Esempio n. 9
0
        private List <uint> BuildItemList()
        {
            var list = new List <uint>();

            string[] entries = ItemID.Split(',');
            if (entries.Length > 0)
            {
                foreach (string entry in entries)
                {
                    uint temp;
                    uint.TryParse(entry.Trim(), out temp);
                    list.Add(temp);
                }
            }
            else
            {
                Professionbuddy.Err(Pb.Strings["Error_NoItemEntries"]);
                IsDone = true;
            }
            return(list);
        }
        List <uint> BuildItemList()
        {
            List <uint> list = 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);
                    list.Add(temp);
                }
            }
            else
            {
                Professionbuddy.Err("No ItemIDs are specified");
                IsDone = true;
            }
            return(list);
        }
Esempio n. 11
0
 protected override RunStatus Run(object context)
 {
     try
     {
         if (!IsDone)
         {
             try
             {
                 Action(this);
             }
             catch (Exception ex)
             {
                 Professionbuddy.Err("Custom:({0})\n{1}", Code, ex);
             }
             IsDone = true;
         }
         return(RunStatus.Failure);
     }
     catch (Exception ex) { Logging.Write(System.Drawing.Color.Red, "There was an exception while executing a CustomAction\n{0}", ex); }
     return(RunStatus.Failure);
 }
Esempio n. 12
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (_sub == null)
         {
             if (!GetSubRoutine())
             {
                 Professionbuddy.Err("Unable to find Subroutine with name: {0}.", SubRoutineName);
                 IsDone = true;
             }
         }
         if (!ranonce)
         {
             // make sure all actions within the subroutine are reset before we start.
             _sub.Reset();
             ranonce = true;
         }
         if (_sub != null)
         {
             if (!_sub.IsRunning)
             {
                 _sub.Start(SubRoutineName);
             }
             try
             {
                 _sub.Tick(SubRoutineName);
             }
             catch { IsDone = true; _sub.Reset(); return(RunStatus.Failure); }
             IsDone = _sub.IsDone;
             // we need to reset so calls to the sub from other places can
             if (!IsDone)
             {
                 return(RunStatus.Running);
             }
         }
     }
     return(RunStatus.Failure);
 }
        static public void ChangeBot(string name)
        {
            if (_botIsChanging)
            {
                Professionbuddy.Log("Must wait for previous ChangeBot to finish before calling ChangeBot again.");
                return;
            }
            BotBase bot = BotManager.Instance.Bots.FirstOrDefault(b => b.Key.Contains(name)).Value;

            if (BotManager.Current == bot)
            {
                return;
            }
            if (bot != null)
            {
                // execute from GUI thread since this thread will get aborted when switching bot
                _botIsChanging = true;
                Application.Current.Dispatcher.BeginInvoke(
                    new System.Action(() => {
                    bool isRunning = TreeRoot.IsRunning;
                    BotManager.Instance.SetCurrent(bot);
                    if (isRunning)
                    {
                        Professionbuddy.Log("Restarting HB in 3 seconds");
                        _timer = new Timer(new TimerCallback((o) => {
                            TreeRoot.Start();
                            Professionbuddy.Log("Restarting HB");
                            _botIsChanging = false;
                        }), null, 3000, Timeout.Infinite);
                    }
                }
                                      ));
                Professionbuddy.Log("Changing bot to {0}", name);
            }
            else
            {
                Professionbuddy.Err("Bot {0} does not exist", name);
            }
        }
Esempio n. 14
0
        private void MoveToBanker()
        {
            WoWPoint  movetoPoint = _loc;
            WoWObject bank        = GetLocalBanker();

            if (bank != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, bank.Location, 3);
            }
            // search the database
            else if (movetoPoint == WoWPoint.Zero)
            {
                movetoPoint =
                    MoveToAction.GetLocationFromDB(
                        Bank == BankType.Personal
                            ? MoveToAction.MoveToType.NearestBanker
                            : MoveToAction.MoveToType.NearestGB, NpcEntry);
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                IsDone = true;
                Professionbuddy.Err(Pb.Strings["Error_UnableToFindBank"]);
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4)
            {
                Util.MoveTo(movetoPoint);
            }
            // since there are many personal bank replacement addons I can't just check if frame is open and be generic.. using events isn't reliable
            else if (bank != null)
            {
                bank.Interact();
            }
            else
            {
                IsDone = true;
                Professionbuddy.Err(Pb.Strings["Error_UnableToFindBank"]);
            }
        }
        void MoveToAh()
        {
            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)
            {
                Professionbuddy.Err("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();
            }
        }
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            reader.ReadStartElement("Professionbuddy");
            PrioritySelector ps = (PrioritySelector)DecoratedChild;

            while (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.Comment)
            {
                if (reader.NodeType == XmlNodeType.Comment)
                {
                    ps.AddChild(new Comment(reader.Value));
                    reader.Skip();
                }
                else
                {
                    Type type = Type.GetType("HighVoltz.Composites." + reader.Name);
                    if (type != null)
                    {
                        IPBComposite comp = (IPBComposite)Activator.CreateInstance(type);
                        if (comp != null)
                        {
                            comp.ReadXml(reader);
                            ps.AddChild((Composite)comp);
                        }
                    }
                    else
                    {
                        Professionbuddy.Err("PB:Failed to load type {0}", type);
                    }
                }
            }
            if (reader.NodeType == XmlNodeType.Element)
            {
                reader.ReadEndElement();
            }
        }
Esempio n. 17
0
 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. 18
0
        /// <summary>
        /// Switches to a different character on same account
        /// </summary>
        /// <param name="character"></param>
        /// <param name="server"></param>
        /// <param name="botName">Name of bot to use on that character</param>
        public static void SwitchCharacter(string character, string server, string botName)
        {
            if (_isSwitchingToons)
            {
                Professionbuddy.Log("Already switching characters");
                return;
            }
            string loginLua = string.Format(LoginLua, character, server);

            _isSwitchingToons = true;
            // reset all actions
            Professionbuddy.Instance.IsRunning = false;
            Professionbuddy.Instance.PbBehavior.Reset();

            Application.Current.Dispatcher.Invoke(
                new Action(() =>
            {
                TreeRoot.Stop();
                BotBase bot =
                    BotManager.Instance.Bots.FirstOrDefault(
                        b => b.Key.IndexOf(botName, StringComparison.OrdinalIgnoreCase) >= 0).Value;
                if (bot != null)
                {
                    if (Professionbuddy.Instance.SecondaryBot.Name != bot.Name)
                    {
                        Professionbuddy.Instance.SecondaryBot = bot;
                    }
                    if (!bot.Initialized)
                    {
                        bot.Initialize();
                    }
                    if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name)
                    {
                        ProfessionBuddySettings.Instance.LastBotBase = bot.Name;
                        ProfessionBuddySettings.Instance.Save();
                    }
                }
                else
                {
                    Professionbuddy.Err("Could not find bot with name {0}", botName);
                }

                Lua.DoString("Logout()");

                new Thread(() =>
                {
                    while (ObjectManager.IsInGame)
                    {
                        Thread.Sleep(2000);
                    }
                    while (!ObjectManager.IsInGame)
                    {
                        Lua.DoString(loginLua);
                        Thread.Sleep(2000);
                    }
                    TreeRoot.Start();
                    Professionbuddy.Instance.OnTradeSkillsLoaded +=
                        Professionbuddy.Instance.Professionbuddy_OnTradeSkillsLoaded;
                    Professionbuddy.Instance.LoadTradeSkills();
                    _isSwitchingToons = false;
                    Professionbuddy.Instance.IsRunning = true;
                })
                {
                    IsBackground = true
                }.Start();
            }));
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
        public static Type CompileAndLoad()
        {
            CompilerResults results;

            using (var provider = new CSharpCodeProvider(new Dictionary <string, string>
            {
                { "CompilerVersion", "v3.5" },
            }))
            {
                var options = new CompilerParameters();
                foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (!asm.GetName().Name.Contains(Professionbuddy.Instance.Name))
                    {
                        options.ReferencedAssemblies.Add(asm.Location);
                    }
                }
                options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);

                // disabled due to a bug in 2.0.0.3956;
                //options.GenerateInMemory = true;
                options.GenerateExecutable      = false;
                options.TempFiles               = new TempFileCollection(TempFolder, false);
                options.IncludeDebugInformation = false;
                options.OutputAssembly          = string.Format("{0}\\CodeAssembly{1:N}.dll", TempFolder, Guid.NewGuid());
                options.CompilerOptions         = "/optimize";
                CsharpStringBuilder             = new StringBuilder();
                CsharpStringBuilder.Append(Prefix);
                // Line numbers are used to identify actions that genorated compile errors.
                int currentLine = CsharpStringBuilder.ToString().Count(c => c == '\n') + 1;
                // genorate CanRun Methods
                foreach (var met in Declarations)
                {
                    CsharpStringBuilder.AppendFormat("{0}\n", met.Value.Code.Replace(Environment.NewLine, ""));
                    met.Value.CodeLineNumber = currentLine++;
                }
                foreach (var met in NoneDeclarations)
                {
                    if (met.Value.CodeType == CsharpCodeType.BoolExpression)
                    {
                        CsharpStringBuilder.AppendFormat("public bool {0} (object context){{return {1};}}\n", met.Key,
                                                         met.Value.Code.Replace(Environment.NewLine, ""));
                    }
                    else if (met.Value.CodeType == CsharpCodeType.Statements)
                    {
                        CsharpStringBuilder.AppendFormat("public void {0} (object context){{{1}}}\n", met.Key,
                                                         met.Value.Code.Replace(Environment.NewLine, ""));
                    }
                    else if (met.Value.CodeType == CsharpCodeType.Expression)
                    {
                        Type retType = ((IDynamicProperty)met.Value).ReturnType;
                        CsharpStringBuilder.AppendFormat("public {0} {1} (object context){{return {2};}}\n",
                                                         retType.Name, met.Key,
                                                         met.Value.Code.Replace(Environment.NewLine, ""));
                    }
                    met.Value.CodeLineNumber = currentLine++;
                }
                CsharpStringBuilder.Append(Postfix);
                results = provider.CompileAssemblyFromSource(
                    options, CsharpStringBuilder.ToString());
            }
            if (results.Errors.HasErrors)
            {
                if (results.Errors.Count > 0)
                {
                    foreach (CompilerError error in results.Errors)
                    {
                        ICSharpCode icsc = CsharpCodeDict.Values.FirstOrDefault(c => c.CodeLineNumber == error.Line);
                        if (icsc != null)
                        {
                            Professionbuddy.Err("{0}\nCompile Error : {1}\n", icsc.AttachedComposite.Title,
                                                error.ErrorText);
                            icsc.CompileError = error.ErrorText;
                        }
                        else
                        {
                            Professionbuddy.Err("Unable to link action that produced Error: {0}", error.ErrorText);
                        }
                    }
                    if (MainForm.IsValid)
                    {
                        MainForm.Instance.RefreshActionTree(typeof(ICSharpCode));
                    }
                }
                return(null);
            }
            CodeWasModified = false;
            return(results.CompiledAssembly.GetType("CodeDriver"));
        }
Esempio n. 21
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (!IsRecipe)
         {
             CheckTradeskillList();
         }
         if (Casted >= CalculatedRepeat)
         {
             if (ObjectManager.Me.IsCasting && ObjectManager.Me.CastingSpell.Id == Entry)
             {
                 SpellManager.StopCasting();
             }
             _spamControl.Stop();
             _spamControl.Reset();
             Lua.Events.DetachEvent("UNIT_SPELLCAST_SUCCEEDED", OnUnitSpellCastSucceeded);
             IsDone = true;
             return(RunStatus.Failure);
         }
         // can't make recipe so stop trying.
         if (IsRecipe && Recipe.CanRepeatNum2 <= 0)
         {
             Professionbuddy.Debug("{0} doesn't have enough material to craft.", SpellName);
             IsDone = true;
             return(RunStatus.Failure);
         }
         if (Me.IsCasting && Me.CastingSpellId != Entry)
         {
             SpellManager.StopCasting();
         }
         // we should confirm the last recipe in list so we don't make an axtra
         if (!Me.IsFlying && Casted + 1 < CalculatedRepeat || (Casted + 1 == CalculatedRepeat &&
                                                               (Confimed || !_spamControl.IsRunning ||
                                                                (_spamControl.ElapsedMilliseconds >=
                                                                 (_recastTime + (_recastTime / 2)) + _waitTime &&
                                                                 !ObjectManager.Me.IsCasting))))
         {
             if (!_spamControl.IsRunning || _spamControl.ElapsedMilliseconds >= _recastTime ||
                 (!ObjectManager.Me.IsCasting && _spamControl.ElapsedMilliseconds >= _waitTime))
             {
                 if (ObjectManager.Me.IsMoving)
                 {
                     WoWMovement.MoveStop();
                 }
                 if (!QueueIsRunning)
                 {
                     Lua.Events.AttachEvent("UNIT_SPELLCAST_SUCCEEDED", OnUnitSpellCastSucceeded);
                     QueueIsRunning      = true;
                     TreeRoot.StatusText = string.Format("Casting: {0}",
                                                         IsRecipe
                                                             ? Recipe.Name
                                                             : Entry.ToString(CultureInfo.InvariantCulture));
                 }
                 WoWSpell spell = WoWSpell.FromId((int)Entry);
                 if (spell == null)
                 {
                     Professionbuddy.Err("{0}: {1}", Pb.Strings["Error_UnableToFindSpellWithEntry"], Entry);
                     return(RunStatus.Failure);
                 }
                 _recastTime = spell.CastTime;
                 Professionbuddy.Debug("Casting {0}, recast :{1}", spell.Name, _recastTime);
                 if (CastOnItem)
                 {
                     WoWItem item = TargetedItem;
                     if (item != null)
                     {
                         spell.CastOnItem(item);
                     }
                     else
                     {
                         Professionbuddy.Err("{0}: {1}",
                                             Pb.Strings["Error_UnableToFindItemToCastOn"],
                                             IsRecipe
                                                 ? Recipe.Name
                                                 : Entry.ToString(CultureInfo.InvariantCulture));
                         IsDone = true;
                     }
                 }
                 else
                 {
                     spell.Cast();
                 }
                 _waitTime = StyxWoW.WoWClient.Latency * 2;
                 Confimed  = false;
                 _spamControl.Reset();
                 _spamControl.Start();
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 22
0
        List <BuyItemEntry> BuildItemList()
        {
            List <BuyItemEntry> list   = new List <BuyItemEntry>();
            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;
            }

            switch (ItemListType)
            {
            case ItemType.Item:
                foreach (uint id in idList)
                {
                    list.Add(new BuyItemEntry()
                    {
                        Id        = id,
                        BuyAmount = !BuyAdditively ? Amount - Util.GetCarriedItemCount(id) : Amount
                    });
                }
                break;

            case ItemType.MaterialList:
                foreach (var kv in Pb.MaterialList)
                {
                    list.Add(new BuyItemEntry()
                    {
                        Id = kv.Key, BuyAmount = (uint)kv.Value
                    });
                }
                break;

            case ItemType.RecipeMats:
                foreach (uint id in idList)
                {
                    Recipe recipe = (from tradeskill in Pb.TradeSkillList
                                     where tradeskill.Recipes.ContainsKey(id)
                                     select tradeskill.Recipes[id]).FirstOrDefault();
                    if (recipe != null)
                    {
                        foreach (var ingred in recipe.Ingredients)
                        {
                            // subtract whatever material we have in bags already
                            int toBuyAmount = (int)((ingred.Required * Amount) - Ingredient.GetInBagItemCount(ingred.ID));
                            if (toBuyAmount > 0)
                            {
                                list.Add(new BuyItemEntry()
                                {
                                    Id = ingred.ID, BuyAmount = (uint)toBuyAmount
                                });
                            }
                        }
                    }
                }
                break;
            }
            return(list);
        }
Esempio n. 23
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)
                    {
                        Professionbuddy.Err(Pb.Strings["Error_UnableToFindMailbox"]);
                        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);
        }
Esempio n. 24
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
         {
             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)
             {
                 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);
                         break;
                     }
                 }
             }
         }
         else
         {
             // check if we have merchant frame open at correct NPC
             if (NpcEntry > 0 && Me.GotTarget && Me.CurrentTarget.Entry != NpcEntry)
             {
                 MerchantFrame.Instance.Close();
                 return(RunStatus.Success);
             }
             if (!_concludingSw.IsRunning)
             {
                 if (BuyItemType == BuyItemActionType.SpecificItem)
                 {
                     var      idList  = new List <uint>();
                     string[] entries = ItemID.Split(',');
                     if (entries.Length > 0)
                     {
                         foreach (string entry in entries)
                         {
                             uint temp;
                             uint.TryParse(entry.Trim(), out temp);
                             idList.Add(temp);
                         }
                     }
                     else
                     {
                         Professionbuddy.Err(Pb.Strings["Error_NoItemEntries"]);
                         IsDone = true;
                         return(RunStatus.Failure);
                     }
                     foreach (uint id in idList)
                     {
                         int count = !BuyAdditively ? Count - Util.GetCarriedItemCount(id) : Count;
                         if (count > 0)
                         {
                             BuyItem(id, (uint)count);
                         }
                     }
                 }
                 else if (BuyItemType == BuyItemActionType.Material)
                 {
                     foreach (var kv in Pb.MaterialList)
                     {
                         // only buy items if we don't have enough in bags...
                         int amount = kv.Value - (int)Ingredient.GetInBagItemCount(kv.Key);
                         if (amount > 0)
                         {
                             BuyItem(kv.Key, (uint)amount);
                         }
                     }
                 }
                 _concludingSw.Start();
             }
             if (_concludingSw.ElapsedMilliseconds >= 2000)
             {
                 Professionbuddy.Log("BuyItemAction Completed");
                 IsDone = true;
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 25
0
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                try
                {
                    if (
                        Lua.GetReturnVal <int>(
                            "if AuctionFrame and AuctionFrame:IsVisible() == 1 then return 1 else return 0 end ", 0) ==
                        0)
                    {
                        MoveToAh();
                    }
                    else if (
                        Lua.GetReturnVal <int>(
                            "if CanSendAuctionQuery('owner') == 1 then return 1 else return 0 end ", 0) == 1)
                    {
                        if (_toScanItemList == null)
                        {
                            _toScanItemList   = BuildScanItemList();
                            _toCancelItemList = new List <AuctionEntry>();
                        }

                        if (_toScanItemList.Count > 0)
                        {
                            AuctionEntry ae       = _toScanItemList[0];
                            bool         scanDone = ScanAh(ref ae);
                            _toScanItemList[0] = ae; // update
                            if (scanDone)
                            {
                                _toCancelItemList.Add(ae);
                                _toScanItemList.RemoveAt(0);
                            }
                            if (_toScanItemList.Count == 0)
                            {
                                Professionbuddy.Debug("Finished scanning for items");
                            }
                        }
                        else
                        {
                            if (_toCancelItemList.Count == 0)
                            {
                                _toScanItemList = null;
                                IsDone          = true;
                                return(RunStatus.Failure);
                            }
                            if (CancelAuction(_toCancelItemList[0]))
                            {
                                _toCancelItemList.RemoveAt(0);
                            }
                        }
                    }
                    return(RunStatus.Success);
                }
                catch (Exception ex)
                {
                    Professionbuddy.Err(ex.ToString());
                }
            }
            return(RunStatus.Failure);
        }
Esempio n. 26
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)
                    {
                        Professionbuddy.Err(Pb.Strings["Error_UnableToFindMailbox"]);
                        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 < 0 ? 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);
        }