Beispiel #1
0
 static bool hasEnoughGold(BuildItem item)
 {
     return(ObjectManager.Player.Gold >= ItemController.GetItemCost(item.Id));
 }
Beispiel #2
0
        public static void BuyOrSellItems()
        {
            if (CurrentBuild == null)
            {
                return;
            }
            count++;
            if (count < randomNumber)
            {
                return;
            }
            count        = 0;
            randomNumber = new Random().Next(25, 50);
            //
            if (CurrentBuild.Items.Count != 0)
            {
                var buildItem = CurrentBuild.Items[0];
                if (buildItem != null)
                {
                    if (buildItem.Sell)
                    {
                        ItemController.SellItemId(buildItem.Id);
                        Chat.Print("Sold item: " + buildItem.Name);
                        CurrentBuild.Items.Remove(buildItem);
                    }
                    else
                    {
                        if (Item.HasItem(buildItem.Id, ObjectManager.Player))
                        {
                            lock (CurrentBuild.Items)
                            {
                                Chat.Print("Already had item: " + buildItem.Name);
                                Chat.Print("Removing item:" + CurrentBuild.Items[0].Name);
                                CurrentBuild.Items.RemoveAt(0);
                                Chat.Print("Items to buy count: " + CurrentBuild.Items.Count);
                            }
                        }
                        else
                        {
                            if (hasEnoughGold(buildItem))
                            {
                                ItemController.BuyItemId(buildItem.Id);
                                Chat.Print("Bought item: " + buildItem.Name);
                                lock (CurrentBuild.Items)
                                {
                                    Chat.Print("Removing item:" + CurrentBuild.Items[0].Name);
                                    CurrentBuild.Items.RemoveAt(0);
                                    Chat.Print("Items to buy count: " + CurrentBuild.Items.Count);
                                }
                            }
                            else
                            {
                                if (buildItem.BuildFrom.Count != 0)
                                {
                                    var itemToBuy = buildItem.BuildFrom[0];
                                    if (itemToBuy.BuildFrom.Count != 0)
                                    {
                                        var tmp = itemToBuy.BuildFrom[0];
                                        if (hasEnoughGold(tmp))
                                        {
                                            lock (itemToBuy.BuildFrom)
                                            {
                                                Chat.Print("Removed sub sub item:: " + tmp.Name);
                                                itemToBuy.BuildFrom.RemoveAt(0);
                                            }
                                            //Buy tmp
                                            ItemController.BuyItemId(tmp.Id);
                                            Chat.Print("Bought sub sub item: " + tmp.Name);
                                        }
                                    }
                                    else
                                    {
                                        if (hasEnoughGold(itemToBuy))
                                        {
                                            lock (itemToBuy.BuildFrom)
                                            {
                                                Chat.Print("Removed sub item: " + itemToBuy.Name);
                                                buildItem.BuildFrom.RemoveAt(0);

                                                ItemController.BuyItemId(itemToBuy.Id);
                                                Chat.Print("Bought sub item: " + itemToBuy.Name);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            PotionController.BuyOrSellPotions();
        }