Exemple #1
0
        public PlayerVendorBuyGump(Mobile from, PlayerVendor vendor, VendorItem vi) : base(100, 200)
        {
            m_Vendor = vendor;
            m_VI     = vi;

            AddBackground(100, 10, 300, 150, 5054);

            AddHtmlLocalized(125, 20, 250, 24, 1019070, false, false);               // You have agreed to purchase:

            if (!String.IsNullOrEmpty(vi.Description))
            {
                AddLabel(125, 45, 0, vi.Description);
            }
            else
            {
                AddHtmlLocalized(125, 45, 250, 24, 1019072, false, false);           // an item without a description
            }
            AddHtmlLocalized(125, 70, 250, 24, 1019071, false, false);               // for the amount of:
            AddLabel(125, 95, 0, vi.GetPrice(from, vendor).ToString());

            AddButton(250, 130, 4005, 4007, 0, GumpButtonType.Reply, 0);
            AddHtmlLocalized(282, 130, 100, 24, 1011012, false, false);               // CANCEL

            AddButton(120, 130, 4005, 4007, 1, GumpButtonType.Reply, 0);
            AddHtmlLocalized(152, 130, 100, 24, 1011036, false, false);               // OKAY
        }
Exemple #2
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            if (!m_Vendor.CanInteractWith(from, false))
            {
                return;
            }

            if (m_Vendor.IsOwner(from))
            {
                m_Vendor.SayTo(from, 503212);                   // You own this shop, just take what you want.
                return;
            }

            if (info.ButtonID == 1)
            {
                m_Vendor.Say(from.Name);

                if (!m_VI.Valid || !m_VI.Item.IsChildOf(m_Vendor.Backpack))
                {
                    m_Vendor.SayTo(from, 503216);                       // You can't buy that.
                    return;
                }

                int totalGold = 0;
                int price     = m_VI.GetPrice(from, m_Vendor);

                Item[] items = from.Backpack.FindItemsByType(typeof(Gold), true);

                for (int i = 0; i < items.Length; ++i)
                {
                    Item item = items[i];
                    if (item.LootType != LootType.Newbied && item.Movable)
                    {
                        totalGold += items[i].Amount;
                    }
                }

                //if ( from.Backpack != null )
                //	totalGold += from.Backspack.GetAmount( typeof( Gold ) );

                totalGold += Banker.GetBalance(from);

                if (totalGold < price)
                {
                    m_Vendor.SayTo(from, 503205);                       // You cannot afford this item.
                }
                else if (!from.PlaceInBackpack(m_VI.Item))
                {
                    m_Vendor.SayTo(from, 503204);                       // You do not have room in your backpack for this.
                }
                else
                {
                    int leftPrice = price;

                    if (from.Backpack != null)
                    {
                        leftPrice -= from.Backpack.ConsumeUpTo(typeof(Gold), leftPrice);
                    }

                    if (leftPrice > 0)
                    {
                        Banker.Withdraw(from, leftPrice);
                    }

                    m_Vendor.HoldGold += price;
                    from.SendLocalizedMessage(503201);                       // You take the item.
                }
            }
            else
            {
                from.SendLocalizedMessage(503207);                   // Cancelled purchase.
            }
        }