示例#1
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            if (m_Vendor.Deleted)
            {
                return;
            }

            Mobile from = state.Mobile;

            from.CloseGump(typeof(PlayerVendorBuyGump));

            if (info.ButtonID == 2)
            {
                if (m_VI.IsForSale && m_Item.RootParent == m_Vendor)
                {
                    m_Vendor.Say(from.Name);

                    Container pack = from.Backpack;

                    if ((pack != null && pack.ConsumeTotal(typeof(Gold), m_VI.Price)) || from.BankBox.ConsumeTotal(typeof(Gold), m_VI.Price))
                    {
                        int price = m_VI.Price;
                        m_Vendor.HoldGold += price;
                        m_Vendor.RemoveInfo(m_Item);

                        if (pack == null || !pack.TryDropItem(from, m_Item, false))
                        {
                            m_Vendor.SayTo(from, 503204);                             // You do not have room in your backpack for this.
                            m_Item.MoveToWorld(from.Location, from.Map);
                        }

                        // charge our N% commission AFTER the customer gets their goods (in case the comission charge causes the vendor to die.)
                        if (m_Vendor.PricingModel == PricingModel.Commission)
                        {
                            m_Vendor.Charge((int)(price * m_Vendor.Commission), PlayerVendor.ChargeReason.Commission);
                        }
                    }
                    else
                    {
                        m_Vendor.SayTo(from, 503205);                         // You cannot afford this item.
                    }
                }
                else
                {
                    m_Vendor.SayTo(from, 503216);                     // You can't buy that.
                }
            }
        }