Esempio n. 1
0
        private void MerchantMenuHandler_BuyItemWithQuantity(User user, Merchant merchant, ClientPacket packet)
        {
            string name = packet.ReadString8();
            string qStr = packet.ReadString8();


            if (!merchant.Inventory.ContainsKey(name))
            {
                user.ShowMerchantGoBack(merchant, "I do not sell that item.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            var template = merchant.Inventory[name];

            if (!template.Stackable) return;

            int quantity;
            if (!int.TryParse(qStr, out quantity) || quantity < 1)
            {
                user.ShowBuyMenuQuantity(merchant, name);
                return;
            }

            uint cost = (uint) (template.value*quantity);

            if (user.Gold < cost)
            {
                user.ShowMerchantGoBack(merchant, "You do not have enough gold.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (quantity > template.max_stack)
            {
                user.ShowMerchantGoBack(merchant, string.Format("You cannot hold that many {0}.", name),
                    MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.Inventory.Contains(name))
            {
                byte slot = user.Inventory.SlotOf(name);
                if (user.Inventory[slot].Count + quantity > template.max_stack)
                {
                    user.ShowMerchantGoBack(merchant, string.Format("You cannot hold that many {0}.", name),
                        MerchantMenuItem.BuyItemMenu);
                    return;
                }
                user.IncreaseItem(slot, quantity);
            }
            else
            {
                if (user.Inventory.IsFull)
                {
                    user.ShowMerchantGoBack(merchant, "You cannot carry any more items.", MerchantMenuItem.BuyItemMenu);
                    return;
                }

                var item = CreateItem(template.id, quantity);
                Insert(item);
                user.AddItem(item);
            }

            user.RemoveGold(cost);
            user.UpdateAttributes(StatUpdateFlags.Experience);
            user.ShowBuyMenu(merchant);
        }
Esempio n. 2
0
        private void MerchantMenuHandler_BuyItem(User user, Merchant merchant, ClientPacket packet)
        {
            string name = packet.ReadString8();

            if (!merchant.Inventory.ContainsKey(name))
            {
                user.ShowMerchantGoBack(merchant, "I do not sell that item.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            var template = merchant.Inventory[name];

            if (template.Stackable)
            {
                user.ShowBuyMenuQuantity(merchant, name);
                return;
            }

            if (user.Gold < template.value)
            {
                user.ShowMerchantGoBack(merchant, "You do not have enough gold.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.CurrentWeight + template.weight > user.MaximumWeight)
            {
                user.ShowMerchantGoBack(merchant, "That item is too heavy for you to carry.",
                    MerchantMenuItem.BuyItemMenu);
                return;
            }

            if (user.Inventory.IsFull)
            {
                user.ShowMerchantGoBack(merchant, "You cannot carry any more items.", MerchantMenuItem.BuyItemMenu);
                return;
            }

            user.RemoveGold((uint) template.value);

            var item = CreateItem(template.id);
            Insert(item);
            user.AddItem(item);

            user.UpdateAttributes(StatUpdateFlags.Experience);
            user.ShowBuyMenu(merchant);
        }