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

OnBuyItems() public méthode

public OnBuyItems ( Mobile buyer, List list ) : bool
buyer Mobile
list List
Résultat bool
        public virtual bool OnBuyItems( Mobile buyer, List<BuyItemResponse> list )
        {
            if ( !IsActiveSeller )
                return false;

            if ( !buyer.CheckAlive() )
                return false;

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

            UpdateBuyInfo();

            IBuyItemInfo[] buyInfo = this.GetBuyInfo();
            IShopSellInfo[] info = GetSellInfo();
            int totalCost = 0;
            List<BuyItemResponse> validBuy = new List<BuyItemResponse>( list.Count );
            Container cont;
            bool bought = false;
            bool fromBank = false;
            bool fullPurchase = true;
            int controlSlots = buyer.FollowersMax - buyer.Followers;

            foreach ( BuyItemResponse buy in list )
            {
                Serial ser = buy.Serial;
                int amount = buy.Amount;

                if ( ser.IsItem )
                {
                    Item item = World.FindItem( ser );

                    if ( item == null )
                        continue;

                    GenericBuyInfo gbi = LookupDisplayObject( item );

                    if ( gbi != null )
                    {
                        ProcessSinglePurchase( buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost );
                    }
                    else if ( item != this.BuyPack && item.IsChildOf( this.BuyPack ) )
                    {
                        if ( amount > item.Amount )
                            amount = item.Amount;

                        if ( amount <= 0 )
                            continue;

                        foreach ( IShopSellInfo ssi in info )
                        {
                            if ( ssi.IsSellable( item ) )
                            {
                                if ( ssi.IsResellable( item ) )
                                {
                                    totalCost += ssi.GetBuyPriceFor( item ) * amount;
                                    validBuy.Add( buy );
                                    break;
                                }
                            }
                        }
                    }
                }
                else if ( ser.IsMobile )
                {
                    Mobile mob = World.FindMobile( ser );

                    if ( mob == null )
                        continue;

                    GenericBuyInfo gbi = LookupDisplayObject( mob );

                    if ( gbi != null )
                        ProcessSinglePurchase( buy, gbi, validBuy, ref controlSlots, ref fullPurchase, ref totalCost );
                }
            }//foreach

            if ( fullPurchase && validBuy.Count == 0 )
                SayTo( buyer, 500190 ); // Thou hast bought nothing!
            else if ( validBuy.Count == 0 )
                SayTo( buyer, 500187 ); // Your order cannot be fulfilled, please try again.

            if ( validBuy.Count == 0 )
                return false;

            bought = ( buyer.AccessLevel >= AccessLevel.GameMaster );

            cont = buyer.Backpack;
            if ( !bought && cont != null )
            {
                if ( cont.ConsumeTotal( typeof( Gold ), totalCost ) )
                    bought = true;
                else if ( totalCost < 2000 )
                    SayTo( buyer, 500192 ); // Begging thy pardon, but thou canst not afford that.
            }

            if ( !bought && totalCost >= 2000 )
            {
                cont = buyer.FindBankNoCreate();
                if ( cont != null && cont.ConsumeTotal( typeof( Gold ), totalCost ) )
                {
                    bought = true;
                    fromBank = true;
                }
                else
                {
                    SayTo( buyer, 500191 ); //Begging thy pardon, but thy bank account lacks these funds.
                }
            }

            if ( !bought )
                return false;
            else
                buyer.PlaySound( 0x32 );

            cont = buyer.Backpack;
            if ( cont == null )
                cont = buyer.BankBox;

            foreach ( BuyItemResponse buy in validBuy )
            {
                Serial ser = buy.Serial;
                int amount = buy.Amount;

                if ( amount < 1 )
                    continue;

                if ( ser.IsItem )
                {
                    Item item = World.FindItem( ser );

                    if ( item == null )
                        continue;

                    GenericBuyInfo gbi = LookupDisplayObject( item );

                    if ( gbi != null )
                    {
                        ProcessValidPurchase( amount, gbi, buyer, cont );
                    }
                    else
                    {
                        if ( amount > item.Amount )
                            amount = item.Amount;

                        foreach ( IShopSellInfo ssi in info )
                        {
                            if ( ssi.IsSellable( item ) )
                            {
                                if ( ssi.IsResellable( item ) )
                                {
                                    Item buyItem;
                                    if ( amount >= item.Amount )
                                    {
                                        buyItem = item;
                                    }
                                    else
                                    {
                                        buyItem = Mobile.LiftItemDupe( item, item.Amount - amount );

                                        if ( buyItem == null )
                                            buyItem = item;
                                    }

                                    if ( cont == null || !cont.TryDropItem( buyer, buyItem, false ) )
                                        buyItem.MoveToWorld( buyer.Location, buyer.Map );

                                    break;
                                }
                            }
                        }
                    }
                }
                else if ( ser.IsMobile )
                {
                    Mobile mob = World.FindMobile( ser );

                    if ( mob == null )
                        continue;

                    GenericBuyInfo gbi = LookupDisplayObject( mob );

                    if ( gbi != null )
                        ProcessValidPurchase( amount, gbi, buyer, cont );
                }
            }//foreach

            if ( fullPurchase )
            {
                if ( buyer.AccessLevel >= AccessLevel.GameMaster )
                    SayTo( buyer, true, "I would not presume to charge thee anything.  Here are the goods you requested." );
                else if ( fromBank )
                    SayTo(buyer, 1151638, totalCost.ToString());//The total of your purchase is ~1_val~ gold, which has been drawn from your bank account.  My thanks for the patronage.
                else
                    SayTo(buyer, 1151639, totalCost.ToString());//The total of your purchase is ~1_val~ gold.  My thanks for the patronage.
            }
            else
            {
                if ( buyer.AccessLevel >= AccessLevel.GameMaster )
                    SayTo( buyer, true, "I would not presume to charge thee anything.  Unfortunately, I could not sell you all the goods you requested." );
                else if ( fromBank )
                    SayTo( buyer, true, "The total of thy purchase is {0} gold, which has been withdrawn from your bank account.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.", totalCost );
                else
                    SayTo( buyer, true, "The total of thy purchase is {0} gold.  My thanks for the patronage.  Unfortunately, I could not sell you all the goods you requested.", totalCost );
            }

            return true;
        }