private GenericBuyInfo LookupDisplayObject(object obj) { IBuyItemInfo[] buyInfo = this.GetBuyInfo(); for (int i = 0; i < buyInfo.Length; ++i) { GenericBuyInfo gbi = (GenericBuyInfo)buyInfo[i]; if (gbi.GetDisplayEntity() == obj) { return(gbi); } } return(null); }
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.Now - m_LastRestock > RestockDelay) { Restock(); } 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.Now) { 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. } }
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(); } 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; } 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); } } 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)); if (opls != null) { for (int i = 0; i < opls.Count; ++i) { from.Send(opls[i]); } } SayTo(from, 500186); // Greetings. Have a look around. } }