private GenericBuyInfo LookupDisplayObject(object obj) { IBuyItemInfo[] buyInfo = this.GetBuyInfo(); for (int i = 0; i < buyInfo.Length; ++i) { GenericBuyInfo gbi = buyInfo[i] as GenericBuyInfo; if (gbi.GetDisplayObject() == 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 (Core.Now - m_LastRestock > RestockDelay) { Restock(); } UpdateBuyInfo(); int count = 0; ArrayList list; IBuyItemInfo[] buyInfo = this.GetBuyInfo(); IShopSellInfo[] sellInfo = this.GetSellInfo(); list = new ArrayList(buyInfo.Length); Container cont = this.BuyPack; ArrayList opls = new ArrayList(); 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.GetDisplayObject() as IEntity; list.Add(new BuyItemState(buyItem.Name, cont.Serial, disp == null ? (Serial)0x7FC0FFEE : disp.Serial, buyItem.Price, buyItem.Amount, buyItem.ItemID, buyItem.Hue)); count++; if (disp is Item) { opls.Add((disp as Item).PropertyList); } else if (disp is Mobile) { opls.Add((disp as Mobile).PropertyList); } } ArrayList playerItems = cont.Items; for (int i = playerItems.Count - 1; i >= 0; --i) { if (i >= playerItems.Count) { continue; } Item item = (Item)playerItems[i]; if ((item.LastMoved + InventoryDecayTime) <= Core.Now) { item.Delete(); } } for (int i = 0; i < playerItems.Count; ++i) { Item 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++; 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); if (from.NetState == null) { return; } if (from.NetState.IsPost6017) { from.Send(new VendorBuyContent6017(list)); } else { from.Send(new VendorBuyContent(list)); } from.Send(new VendorBuyList(this, list)); from.Send(new DisplayBuyList(this)); from.Send(new MobileStatusExtended(from)); //make sure their gold amount is sent for (int i = 0; i < opls.Count; ++i) { from.Send(opls[i] as Packet); } SayTo(from, 500186); // Greetings. Have a look around. } }
public virtual void VendorBuy(Mobile from) { try { // adam: add new sanity checks if (from == null || from.NetState == null) return; if (!IsActiveSeller) return; if (!from.CheckAlive()) return; if (DateTime.Now - m_LastRestock > RestockDelay) Restock(); int count = 0; ArrayList list; // Adam: Catch the exception IBuyItemInfo[] buyInfo = null; try { buyInfo = this.GetBuyInfo(); } catch (Exception exc) { LogHelper.LogException(exc); System.Console.WriteLine("Error with GetBuyInfo() :: Please send output to Taran:"); System.Console.WriteLine(exc.Message); System.Console.WriteLine(exc.StackTrace); // if buyInfo is null, we can't continue throw new ApplicationException("Error with GetBuyInfo()"); } IShopSellInfo[] sellInfo = this.GetSellInfo(); list = new ArrayList(buyInfo.Length); Container cont = this.BuyPack; ArrayList opls = new ArrayList(); for (int idx = 0; idx < buyInfo.Length; idx++) { IBuyItemInfo buyItem = (IBuyItemInfo)buyInfo[idx]; if (buyItem.Amount <= 0 || list.Count >= 250) continue; if (ResourcePool.IsPooledResource(buyItem.Type)) { if (buyItem.Amount / 100 > 0) { Type bunchtype = ResourcePool.GetBunchType(buyItem.Type); if (bunchtype != null) { int price = buyItem.BunchPrice; int amount = (buyItem.Amount > 59900) ? 599 : buyItem.Amount / 100; GenericBuyInfo gbi = new GenericBuyInfo( bunchtype, price, amount, buyItem.ItemID, 0); IEntity disp = gbi.GetDisplayObject() as IEntity; //plasma: Implement city tax here, but only if the pool is empty (this prevents tax being applied to BBS sales) if (ResourcePool.GetTotalCount(buyItem.Type) == 0) { KinCityRegion kcr = KinCityRegion.GetKinCityAt(this); if (kcr != null && kcr.CityTaxRate > 0.0) { double tax = price * kcr.CityTaxRate; price += (int)Math.Floor(tax); } } list.Add(new BuyItemState(gbi.Name, cont.Serial, disp == null ? (Serial)0x7FC0FFEE : disp.Serial, gbi.Price, gbi.Amount, gbi.ItemID, gbi.Hue)); count++; opls.Add((disp as Item).PropertyList); } } if (buyItem.Amount % 100 > 0) { GenericBuyInfo gbi = (GenericBuyInfo)buyItem; IEntity disp = gbi.GetDisplayObject() as IEntity; int price = buyItem.Price; int amount = buyItem.Amount % 100; //plasma: Implement city tax here, but only if the pool is empty (this prevents tax being applied to BBS sales) if (ResourcePool.GetTotalCount(buyItem.Type) == 0) { KinCityRegion kcr = KinCityRegion.GetKinCityAt(this); if (kcr != null && kcr.CityTaxRate > 0.0) { double tax = price * kcr.CityTaxRate; price += (int)Math.Floor(tax); } } list.Add(new BuyItemState(buyItem.Name, cont.Serial, disp == null ? (Serial)0x7FC0FFEE : disp.Serial, price, amount, buyItem.ItemID, buyItem.Hue)); count++; if (disp is Item) opls.Add((disp as Item).PropertyList); else if (disp is Mobile) opls.Add((disp as Mobile).PropertyList); } } else { // NOTE: Only GBI supported; if you use another implementation of IBuyItemInfo, this will crash GenericBuyInfo gbi = (GenericBuyInfo)buyItem; IEntity disp = gbi.GetDisplayObject() as IEntity; //plasma: Implement city tax here KinCityRegion kcr = KinCityRegion.GetKinCityAt(this); int price = gbi.Price; if (kcr != null && kcr.CityTaxRate > 0.0) { double tax = buyItem.Price * kcr.CityTaxRate; price += (int)Math.Floor(tax); } list.Add(new BuyItemState(buyItem.Name, cont.Serial, disp == null ? (Serial)0x7FC0FFEE : disp.Serial, price, buyItem.Amount, buyItem.ItemID, buyItem.Hue)); count++; if (disp is Item) opls.Add((disp as Item).PropertyList); else if (disp is Mobile) opls.Add((disp as Mobile).PropertyList); } } ArrayList playerItems = cont.Items; for (int i = playerItems.Count - 1; i >= 0; --i) { if (i >= playerItems.Count) continue; Item item = (Item)playerItems[i]; if ((item.LastMoved + InventoryDecayTime) <= DateTime.Now) item.Delete(); } for (int i = 0; i < playerItems.Count; ++i) { Item 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++; 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); if (from.NetState == null) return; if (from.NetState.IsPost6017) from.Send(new VendorBuyContent6017(list)); else from.Send(new VendorBuyContent(list)); from.Send(new VendorBuyList(this, list)); from.Send(new DisplayBuyList(this)); from.Send(new MobileStatusExtended(from));//make sure their gold amount is sent for (int i = 0; i < opls.Count; ++i) from.Send(opls[i] as Packet); SayTo(from, 500186); // Greetings. Have a look around. } else SayTo(from, "I'm all out of stock. Please come back later."); // Added to deal with an empty buy list } catch (Exception exc) { LogHelper.LogException(exc); } }