示例#1
0
        private static void BuyItems(BuyItemsEventArgs args)
        {
            if (ItemToBuy == null)
            {
                return;
            }

            // Little hack here for just Honor and Justice points. Core fails to buy these 2
            if (ItemToBuy.ItemId == 392 || ItemToBuy.ItemId == 395)
            {
                var item = MerchantFrame.Instance.GetAllMerchantItems().FirstOrDefault(i => i.ItemId == ItemToBuy.ItemId);

                if (item == null)
                {
                    Slog("Oops! Something went wrong while trying to buy {0}[{1}]. Please consult to the profile writer", ItemToBuy.ItemName, ItemToBuy.ItemId);
                }
                else
                {
                    Lua.DoString("BuyMerchantItem(" + (item.Index + 1) + ")");
                    // Adding a sleep here to let WoW update itself with currencies. So we don't end up buying something wrong.
                    Thread.Sleep(1000);
                    _pulseTimer.Reset();
                }
            }
            else
            {
                args.BuyItemsIds.Add(ItemToBuy.ItemId, 1);
            }

            Slog("Bought item \"{0}\".", ItemToBuy.ItemName);

            if (!RemoveHPJPWhenCapped || (ItemToBuy.ItemId != 392 && ItemToBuy.ItemId != 395) || _forceAddedPoints)
            {
                Slog("Removing {0} from List Since we bought the Item", ItemToBuy.ItemName);
                BuyItemList.Remove(ItemToBuy);
                _forceAddedPoints = false;
            }
            else
            {
                if (ItemToBuy.ItemId == 392 && WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints).Amount >= 3750)
                {
                    Slog("Removing Honor Points from List Since Capped");
                    BuyItemList.Remove(ItemToBuy);
                }
                else if (ItemToBuy.ItemId == 395 && WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints).Amount >= 3750)
                {
                    Slog("Removing Justice Points from List Since Capped");
                    BuyItemList.Remove(ItemToBuy);
                }
            }

            ItemToBuy = null;
        }
示例#2
0
        public override void Pulse()
        {
            if (!_pulseTimer.IsFinished)
            {
                return;
            }

            _pulseTimer.Reset();

            if (LogoutAtCap && WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints).Amount > 3750 && WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints).Amount > 3750)
            {
                Slog("HonorPoints and Justice Points are Capped! Logging out!");
                InactivityDetector.ForceLogout(true);
            }
            // We should avoid overriding any poi set by the core
            if (BotPoi.Current.Type != PoiType.None)
            {
                return;
            }

            // There are no vendors in battlegrounds or dungeons !
            if (Styx.Logic.Battlegrounds.IsInsideBattleground || Me.IsInInstance)
            {
                return;
            }

            // First item in the list. We should check item by item so we don't end up buying the last item in the list with lower cost.
            var firstItem = BuyItemList.FirstOrDefault();

            // BuyItemList looks to be empty. Wait for user to populate the list
            if (firstItem == null)
            {
                return;
            }

            // Should check if we have enough currency.
            var currencyType = Enum.Parse(typeof(WoWCurrencyType), firstItem.ItemCostType);

            // Something went wrong with parsing. We should avoid buying that item.
            if (!(currencyType is WoWCurrencyType))
            {
                Slog("Couldn't parse item's cost type ({0}). Please consult to the plugin writer", firstItem.ItemCostType);
                BuyItemList.Remove(firstItem);

                return;
            }

            // Actually checking if we have enough of that currency now.
            var currency   = WoWCurrency.GetCurrencyByType((WoWCurrencyType)currencyType);
            var currencyJp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints);
            var currencyHp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints);

            if (currency == null)
            {
                return;
            }

            if (currency.Amount < firstItem.ItemCost)
            {
                // Don't ever buy justice points to buy honor points and vice versa. Otherwise we will enter in an endless loop which will drop
                // the total of our points.
                if (firstItem.ItemId != 392 && firstItem.ItemId != 395 && BuyOppositePointToBuildUp)
                {
                    if (currency.CurrencyType == WoWCurrencyType.JusticePoints && currencyHp.Amount >= 375)
                    {
                        // We set this to true here. So we don't end up spending all our honor points if the Only remove hp/jp points when capped is true
                        _forceAddedPoints = true;
                        if (Me.IsAlliance)
                        {
                            var buyJusticePoint = new BuyItemInfo
                            {
                                ItemCost       = 375,
                                ItemName       = "Justice Points",
                                ItemSupplierId = 52029,
                                ItemId         = 395,
                                ItemCostType   = WoWCurrencyType.HonorPoints.ToString()
                            };
                            Slog(
                                "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName);
                            BuyItemList.Insert(0, buyJusticePoint);
                        }
                        if (Me.IsHorde)
                        {
                            var buyJusticePoint = new BuyItemInfo
                            {
                                ItemCost       = 375,
                                ItemName       = "Justice Points",
                                ItemSupplierId = 52033,
                                ItemId         = 395,
                                ItemCostType   = WoWCurrencyType.HonorPoints.ToString()
                            };
                            Slog(
                                "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName);
                            BuyItemList.Insert(0, buyJusticePoint);
                        }
                    }
                    if (currency.CurrencyType == WoWCurrencyType.HonorPoints && currencyJp.Amount >= 375)
                    {
                        // We set this to true here. So we don't end up spending all our justice points if the Only remove hp/jp points when capped is true
                        _forceAddedPoints = true;
                        if (Me.IsAlliance)
                        {
                            var buyHonorPoint = new BuyItemInfo
                            {
                                ItemCost       = 375,
                                ItemName       = "Honor Points",
                                ItemSupplierId = 52028,
                                ItemId         = 392,
                                ItemCostType   = WoWCurrencyType.JusticePoints.ToString()
                            };
                            Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName);
                            BuyItemList.Insert(0, buyHonorPoint);
                        }
                        if (Me.IsHorde)
                        {
                            var buyHonorPoint = new BuyItemInfo
                            {
                                ItemCost       = 375,
                                ItemName       = "Honor Points",
                                ItemSupplierId = 52034,
                                ItemId         = 392,
                                ItemCostType   = WoWCurrencyType.JusticePoints.ToString()
                            };
                            Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName);
                            BuyItemList.Insert(0, buyHonorPoint);
                        }
                    }
                }
                return;
            }


            // We need to find the vendor
            var vendorAsUnit =
                ObjectManager.GetObjectsOfType <WoWUnit>(false, false).FirstOrDefault(
                    u => u.Entry == firstItem.ItemSupplierId);
            Vendor vendor;

            // Vendor is not around. This won't work
            if (vendorAsUnit == null)
            {
                // Check the database for the vendor as a second hope
                NpcResult npc = NpcQueries.GetNpcById(firstItem.ItemSupplierId);
                if (npc != null)
                {
                    vendor = new Vendor(npc.Entry, npc.Name, Vendor.VendorType.Unknown, npc.Location);
                }
                else
                {
                    Slog("Please move your toon close to the vendor. Otherwise HonorCap won't be able to buy items.");
                    return;
                }
            }
            else
            {
                vendor = new Vendor(vendorAsUnit, Vendor.VendorType.Unknown);
            }

            // Setting ItemToBuy here so VendorBehavior knows which item we want.
            ItemToBuy = firstItem;

            //We need to make sure vender is usable, so removing blacklist.
            if (Blacklist.Contains(vendorAsUnit))
            {
                Slog("For whatever reason vender is blacklisted, Clearing Blacklist.");
                Blacklist.Flush();
            }

            // Finally setting the poi
            BotPoi.Current = new BotPoi(vendor, PoiType.Buy);
        }