Ejemplo n.º 1
0
        public static WoWCurrency GetCurrencyInfo(int entry)
        {
            string randomString = Others.GetRandomString(Others.Random(5, 10));
            string result       = Lua.LuaDoString(
                randomString + " = \"\"; " +
                "local name, currentAmount, texture, earnedThisWeek, weeklyMax, totalMax, isDiscovered = GetCurrencyInfo(" + entry + "); " +
                randomString +
                " = tostring(name) .. \"##\" .. tostring(currentAmount) .. \"##\" .. tostring(texture) .. \"##\" .. tostring(earnedThisWeek)  .. \"##\" .. tostring(weeklyMax)  .. \"##\" .. tostring(totalMax)  .. \"##\" .. tostring(isDiscovered);"
                , randomString);

            if (!string.IsNullOrWhiteSpace(result))
            {
                string[] ar      = { "##" };
                string[] slipped = result.Split(ar, StringSplitOptions.None);
                if (slipped.Length == 6)
                {
                    var tmp = new WoWCurrency
                    {
                        Entry          = entry,
                        Name           = slipped[0],
                        CurrentAmount  = Others.ToInt32(slipped[1]),
                        FileId         = Others.ToInt32(slipped[2]),
                        EarnedThisWeek = Others.ToInt32(slipped[3]),
                        WeeklyMax      = Others.ToInt32(slipped[4]),
                        TotalMax       = Others.ToInt32(slipped[5]),
                        IsDiscovered   = Others.ToBoolean(slipped[6])
                    };
                    return(tmp);
                }
            }
            return(new WoWCurrency());
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public override void Pulse()
        {
            if (!lockTimer.IsFinished)
            {
                return;
            }
            lockTimer.Reset(); // Lock pulse for a while. Deal with lua events.



            // Simple stop pulse.
            if (
                currentlyCheckingItemUpgrades ||                         // currentlyCheckingItemUpgrades is important lock.
                !Me.IsAlive ||                                           // Skip if not alive.
                (Battlegrounds.IsInsideBattleground || Me.IsInInstance)) // Skip if in bg / instance.
            {
                return;
            }



            WoWUnit vendorunit = null;

            uint[] vendorIds = (Me.IsAlliance ? ID_ALLIANCE_VENDORS : ID_HORDE_VENDORS);
            foreach (uint vendorId in vendorIds)
            {
                if (vendorunit == null)
                {
                    vendorunit = ObjectManager.GetObjectsOfType <WoWUnit>(false, false).FirstOrDefault(
                        u => u.Entry == vendorId
                        );
                }
            }


            if (vendorunit == null)
            {
                if (!errorNotNearVendorExplained)
                {
                    errorNotNearVendorExplained = true;
                    SError("Not buying item upgrades, you are not near {0} NPC ID: #{1} . See http://www.wowhead.com/npc={1} for location.", (Me.IsAlliance ? "Alliance" : "Horde"), vendorIds[0]);
                }
                return;
            }


            if ((vendorunit != null && !vendorunit.WithinInteractRange))
            {
                Styx.Pathing.Navigator.MoveTo(vendorunit.Location);
                return;
            }


            // Cache some values
            items = Me.CarriedItems;
            // Order by highest ilevel first, since thats the items we want to upgrade first.
            items.OrderByDescending(item => item != null ? item.ItemInfo.Level : 0);
            currentHonor    = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints);
            currentConquest = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints);
            currentJustice  = WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints);
            currentValor    = WoWCurrency.GetCurrencyByType(WoWCurrencyType.ValorPoints);


            uint previousItem = currentItem == null ? 0 : currentItem.ItemInfo.Id;

            currentItem = getBuyItemUpgradeOnItem();

            if (currentItem == null)
            {
                return;
            }


            vendorunit.Interact();
        }
Ejemplo n.º 4
0
        public override void Pulse()
        {
            if (!lockTimer.IsFinished)
                return;
            lockTimer.Reset(); // Lock pulse for a while. Deal with lua events.

            // Simple stop pulse.
            if (
                currentlyCheckingItemUpgrades || // currentlyCheckingItemUpgrades is important lock.
                !Me.IsAlive || // Skip if not alive.
                (Battlegrounds.IsInsideBattleground || Me.IsInInstance)) // Skip if in bg / instance.
            {
                return;
            }

            WoWUnit vendorunit = null;
            uint[] vendorIds = (Me.IsAlliance ? ID_ALLIANCE_VENDORS : ID_HORDE_VENDORS);
            foreach (uint vendorId in vendorIds)
            {
                if (vendorunit == null)
                {
                    vendorunit = ObjectManager.GetObjectsOfType<WoWUnit>(false, false).FirstOrDefault(
                        u => u.Entry == vendorId
                    );
                }
            }

            if (vendorunit == null)
            {
                if (!errorNotNearVendorExplained)
                {
                    errorNotNearVendorExplained = true;
                    SError("Not buying item upgrades, you are not near {0} NPC ID: #{1} . See http://www.wowhead.com/npc={1} for location.", (Me.IsAlliance ? "Alliance" : "Horde"), vendorIds[0]);
                }
                return;
            }

            if ((vendorunit != null && !vendorunit.WithinInteractRange))
            {
                Styx.Pathing.Navigator.MoveTo(vendorunit.Location);
                return;
            }

            // Cache some values
            items = Me.CarriedItems;
            // Order by highest ilevel first, since thats the items we want to upgrade first.
            items.OrderByDescending(item => item != null ? item.ItemInfo.Level : 0);
            currentHonor = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints);
            currentConquest = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints);
            currentJustice = WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints);
            currentValor = WoWCurrency.GetCurrencyByType(WoWCurrencyType.ValorPoints);

            uint previousItem = currentItem == null ? 0 : currentItem.ItemInfo.Id;
            currentItem = getBuyItemUpgradeOnItem();

            if (currentItem == null)
            {
                return;
            }

            vendorunit.Interact();
        }
Ejemplo n.º 5
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);
        }