Server.Mobiles.BaseVendor.VendorBuy C# (CSharp) Méthode

VendorBuy() public méthode

public VendorBuy ( Mobile from ) : void
from Mobile
Résultat void
        public virtual void VendorBuy( Mobile from )
        {
            if ( !IsActiveSeller )
                return;

            if ( !from.CheckAlive() )
                return;

            if ( !CheckVendorAccess( from ) )
            {
                Say( 501522 ); // I shall not treat with scum like thee!
                return;
            }

            if ( DateTime.UtcNow - m_LastRestock > RestockDelay )
                Restock();

            UpdateBuyInfo();

            int count = 0;
            List<BuyItemState> list;
            IBuyItemInfo[] buyInfo = this.GetBuyInfo();
            IShopSellInfo[] sellInfo = this.GetSellInfo();

            list = new List<BuyItemState>( buyInfo.Length );
            Container cont = this.BuyPack;

            List<ObjectPropertyList> opls = null;

            for ( int idx = 0; idx < buyInfo.Length; idx++ )
            {
                IBuyItemInfo buyItem = (IBuyItemInfo)buyInfo[idx];

                if ( buyItem.Amount <= 0 || list.Count >= 250 )
                    continue;

                // NOTE: Only GBI supported; if you use another implementation of IBuyItemInfo, this will crash
                GenericBuyInfo gbi = (GenericBuyInfo)buyItem;
                IEntity disp = gbi.GetDisplayEntity();

                list.Add( new BuyItemState( buyItem.Name, cont.Serial, disp == null ? (Serial)0x7FC0FFEE : disp.Serial, buyItem.Price, buyItem.Amount, buyItem.ItemID, buyItem.Hue ) );
                count++;

                if ( opls == null ) {
                    opls = new List<ObjectPropertyList>();
                }

                if ( disp is Item ) {
                    opls.Add( ( ( Item ) disp ).PropertyList );
                } else if ( disp is Mobile ) {
                    opls.Add( ( ( Mobile ) disp ).PropertyList );
                }
            }

            List<Item> playerItems = cont.Items;

            for ( int i = playerItems.Count - 1; i >= 0; --i )
            {
                if ( i >= playerItems.Count )
                    continue;

                Item item = playerItems[i];

                if ( ( item.LastMoved + InventoryDecayTime ) <= DateTime.UtcNow )
                    item.Delete();
            }

            for ( int i = 0; i < playerItems.Count; ++i )
            {
                Item item = playerItems[i];

                int price = 0;
                string name = null;

                foreach ( IShopSellInfo ssi in sellInfo )
                {
                    if ( ssi.IsSellable( item ) )
                    {
                        price = ssi.GetBuyPriceFor( item );
                        name = ssi.GetNameFor( item );
                        break;
                    }
                }

                if ( name != null && list.Count < 250 )
                {
                    list.Add( new BuyItemState( name, cont.Serial, item.Serial, price, item.Amount, item.ItemID, item.Hue ) );
                    count++;

                    if ( opls == null ) {
                        opls = new List<ObjectPropertyList>();
                    }

                    opls.Add( item.PropertyList );
                }
            }

            //one (not all) of the packets uses a byte to describe number of items in the list.  Osi = dumb.
            //if ( list.Count > 255 )
            //	Console.WriteLine( "Vendor Warning: Vendor {0} has more than 255 buy items, may cause client errors!", this );

            if ( list.Count > 0 )
            {
                list.Sort( new BuyItemStateComparer() );

                SendPacksTo( from );

                NetState ns = from.NetState;

                if ( ns == null )
                    return;

                if ( ns.ContainerGridLines )
                    from.Send( new VendorBuyContent6017( list ) );
                else
                    from.Send( new VendorBuyContent( list ) );

                from.Send( new VendorBuyList( this, list ) );

                if ( ns.HighSeas )
                    from.Send( new DisplayBuyListHS( this ) );
                else
                    from.Send( new DisplayBuyList( this ) );

                from.Send( new MobileStatusExtended( from ) );//make sure their gold amount is sent

                if ( opls != null ) {
                    for ( int i = 0; i < opls.Count; ++i ) {
                        from.Send( opls[i] );
                    }
                }

                SayTo( from, 500186 ); // Greetings.  Have a look around.
            }
        }

Usage Example

Exemple #1
0
        // Temporary
        public override void OnSpeech(SpeechEventArgs e)
        {
            base.OnSpeech(e);

            Mobile from = e.Mobile;

            BaseVendor vendor = m_Mobile as BaseVendor;

            if (m_Mobile is BaseVendor && from.InRange(m_Mobile, m_Mobile.EraAOS ? 1 : 4) && !e.Handled)
            {
                if (e.HasKeyword(0x14D))                     // *vendor sell*
                {
                    e.Handled = true;

                    vendor.VendorSell(from);
                    m_Mobile.FocusMob = from;
                }
                else if (e.HasKeyword(0x3C))
                {
                    e.Handled = true;

                    vendor.VendorBuy(from);
                    m_Mobile.FocusMob = from;
                }
                else if (WasNamed(e.Speech))
                {
                    e.Handled = true;

                    if (e.HasKeyword(0x177))                         // *sell*
                    {
                        vendor.VendorSell(from);
                    }
                    else if (e.HasKeyword(0x171))                         // *buy*
                    {
                        vendor.VendorBuy(from);
                    }

                    m_Mobile.FocusMob = from;
                }
            }
        }