Exemplo n.º 1
0
        // Credits to Inrego
        // Index are {0}=ItemID, {1}=Amount
        // returns 1 if item is found, otherwise -1

        public static void BuyItem(uint id, uint count)
        {
            string lua   = string.Format(BuyItemFormat, id, count);
            bool   found = Lua.GetReturnVal <int>(lua, 0) == 1;

            PBLog.Log("item {0} {1}", id, found ? "bought " : "not found");
        }
        protected async override Task Run()
        {
            if (_sub == null && !SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub))
            {
                PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName);
                IsDone = true;
                return;
            }

            using (SubRoutineComposite.Activate(_sub))
            {
                try
                {
                    if (_sub.IsDone)
                    {
                        _sub.Reset();
                    }
                    await _sub;
                }
                finally
                {
                    IsDone = _sub.IsDone;
                }
            }
        }
Exemplo n.º 3
0
 protected async override Task Run()
 {
     try
     {
         try
         {
             await Action(this);
         }
         catch (Exception ex)
         {
             if (ex.GetType() != typeof(ThreadAbortException))
             {
                 PBLog.Warn("{0}:({1})\n{2}", Strings["Action_CustomAction_Name"], Code, ex);
             }
         }
         IsDone = true;
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             PBLog.Warn("There was an exception while executing a CustomAction\n{0}", ex);
         }
     }
 }
Exemplo n.º 4
0
 private void OnUnitSpellCastSucceeded(object obj, LuaEventArgs args)
 {
     try
     {
         if ((string)args.Args[0] == "player" && (uint)((double)args.Args[4]) == Entry)
         {
             // confirm last recipe
             if (Casted + 1 == CalculatedRepeat)
             {
                 Confimed = true;
             }
             if (RepeatType != RepeatCalculationType.Craftable)
             {
                 Casted++;
             }
             ProfessionbuddyBot.Instance.UpdateMaterials();
             if (MainForm.IsValid)
             {
                 MainForm.Instance.RefreshTradeSkillTabs();
                 MainForm.Instance.RefreshActionTree(typeof(CastSpellAction));
             }
         }
     }
     catch (Exception ex)
     {
         PBLog.Warn(ex.ToString());
     }
 }
Exemplo n.º 5
0
        private List <AuctionEntry> BuildScanItemList()
        {
            var tmpItemlist = new List <AuctionEntry>();

            if (UseCategory)
            {
                var itemList =
                    StyxWoW.Me.BagItems.Where(
                        i =>
                        !i.IsSoulbound && !i.IsConjured && !i.IsDisabled && !i.IsGiftWrapped && i.ItemInfo.ItemClass == Category &&
                        SubCategoryCheck(i)).ToList();
                foreach (var item in itemList)
                {
                    // skip tradeskill tools. If tools need to be mailed then they should be selected by ID
                    if (ProfessionbuddyBot.Instance.TradeskillTools.Contains(item.Entry))
                    {
                        continue;
                    }
                    // don't add same item id multiple times.
                    if (tmpItemlist.Any(ae => ae.Id == item.Entry))
                    {
                        continue;
                    }
                    // skip items with less than 'StackSize amount in bag if not posting partial stacks.
                    if (!PostPartialStacks && Helpers.InbagCount(item.Entry) < StackSize)
                    {
                        continue;
                    }
                    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 itemID;
                        if (!uint.TryParse(entry.Trim(), out itemID))
                        {
                            PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                            continue;
                        }
                        List <WoWItem> itemList = StyxWoW.Me.BagItems.Where(i => !i.IsSoulbound && !i.IsConjured && i.Entry == itemID).ToList();
                        if (!itemList.Any() || !PostPartialStacks && itemList.Count < StackSize)
                        {
                            continue;
                        }
                        tmpItemlist.Add(new AuctionEntry(itemList[0].Name, itemList[0].Entry, 0, 0));
                    }
                }
                else
                {
                    PBLog.Warn(Strings["Error_NoItemEntries"]);
                    IsDone = true;
                }
            }
            return(tmpItemlist);
        }
Exemplo n.º 6
0
        private List <uint> BuildItemList()
        {
            var idList = new List <uint>();

            string[] entries = ItemID.Split(',');
            if (entries.Length > 0)
            {
                foreach (string entry in entries)
                {
                    uint itemID;
                    if (!uint.TryParse(entry.Trim(), out itemID))
                    {
                        PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                        continue;
                    }
                    idList.Add(itemID);
                }
            }
            else
            {
                PBLog.Warn(Strings["Error_NoItemEntries"]);
                IsDone = true;
            }
            return(idList);
        }
Exemplo n.º 7
0
 private void DoCleanup()
 {
     TreeHooks.Instance.RemoveHook(TreeHookName, _treeHookStub);
     BotEvents.Profile.OnNewOuterProfileLoaded -= ProfileOnOnNewOuterProfileLoaded;
     BotEvents.OnBotStopped -= BotEvents_OnBotStopped;
     PBLog.Debug("Detached the '{0}' SubRoutine from the {1} TreeHook", SubRoutineName, TreeHookName);
     _ranonce = false;
 }
Exemplo n.º 8
0
        protected override async Task Run()
        {
            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)
                {
                    PBLog.Warn(Strings["Error_UnableToFindLocationFromDB"]);
                    IsDone = true;
                    return;
                }
            }
            if (Entry > 0 && (!StyxWoW.Me.GotTarget || StyxWoW.Me.CurrentTarget.Entry != Entry))
            {
                WoWUnit unit = ObjectManager.GetObjectsOfType <WoWUnit>(true).FirstOrDefault(u => u.Entry == Entry);
                if (unit != null)
                {
                    unit.Target();
                }
            }
            float speed = StyxWoW.Me.MovementInfo.CurrentSpeed;

            Navigator.PathPrecision = speed > 7 ? (SpeedModifer * speed) / 7f : SpeedModifer;
            if (StyxWoW.Me.Location.Distance(_loc) > 4.5)
            {
                if (Pathing == NavigationType.ClickToMove)
                {
                    WoWMovement.ClickToMove(_loc);
                }
                else
                {
                    Util.MoveTo(_loc);
                }
            }
            else
            {
                if (!_concludingSw.IsRunning)
                {
                    _concludingSw.Start();
                }
                else if (_concludingSw.ElapsedMilliseconds >= 2000)
                {
                    IsDone = true;
                    PBLog.Log("MoveTo Action completed for type {0}", MoveType);
                    _concludingSw.Stop();
                    _concludingSw.Reset();
                }
            }
        }
Exemplo n.º 9
0
        private async Task MailItems(string recipient, string subject)
        {
            var lua = string.Format("SendMail ('{0}', '{1}' ,'');  ",
                                    recipient.ToFormatedUTF8(), subject.ToFormatedUTF8());

            PBLog.Debug("MailItem: Sending mail");
            Lua.DoString(lua);
            await CommonCoroutines.SleepForLagDuration();
        }
Exemplo n.º 10
0
        protected async override Task Run()
        {
            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)
                        {
                            ProfessionbuddyBot.Debug("Finished scanning for items");
                        }
                    }
                    else
                    {
                        if (_toCancelItemList.Count == 0)
                        {
                            _toScanItemList = null;
                            IsDone          = true;
                            return;
                        }
                        if (CancelAuction(_toCancelItemList[0]))
                        {
                            _toCancelItemList.RemoveAt(0);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PBLog.Warn(ex.ToString());
            }
        }
Exemplo n.º 11
0
        private List <AuctionEntry> BuildScanItemList()
        {
            var tmpItemlist = new List <AuctionEntry>();
            Dictionary <uint, string> myAucs = GetMyAuctions();

            if (UseCategory)
            {
                using (StyxWoW.Memory.AcquireFrame())
                {
                    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
                        {
                            PBLog.Warn("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 itemID;
                            if (!uint.TryParse(entry.Trim(), out itemID))
                            {
                                PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                                continue;
                            }
                            if (myAucs.ContainsKey(itemID))
                            {
                                tmpItemlist.Add(new AuctionEntry(myAucs[itemID], itemID, 0, 0));
                            }
                        }
                    }
                }
            }
            return(tmpItemlist);
        }
Exemplo n.º 12
0
 protected async override Task Run()
 {
     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 (StyxWoW.Me.GotTarget)
             {
                 obj = StyxWoW.Me.CurrentTarget;
             }
         }
         else if (InteractType == InteractActionType.GameObject)
         {
             obj =
                 ObjectManager.GetObjectsOfType <WoWGameObject>().OrderBy(u => u.Distance).FirstOrDefault(
                     u => (Entry > 0 && u.Entry == Entry) || (u.SubType == GameObjectType &&
                                                              (GameObjectType != WoWGameObjectType.SpellFocus ||
                                                               (GameObjectType == WoWGameObjectType.SpellFocus &&
                                                                u.SpellFocus == SpellFocus))));
         }
         if (obj != null)
         {
             WoWPoint moveToLoc = WoWMathHelper.CalculatePointFrom(Me.Location, obj.Location, 3);
             if (moveToLoc.Distance(Me.Location) > 4)
             {
                 Util.MoveTo(moveToLoc);
             }
             else
             {
                 if (InteractDelay > 0 &&
                     (!_interactSw.IsRunning || _interactSw.ElapsedMilliseconds < InteractDelay))
                 {
                     _interactSw.Start();
                 }
                 else
                 {
                     _interactSw.Reset();
                     obj.Interact();
                     IsDone = true;
                 }
             }
         }
         if (IsDone)
         {
             PBLog.Log("InteractAction complete");
         }
     }
 }
Exemplo n.º 13
0
        private bool CancelAuction(AuctionEntry ae)
        {
            string lua         = String.Format(CancelAuctionLuaFormat, ae.Id, MinBuyout.TotalCopper, ae.LowestBo);
            var    numCanceled = Lua.GetReturnVal <int>(lua, 0);

            if (numCanceled > 0)
            {
                PBLog.Log("Canceled {0} x{1}", ae.Name, numCanceled);
            }
            return(true);
        }
Exemplo n.º 14
0
 private void All()
 {
     try
     {
         DGVEmployee.DataSource = employeeModel.All();
     }
     catch (Exception Ex)
     {
         PBLog.Save(this, Ex);
     }
 }
Exemplo n.º 15
0
 private void TBFilter_KeyUp(object sender, KeyEventArgs e)
 {
     try
     {
         DGVEmployee.DataSource = employeeModel.Filter(TBFilter.Text);
     }
     catch (Exception Ex)
     {
         PBLog.Save(this, Ex);
     }
 }
Exemplo n.º 16
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 (item.ItemInfo.ItemClass == Category &&
                        SubCategoryCheck(item) && !itemList.ContainsKey(item.Entry))
                    {
                        itemList.Add(
                            item.Entry,
                            Deposit == DepositWithdrawAmount.Amount
                                                                ? Amount
                                                                : Util.GetCarriedItemCount(item.Entry));
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint itemID;
                        if (!uint.TryParse(entry.Trim(), out itemID))
                        {
                            PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                            continue;
                        }
                        itemList.Add(
                            itemID,
                            Deposit == DepositWithdrawAmount.Amount
                                                                ? Amount
                                                                : Util.GetCarriedItemCount(itemID));
                    }
                }
                else
                {
                    PBLog.Warn(Strings["Error_NoItemEntries"]);
                    IsDone = true;
                }
            }
            return(itemList);
        }
Exemplo n.º 17
0
 protected bool CanRun()
 {
     try
     {
         return(CanRunDelegate(this));
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             PBLog.Warn("{0}\nErr:{1}", Title, ex);
         }
         return(false);
     }
 }
Exemplo n.º 18
0
        protected override async Task Run()
        {
            try
            {
                if (_changeBotTimer == null)
                {
                    _changeBotTimer = new WaitTimer(TimeSpan.FromSeconds(10));
                    _changeBotTimer.Reset();
                    _bot = Util.GetBotByName(BotName);
                    if (_bot != null)
                    {
                        if (ProfessionbuddyBot.Instance.SecondaryBot == _bot)
                        {
                            IsDone = true;
                            return;
                        }
                        ProfessionbuddyBot.ChangeSecondaryBot(BotName);
                    }
                }
            }
            finally
            {
                // Wait until bot change completes or fails
                if (_bot == null ||
                    _changeBotTimer != null && (_changeBotTimer.IsFinished || ProfessionbuddyBot.Instance.SecondaryBot == _bot))
                {
                    IsDone          = true;
                    _changeBotTimer = null;
                }
            }

            if (IsDone)
            {
                if (_bot == null)
                {
                    PBLog.Warn("No bot with name: {0} could be found", BotName);
                }
                else if (ProfessionbuddyBot.Instance.SecondaryBot == _bot)
                {
                    PBLog.Log("Successfuly changed secondary bot to: {0}", BotName);
                }
                else
                {
                    PBLog.Warn("Unable to switch secondary bot to: {0}", BotName);
                }
            }
        }
Exemplo n.º 19
0
        private async Task OpenMailbox()
        {
            WoWPoint      movetoPoint = _loc;
            WoWGameObject mailbox;

            if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
            {
                mailbox =
                    ObjectManager.GetObjectsOfType <WoWGameObject>().Where(
                        o => o.SubType == WoWGameObjectType.Mailbox && o.CanUse())
                    .OrderBy(o => o.DistanceSqr).FirstOrDefault();
            }
            else
            {
                mailbox =
                    ObjectManager.GetObjectsOfType <WoWGameObject>().Where(
                        o => o.SubType == WoWGameObjectType.Mailbox &&
                        o.Location.Distance(_loc) < 10 && o.CanUse())
                    .OrderBy(o => o.DistanceSqr).FirstOrDefault();
            }
            if (mailbox != null)
            {
                movetoPoint = mailbox.Location;
            }

            if (movetoPoint == WoWPoint.Zero)
            {
                PBLog.Warn(Strings["Error_UnableToFindMailbox"]);
                return;
            }

            if (mailbox == null || !mailbox.WithinInteractRange)
            {
                await CommonCoroutines.MoveTo(movetoPoint);

                return;
            }

            if (Me.IsMoving)
            {
                await CommonCoroutines.StopMoving();
            }
            mailbox.Interact();
        }
        // indexes are {0} = ItemID, {1} = amount to deposit

        /// <summary>
        /// Withdraws items from gbank
        /// </summary>
        /// <param name="id">item ID</param>
        /// <param name="amount">amount to withdraw.</param>
        /// <returns>the amount withdrawn.</returns>
        public int GetItemFromGBank(uint id, int amount)
        {
            if (_queueServerSW == null)
            {
                _queueServerSW = new Stopwatch();
                _queueServerSW.Start();
                Lua.DoString("for i=GetNumGuildBankTabs(), 1, -1 do QueryGuildBankTab(i) end ");
                PBLog.Log("Queuing server for gbank info");
                return(0);
            }
            if (_queueServerSW.ElapsedMilliseconds < 2000)
            {
                return(0);
            }
            string lua    = string.Format(WithdrawItemFromGBankLuaFormat, id, amount);
            var    retVal = Lua.GetReturnVal <int>(lua, 0);

            return(retVal);
        }
Exemplo n.º 21
0
        private 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)
            {
                PBLog.Warn(Strings["Error_UnableToFindAuctioneer"]);
            }
            if (movetoPoint.Distance(StyxWoW.Me.Location) > 4.5)
            {
                Util.MoveTo(movetoPoint);
            }
            else if (auctioneer != null)
            {
                auctioneer.Interact();
            }
        }
Exemplo n.º 22
0
        protected async override Task Run()
        {
            try
            {
                if (!SubRoutineComposite.GetSubRoutineMyName(SubRoutineName, out _sub))
                {
                    PBLog.Warn("{0}: {1}.", ProfessionbuddyBot.Instance.Strings["Error_SubroutineNotFound"], SubRoutineName);
                    return;
                }

                _treeHookStub = new ActionRunCoroutine(ctx => SubRoutineExecutor());
                TreeHooks.Instance.InsertHook(TreeHookName, 0, _treeHookStub);
                BotEvents.Profile.OnNewOuterProfileLoaded += ProfileOnOnNewOuterProfileLoaded;
                BotEvents.OnBotStopped += BotEvents_OnBotStopped;
                PBLog.Debug("Attached the '{0}' SubRoutine to the {1} TreeHook", SubRoutineName, TreeHookName);
            }
            finally
            {
                _ranonce = true;
            }
        }
        private Dictionary <uint, int> BuildItemList()
        {
            var items = new Dictionary <uint, int>();

            switch (GetItemfromBankType)
            {
            case BankWithdrawlItemType.SpecificItem:
                //List<uint> idList = new List<uint>();
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint itemID;
                        if (!uint.TryParse(entry.Trim(), out itemID))
                        {
                            PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                            continue;
                        }
                        if (WithdrawAdditively)
                        {
                            items.Add(itemID, Withdraw == DepositWithdrawAmount.All ? int.MaxValue : Amount);
                        }
                        else
                        {
                            items.Add(itemID, Amount - Util.GetCarriedItemCount(itemID));
                        }
                    }
                }
                break;

            case BankWithdrawlItemType.Materials:
                foreach (var kv in PB.MaterialList)
                {
                    items.Add(kv.Key, kv.Value);
                }
                break;
            }
            return(items);
        }
Exemplo n.º 24
0
        private void MoveToBanker()
        {
            WoWPoint  movetoPoint = _loc;
            WoWObject bank        = GetLocalBanker();

            if (bank != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, bank.Location, 4);
            }
            // 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;
                PBLog.Warn("Unable to find bank");
            }
            if (movetoPoint.Distance(StyxWoW.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;
                PBLog.Warn(Strings["Error_UnableToFindBank"]);
            }
        }
Exemplo n.º 25
0
 protected async override Task Run()
 {
     if (!_timeout.IsRunning)
     {
         _timeout.Start();
     }
     try
     {
         if (_timeout.ElapsedMilliseconds >= Timeout || CanRunDelegate(this))
         {
             _timeout.Reset();
             ProfessionbuddyBot.Debug("Wait for {0} or until {1} Completed", TimeSpan.FromMilliseconds(Timeout), Condition);
             IsDone = true;
         }
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             PBLog.Warn("{0}:({1})\n{2}", Strings["Action_WaitAction_Name"], Condition, ex);
         }
     }
 }
Exemplo n.º 26
0
 private void Login()
 {
     try
     {
         if (TBUsername.Text != "")
         {
             if (TBPassword.Text != "")
             {
                 if (employeeModel.Login(TBUsername.Text, Helpers.SHA1(TBPassword.Text)))
                 {
                     FormMain Frm = new FormMain();
                     Frm.Show();
                     Hide();
                 }
                 else
                 {
                     Msg("Usuario y/o contraseña incorrecta. \npor favor vuelve a intentarlo.");
                 }
             }
             else
             {
                 Msg("Ingresa tu contraseña!");
                 TBPassword.Focus();
             }
         }
         else
         {
             Msg("Ingresa tu Usuario");
             TBUsername.Focus();
         }
     }
     catch (Exception er)
     {
         PBLog.Save(this, er);
     }
 }
Exemplo n.º 27
0
        protected override async Task Run()
        {
            if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
            {
                WoWPoint movetoPoint = _loc;
                if (_entry == 0)
                {
                    _entry = NpcEntry;
                }
                if (_entry == 0)
                {
                    MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestVendor, 0);
                    NpcResult npcResults = NpcQueries.GetNearestNpc(
                        StyxWoW.Me.MapId,
                        StyxWoW.Me.Location,
                        UnitNPCFlags.Vendor);
                    _entry      = (uint)npcResults.Entry;
                    movetoPoint = npcResults.Location;
                }
                WoWUnit 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 && StyxWoW.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;
                        }
                    }
                }
            }
            else
            {
                if (SellItemType == SellItemActionType.Specific)
                {
                    var      idList  = new List <uint>();
                    string[] entries = ItemID.Split(',');
                    if (entries.Length > 0)
                    {
                        foreach (string entry in entries)
                        {
                            uint itemID;
                            if (!uint.TryParse(entry.Trim(), out itemID))
                            {
                                PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                                continue;
                            }
                            idList.Add(itemID);
                        }
                    }
                    else
                    {
                        PBLog.Warn(Strings["Error_NoItemEntries"]);
                        IsDone = true;
                        return;
                    }
                    List <WoWItem> itemList = StyxWoW.Me.BagItems.Where(u => idList.Contains(u.Entry)).
                                              Take(Sell == DepositWithdrawAmount.All ? int.MaxValue : Count).ToList();
                    using (StyxWoW.Memory.AcquireFrame())
                    {
                        foreach (WoWItem item in itemList)
                        {
                            item.UseContainerItem();
                        }
                    }
                }
                else
                {
                    List <WoWItem>        itemList  = null;
                    IEnumerable <WoWItem> itemQuery = from item in Me.BagItems
                                                      where !ProtectedItemsManager.Contains(item.Entry) &&
                                                      !ProfessionbuddyBot.Instance.TradeskillTools.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;

                    case SellItemActionType.Blues:
                        itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Rare).ToList();
                        break;
                    }
                    if (itemList != null)
                    {
                        using (StyxWoW.Memory.AcquireFrame())
                        {
                            foreach (WoWItem item in itemList)
                            {
                                item.UseContainerItem();
                            }
                        }
                    }
                }
                PBLog.Log("SellItemAction Completed for {0}", ItemID);
                IsDone = true;
            }
        }
Exemplo n.º 28
0
        protected async override Task Run()
        {
            if (_loadingProfile)
            {
                return;
            }

            var absPath = GetAbsolutePath();

            bool emptyProfile = string.IsNullOrEmpty(Path);

            if (IsLocal)
            {
                // check if profile is already loaded.
                if (!string.IsNullOrEmpty(ProfileManager.XmlLocation) &&
                    ProfileManager.XmlLocation.Equals(absPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    IsDone = true;
                    return;
                }
                // check if profile exists
                if (!emptyProfile && !File.Exists(absPath))
                {
                    PBLog.Warn("{0}: {1}", ProfessionbuddyBot.Instance.Strings["Error_UnableToFindProfile"], Path);
                    IsDone = true;
                    return;
                }
            }

            ProfessionbuddyBot.Debug(
                "Loading Profile: {0}, previous profile was {1}",
                emptyProfile ? "(Empty Profile)" : Path,
                ProfileManager.XmlLocation ?? "[No Profile]");

            var path = emptyProfile || !IsLocal ? Path : absPath;

            Util.ExecuteActionWhileBotIsStopped(
                () =>
            {
                try
                {
                    if (string.IsNullOrEmpty(path))
                    {
                        ProfileManager.LoadEmpty();
                    }
                    else if (!IsLocal)
                    {
                        var req   = WebRequest.Create(path);
                        req.Proxy = null;
                        using (WebResponse res = req.GetResponse())
                        {
                            using (var stream = res.GetResponseStream())
                            {
                                ProfileManager.LoadNew(stream);
                            }
                        }
                    }
                    else if (File.Exists(path))
                    {
                        ProfileManager.LoadNew(path);
                    }
                    IsDone = true;
                    ProfessionbuddyBot.Debug("Successfully loaded profile:{0}", emptyProfile ? "(Empty Profile)" : Path);
                }
                catch (Exception ex)
                {
                    // if ex is not null there was a problem loading profile.
                    ProfessionbuddyBot.Fatal("Failed to load profile.\n{0}", ex);
                }
            },
                "Loading a new profile");
            _loadingProfile = true;
        }
Exemplo n.º 29
0
        public bool Load()
        {
            var absPath = AbsolutePath;

            if (IsLocal && !string.IsNullOrEmpty(ProfileManager.XmlLocation) &&
                ProfileManager.XmlLocation.Equals(absPath, StringComparison.CurrentCultureIgnoreCase))
            {
                return(false);
            }
            try
            {
                // Logging.Write("Cava: {0}", "something");

                PBLog.Debug(
                    "CAVAPB Loading Profile :{0}, previous profile was {1}",
                    Path,
                    ProfileManager.XmlLocation ?? "[No Profile]");
                if (string.IsNullOrEmpty(Path))
                {
                    ProfileManager.LoadEmpty();
                }
                else if (!IsLocal)
                {
                    if (Path.Contains("cavaprofessions"))
                    {
                        var pathtocavasettings = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                        string.Format(@"Settings\CavaPlugin\Main-Settings.xml"));
                        var servertouse = Getdata(pathtocavasettings, "UseServer");
                        if (servertouse == "0")
                        {
                            Path = "https://cavaprofiles.net/index.php/profiles/profiles-list/" + Path;
                            var url = string.Format("https://cavaprofiles.net/index.php?user={0}&passw={1}",
                                                    Getdata(pathtocavasettings, "CpLogin"), Decrypt(Getdata(pathtocavasettings, "CpPassword")));
                            var request = (HttpWebRequest)WebRequest.Create(url);
                            request.AllowAutoRedirect = false;
                            request.CookieContainer   = new CookieContainer();
                            var response = (HttpWebResponse)request.GetResponse();
                            var cookies  = request.CookieContainer;
                            response.Close();
                            try
                            {
                                request =
                                    (HttpWebRequest)
                                    WebRequest.Create(Path + "/file");
                                request.AllowAutoRedirect = false;
                                request.CookieContainer   = cookies;
                                response = (HttpWebResponse)request.GetResponse();
                                var    data = response.GetResponseStream();
                                string html;
                                // ReSharper disable once AssignNullToNotNullAttribute
                                using (var sr = new StreamReader(data))
                                {
                                    html = sr.ReadToEnd();
                                }
                                response.Close();
                                var profilepath =
                                    new MemoryStream(
                                        Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(Convert.FromBase64String(html))));
                                ProfileManager.LoadNew(profilepath);
                            }
                            catch (Exception ex)
                            {
                                PBLog.Warn(
                                    "CAVAPB Does not have access to Profile {0}. Please check if you have Profession access Error code: {1}",
                                    Path, ex);
                                return(false);
                            }
                        }
                        else
                        {
                            Path = "https://cavaprofiles.org/index.php/cavapages/profiles/profiles-list/" + Path;
                            var url = string.Format("https://cavaprofiles.org/index.php?user={0}&passw={1}",
                                                    Getdata(pathtocavasettings, "CpLogin"), Decrypt(Getdata(pathtocavasettings, "CpPassword")));
                            var request = (HttpWebRequest)WebRequest.Create(url);
                            request.AllowAutoRedirect = false;
                            request.CookieContainer   = new CookieContainer();
                            var response = (HttpWebResponse)request.GetResponse();
                            var cookies  = request.CookieContainer;
                            response.Close();
                            try
                            {
                                request =
                                    (HttpWebRequest)
                                    WebRequest.Create(Path + "/file");
                                request.AllowAutoRedirect = false;
                                request.CookieContainer   = cookies;
                                response = (HttpWebResponse)request.GetResponse();
                                var    data = response.GetResponseStream();
                                string html;
                                // ReSharper disable once AssignNullToNotNullAttribute
                                using (var sr = new StreamReader(data))
                                {
                                    html = sr.ReadToEnd();
                                }
                                response.Close();
                                var profilepath =
                                    new MemoryStream(
                                        Encoding.UTF8.GetBytes(Encoding.UTF8.GetString(Convert.FromBase64String(html))));
                                ProfileManager.LoadNew(profilepath);
                            }
                            catch (Exception ex)
                            {
                                PBLog.Warn(
                                    "CAVAPB Does not have access to Profile {0}. Please check if you have Profession access Error code: {1}",
                                    Path, ex);
                                return(false);
                            }
                        }
                    }
                    else
                    {
                        var req = WebRequest.Create(Path);
                        req.Proxy = null;
                        using (WebResponse res = req.GetResponse())
                        {
                            using (var stream = res.GetResponseStream())
                            {
                                ProfileManager.LoadNew(stream);
                            }
                        }
                    }
                }
                else if (File.Exists(absPath))
                {
                    ProfileManager.LoadNew(absPath);
                }
                else
                {
                    PBLog.Warn("{0}: {1}", "CAVAPB Unable to find profile", Path);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                PBLog.Warn("CAVAPB {0}", ex);
                return(false);
            }
            return(true);
        }
Exemplo n.º 30
0
        public int PutItemInGBank(uint id, int amount, uint tab)
        {
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (_queryServerSW == null)
                {
                    _queryServerSW = new Stopwatch();
                    _queryServerSW.Start();
                    Lua.DoString(
                        "for i=GetNumGuildBankTabs(), 1, -1 do QueryGuildBankTab(i) end SetCurrentGuildBankTab({0}) ",
                        tab == 0 ? 1 : tab);
                    PBLog.Log("Querying server for gbank info");
                    return(0);
                }
                if (_queryServerSW.ElapsedMilliseconds < 2000)
                {
                    return(0);
                }
                if (_bankSlots == null)
                {
                    _bankSlots = GetBankSlotInfo();
                }
                var tabCnt     = Lua.GetReturnVal <int>("return GetNumGuildBankTabs()", 0);
                var currentTab = Lua.GetReturnVal <int>("return GetCurrentGuildBankTab()", 0);

                var slotsInCurrentTab = _bankSlots
                                        .Where(slotI => slotI.Bag == currentTab).ToList();

                WoWItem itemToDeposit = Me.CarriedItems.OrderBy(item => item.StackCount)
                                        .FirstOrDefault(item => item.Entry == id && !item.IsDisabled);
                if (itemToDeposit != null)
                {
                    int depositAmount = amount > 0 && amount < (int)itemToDeposit.StackCount
                                                ? amount
                                                : (int)itemToDeposit.StackCount;

                    BankSlotInfo emptySlot    = slotsInCurrentTab.FirstOrDefault(slotI => slotI.StackSize == 0);
                    BankSlotInfo partialStack = slotsInCurrentTab
                                                .FirstOrDefault(
                        slotI => slotI.ItemID == id && slotI.MaxStackSize - slotI.StackSize >= depositAmount);
                    if (partialStack != null || emptySlot != null)
                    {
                        bool slotIsEmpty = partialStack == null;
                        int  bSlotIndex  = slotIsEmpty ? _bankSlots.IndexOf(emptySlot) : _bankSlots.IndexOf(partialStack);
                        _bankSlots[bSlotIndex].StackSize += itemToDeposit.StackCount;
                        if (slotIsEmpty)
                        {
                            _bankSlots[bSlotIndex].ItemID       = itemToDeposit.Entry;
                            _bankSlots[bSlotIndex].MaxStackSize = itemToDeposit.ItemInfo.MaxStackSize;
                        }
                        if (depositAmount == itemToDeposit.StackCount)
                        {
                            itemToDeposit.UseContainerItem();
                        }
                        else
                        {
                            Lua.DoString(
                                "SplitContainerItem({0},{1},{2}) PickupGuildBankItem({3},{4})",
                                itemToDeposit.BagIndex + 1,
                                itemToDeposit.BagSlot + 1,
                                depositAmount,
                                _bankSlots[bSlotIndex].Bag,
                                _bankSlots[bSlotIndex].Slot);
                        }
                        return(depositAmount);
                    }
                    if (tab > 0 || currentTab == tabCnt)
                    {
                        PBLog.Log("Guild Tab: {0} is full", tab);
                        return(-1);
                    }
                    if (tab == 0 && currentTab < tabCnt)
                    {
                        Lua.DoString("SetCurrentGuildBankTab({0})", currentTab + 1);
                        return(0);
                    }
                }
                return(-1);
            }
        }