private void ProcessSinglePurchase(BuyItemResponse buy, IBuyItemInfo bii, List <BuyItemResponse> validBuy, ref int controlSlots, ref bool fullPurchase, ref int totalCost) { int amount = buy.Amount; if (amount > bii.Amount) { amount = bii.Amount; } if (amount <= 0) { return; } int slots = bii.ControlSlots * amount; if (controlSlots >= slots) { controlSlots -= slots; } else { fullPurchase = false; return; } totalCost += bii.Price * amount; validBuy.Add(buy); }
protected override void OnItemReceived(Mobile buyer, Item item, IBuyItemInfo buy) { base.OnItemReceived(buyer, item, buy); if (buyer != null && item != null && !item.Deleted) { ++Sold; } }
protected virtual void OnItemReceived(Mobile buyer, Item item, IBuyItemInfo buy) { if (buy is DynamicBuyInfo) { item.Movable = true; if (item is Container) { foreach (var o in ((Container)item).FindItemsByType <Item>(true, o => !o.Movable)) { o.Movable = true; } } } }
private void ProcessSinglePurchase(BuyItemResponse buy, IBuyItemInfo bii, List <BuyItemResponse> validBuy, ref bool fullPurchase, ref int totalCost) { int amount = buy.Amount; if (amount > bii.Amount) { amount = bii.Amount; } if (amount <= 0) { return; } totalCost += bii.Price * amount; validBuy.Add(buy); }
private void ProcessSinglePurchase( BuyItemResponse buy, IBuyItemInfo bii, ICollection<BuyItemResponse> validBuy, ref int controlSlots, ref bool fullPurchase, ref int totalCost) { if (!Trading || TokenType == null || !TokenType.IsNotNull) { return; } int amount = buy.Amount; if (amount > bii.Amount) { amount = bii.Amount; } if (amount <= 0) { return; } int slots = bii.ControlSlots * amount; if (controlSlots >= slots) { controlSlots -= slots; } else { fullPurchase = false; return; } totalCost += bii.Price * amount; validBuy.Add(buy); }
private void ProcessSinglePurchase( BuyItemResponse buy, IBuyItemInfo bii, ICollection <BuyItemResponse> validBuy, ref int controlSlots, ref bool fullPurchase, ref int totalCost) { if (!Trading || CashType == null || !CashType.IsNotNull) { return; } var amount = buy.Amount; if (amount > bii.Amount) { amount = bii.Amount; } if (amount <= 0) { return; } var slots = bii.ControlSlots * amount; if (controlSlots >= slots) { controlSlots -= slots; } else { fullPurchase = false; return; } totalCost += bii.Price * amount; validBuy.Add(buy); }
private void ProcessSinglePurchase( BuyItemResponse buy, IBuyItemInfo bii, List<BuyItemResponse> validBuy, ref int controlSlots, ref bool fullPurchase, ref int totalCost ) { int amount = buy.Amount; if ( amount > bii.Amount ) amount = bii.Amount; if ( amount <= 0 ) return; int slots = bii.ControlSlots * amount; if ( controlSlots >= slots ) { controlSlots -= slots; } else { fullPurchase = false; return; } totalCost += bii.Price * amount; validBuy.Add( buy ); }
private void ProcessValidPurchase(int amount, IBuyItemInfo bii, Mobile buyer, Container cont) { if (!Trading || CashType == null || !CashType.IsNotNull) { return; } if (amount > bii.Amount) { amount = bii.Amount; } if (amount < 1) { return; } bii.Amount -= amount; var o = bii.GetEntity(); if (o is Item) { var item = (Item)o; if (item.Stackable) { item.Amount = amount; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } else { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } for (var i = 1; i < amount; i++) { item = bii.GetEntity() as Item; if (item == null) { continue; } item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } } } else if (o is Mobile) { var m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); m.PlaySound(m.GetIdleSound()); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } for (var i = 1; i < amount; ++i) { m = bii.GetEntity() as Mobile; if (m == null) { continue; } m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } } } }
public int GetSellPriceFor(Item item, BaseVendor vendor) { int price; m_Table.TryGetValue(item.GetType(), out price); if (vendor != null && BaseVendor.UseVendorEconomy) { IBuyItemInfo buyInfo = null; var infos = vendor.GetBuyInfo(); for (var index = 0; index < infos.Length; index++) { IBuyItemInfo info = infos[index]; if (info is GenericBuyInfo gbi && gbi.EconomyItem && gbi.Type == item.GetType()) { buyInfo = gbi; break; } } if (buyInfo != null) { int sold = buyInfo.TotalSold; price = (int)(buyInfo.Price * .75); return(Math.Max(1, price)); } } if (item is BaseArmor armor) { if (armor.Quality == ItemQuality.Low) { price = (int)(price * 0.60); } else if (armor.Quality == ItemQuality.Exceptional) { price = (int)(price * 1.25); } price += 5 * armor.ArmorAttributes.DurabilityBonus; if (price < 1) { price = 1; } } else if (item is BaseWeapon weapon) { if (weapon.Quality == ItemQuality.Low) { price = (int)(price * 0.60); } else if (weapon.Quality == ItemQuality.Exceptional) { price = (int)(price * 1.25); } price += 100 * weapon.WeaponAttributes.DurabilityBonus; price += 10 * weapon.Attributes.WeaponDamage; if (price < 1) { price = 1; } } else if (item is BaseBeverage bev) { int price1 = price, price2 = price; if (bev is Pitcher) { price1 = 3; price2 = 5; } else if (bev is BeverageBottle) { price1 = 3; price2 = 3; } else if (bev is Jug) { price1 = 6; price2 = 6; } if (bev.IsEmpty || bev.Content == BeverageType.Milk) { price = price1; } else { price = price2; } } return(price); }
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. } }
protected virtual void OnMobileReceived(Mobile buyer, Mobile mob, IBuyItemInfo buy) { }
private static void ProcessValidPurchase(int amount, IBuyItemInfo bii, Mobile buyer, Container cont) { if (amount > bii.Amount) { amount = bii.Amount; } if (amount < 1) { return; } bii.Amount -= amount; IEntity o = bii.GetEntity(); if (o is Item) { var item = (Item)o; if (item.Stackable) { item.Amount = amount; if (cont is BankBox) { buyer.LocalOverheadMessage( MessageType.Regular, 0x38, false, "Given the cost of the items, they will be delivered to your bank."); } if (cont == null || !cont.TryDropItem(buyer, item, false)) { // try to put it in the bank cont = buyer.BankBox; if (cont == null || !cont.TryDropItem(buyer, item, false)) { //buyer.SendMessage(38, "You don't have enough room for that in your pack OR in your bank. It has been placed on the ground!"); buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "You don't have enough room for that in your pack OR in your bank. It has been placed on the ground!"); item.MoveToWorld(buyer.Location, buyer.Map); } else { //buyer.SendMessage(0x38, "Since you could not carry the item, it has been delivered to your bank."); buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "Since you could not carry the item, it has been delivered to your bank."); } } } else { item.Amount = 1; if (cont is BankBox) { buyer.LocalOverheadMessage( MessageType.Regular, 0x38, false, "Given the cost of the items, they will be delivered to your bank."); } if (cont == null || !cont.TryDropItem(buyer, item, false)) { // try to put it in the bank cont = buyer.BankBox; if (cont == null || !cont.TryDropItem(buyer, item, false)) { buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "You don't have enough room for that in your pack OR in your bank. It has been placed on the ground!"); //buyer.SendMessage(38, ); item.MoveToWorld(buyer.Location, buyer.Map); } else { buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "Since you could not carry the item, it has been delivered to your bank."); //buyer.SendMessage(0x38, "Since you could not carry the item, it has been delivered to your bank."); } } for (int i = 1; i < amount; i++) { item = bii.GetEntity() as Item; if (item == null) { continue; } item.Amount = 1; if (cont != null && cont.TryDropItem(buyer, item, false)) { continue; } // try to put it in the bank cont = buyer.BankBox; if (cont == null || !cont.TryDropItem(buyer, item, false)) { //buyer.SendMessage(38, "You don't have enough room for that in your pack OR in your bank. It has been placed on the ground!"); buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "You don't have enough room for that in your pack OR in your bank. It has been placed on the ground!"); item.MoveToWorld(buyer.Location, buyer.Map); } else { //buyer.SendMessage(0x38, "Since you could not carry the item, it has been delivered to your bank."); buyer.LocalOverheadMessage( MessageType.Regular, 38, false, "Since you could not carry the item, it has been delivered to your bank."); } } if (item is BaseBoatDeed && buyer is PlayerMobile) { Timer.DelayCall(TimeSpan.FromSeconds(3.0), ((PlayerMobile)buyer).BoatDeedWarning); } } } else if (o is Mobile) { var m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); m.PlaySound(m.GetIdleSound()); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } for (int i = 1; i < amount; ++i) { m = bii.GetEntity() as Mobile; if (m == null) { continue; } m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } } } }
//public virtual bool OnBuyItems( Mobile buyer, ArrayList list ) public virtual bool OnBuyItems(Mobile buyer, System.Collections.Generic.List <BuyItemResponse> list) { if (!IsActiveSeller) { return(false); } if (!buyer.CheckAlive()) { return(false); } IBuyItemInfo[] buyInfo = this.GetBuyInfo(); IShopSellInfo[] info = GetSellInfo(); int totalCost = 0; ArrayList validBuy = new ArrayList(list.Count); Container cont; bool bought = false; bool fromBank = false; bool fullPurchase = true; int controlSlots = buyer.FollowersMax - buyer.Followers; double discount = GetBuyDiscountFor(buyer); foreach (BuyItemResponse buy in list) { Serial ser = 0x7FFFFEFF - buy.Serial; int amount = buy.Amount; if (ser >= 0 && ser <= buyInfo.Length) { IBuyItemInfo bii = buyInfo[ser]; if (amount > bii.Amount) { amount = bii.Amount; } if (amount <= 0) { continue; } /*int slots = bii.ControlSlots * amount; * * if ( controlSlots >= slots ) * { * controlSlots -= slots; * } * else * { * fullPurchase = false; * continue; * }*/ int price = (int)Math.Round(bii.Price * discount); if (price < 1) { price = 1; } totalCost += price * amount; validBuy.Add(buy); } else { Item item = World.FindItem(buy.Serial); if (item == null || item.RootParent != this) { continue; } if (amount > item.Amount) { amount = item.Amount; } if (amount <= 0) { continue; } foreach (IShopSellInfo ssi in info) { if (ssi.IsSellable(item)) { if (ssi.IsResellable(item)) { int price = (int)Math.Round(ssi.GetBuyPriceFor(item) * discount); if (price < 1) { price = 1; } totalCost += price * amount; validBuy.Add(buy); break; } } } } } //foreach if (fullPurchase && validBuy.Count == 0) { SayTo(buyer, true, "Thou hast bought nothing!"); } else if (validBuy.Count == 0) { SayTo(buyer, true, "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, true, "Begging thy pardon, but thou casnt afford that."); } } if (!bought && totalCost >= 2000) { cont = buyer.BankBox; if (cont != null && cont.ConsumeTotal(typeof(Gold), totalCost)) { bought = true; fromBank = true; } else { SayTo(buyer, true, "Begging thy pardon, but thy bank account lacks these funds."); } } if (!bought) { return(false); } else { buyer.PlaySound(0x32); } if (buyer.AccessLevel < AccessLevel.GameMaster) // dont count free purchases { m_BankAccount += (int)(totalCost * 0.9); // gets back 90% } cont = buyer.Backpack; if (cont == null) { cont = buyer.BankBox; } foreach (BuyItemResponse buy in validBuy) { Serial ser = 0x7FFFFEFF - buy.Serial; int amount = buy.Amount; if (ser >= 0 && ser <= buyInfo.Length) { IBuyItemInfo bii = buyInfo[ser]; if (amount > bii.Amount) { amount = bii.Amount; } bii.Amount -= amount; object o = bii.GetObject(); if (o is Item) { Item item = (Item)o; if (item.Stackable) { item.Amount = amount; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } else { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } for (int i = 1; i < amount; i++) { item = bii.GetObject() as Item; if (item != null) { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } } } } else if (o is Mobile) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); //m.MoveToWorld( buyer.Location, buyer.Map ); m.Location = buyer.Location; m.Map = buyer.Map; m.PlaySound(m.GetIdleSound()); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } for (int i = 1; i < amount; ++i) { m = bii.GetObject() as Mobile; if (m != null) { m.Direction = (Direction)Utility.Random(8); m.Location = buyer.Location; m.Map = buyer.Map; if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } } } } } else { Item item = World.FindItem(buy.Serial); if (item == null) { continue; } 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 = item.Dupe(amount); item.Amount -= amount; } if (cont == null || !cont.TryDropItem(buyer, buyItem, false)) { buyItem.MoveToWorld(buyer.Location, buyer.Map); } break; } } } } } //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, true, "The total of thy purchase is {0} gold, which has been withdrawn from your bank account. My thanks for the patronage.", totalCost); } else { SayTo(buyer, true, "The total of thy purchase is {0} gold. My thanks for the patronage.", totalCost); } } 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); }
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. } }
private void ProcessValidPurchase( int amount, IBuyItemInfo bii, Mobile buyer, Container cont ) { if ( amount > bii.Amount ) amount = bii.Amount; if ( amount < 1 ) return; bii.Amount -= amount; IEntity o = bii.GetEntity(); if ( o is Item ) { Item item = (Item)o; if ( item.Stackable ) { item.Amount = amount; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); } else { item.Amount = 1; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); for ( int i = 1; i < amount; i++ ) { item = bii.GetEntity() as Item; if ( item != null ) { item.Amount = 1; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); } } } } else if ( o is Mobile ) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random( 8 ); m.MoveToWorld( buyer.Location, buyer.Map ); m.PlaySound( m.GetIdleSound() ); if ( m is BaseCreature ) ( (BaseCreature)m ).SetControlMaster( buyer ); for ( int i = 1; i < amount; ++i ) { m = bii.GetEntity() as Mobile; if ( m != null ) { m.Direction = (Direction)Utility.Random( 8 ); m.MoveToWorld( buyer.Location, buyer.Map ); if ( m is BaseCreature ) ( (BaseCreature)m ).SetControlMaster( buyer ); } } } }
private void ProcessValidPurchase( int amount, IBuyItemInfo bii, Mobile buyer, Container cont ) { if ( amount > bii.Amount ) amount = bii.Amount; if ( amount < 1 ) return; bii.Amount -= amount; IEntity o = bii.GetEntity(); if ( o is Item ) { Item item = (Item)o; if (item is Food) { Food food = item as Food; if (Utility.RandomDouble() <= 0.05) food.Poison = Poison.Lesser; } if (item is BaseWeapon) { BaseWeapon wpn = item as BaseWeapon; if (Utility.RandomDouble() <= 0.05) wpn.Quality = WeaponQuality.Low; } if (item is BaseArmor) { BaseArmor arm = item as BaseArmor; if (Utility.RandomDouble() <= 0.05) arm.Quality = ArmorQuality.Low; } if (item is BaseTool) { BaseTool tool = item as BaseTool; if (Utility.RandomDouble() <= 0.05) tool.UsesRemaining /= 2; } if ( item.Stackable ) { item.Amount = amount; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); } else { item.Amount = 1; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); for ( int i = 1; i < amount; i++ ) { item = bii.GetEntity() as Item; if ( item != null ) { item.Amount = 1; if ( cont == null || !cont.TryDropItem( buyer, item, false ) ) item.MoveToWorld( buyer.Location, buyer.Map ); } } } } else if ( o is Mobile ) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random( 8 ); m.MoveToWorld( buyer.Location, buyer.Map ); m.PlaySound( m.GetIdleSound() ); if ( m is BaseCreature ) ( (BaseCreature)m ).SetControlMaster( buyer ); for ( int i = 1; i < amount; ++i ) { m = bii.GetEntity() as Mobile; if ( m != null ) { m.Direction = (Direction)Utility.Random( 8 ); m.MoveToWorld( buyer.Location, buyer.Map ); if ( m is BaseCreature ) ( (BaseCreature)m ).SetControlMaster( buyer ); } } } }
private void ProcessValidPurchase(int amount, IBuyItemInfo bii, Mobile buyer, Container cont) { if (amount > bii.Amount) amount = bii.Amount; if (amount < 1) return; if (ResourcePool.IsPooledResource(bii.Type) && ResourcePool.GetTotalCount(bii.Type) > 0) { ResourcePool.SellOff(bii.Type, amount, this.Serial, buyer); } else { bii.Amount -= amount; } object o = bii.GetObject(); if (o is Item) { Item item = (Item)o; // all weapons and armor are exceptional during server wars if (Server.Misc.TestCenter.Enabled == true) { if (item is BaseArmor) { (item as BaseArmor).Quality = ArmorQuality.Exceptional; (item as BaseArmor).Durability = ArmorDurabilityLevel.Fortified; (item as BaseArmor).Identified = true; } if (item is BaseWeapon) { (item as BaseWeapon).Quality = WeaponQuality.Exceptional; (item as BaseWeapon).DurabilityLevel = WeaponDurabilityLevel.Fortified; (item as BaseWeapon).Identified = true; } } if (item.Stackable) { item.Amount = amount; if (ResourcePool.IsPooledResource(item.GetType()) && item.Amount >= 100) item = new CommodityDeed(item); if (cont == null || !cont.TryDropItem(buyer, item, false)) item.MoveToWorld(buyer.Location, buyer.Map); } else { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) item.MoveToWorld(buyer.Location, buyer.Map); for (int i = 1; i < amount; i++) { item = bii.GetObject() as Item; if (item != null) { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) item.MoveToWorld(buyer.Location, buyer.Map); } } } } else if (o is Mobile) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); m.PlaySound(m.GetIdleSound()); if (m is BaseCreature) ((BaseCreature)m).SetControlMaster(buyer); for (int i = 1; i < amount; ++i) { m = bii.GetObject() as Mobile; if (m != null) { m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); if (m is BaseCreature) ((BaseCreature)m).SetControlMaster(buyer); } } } }
private void ProcessValidPurchase(int amount, IBuyItemInfo bii, Mobile buyer, Container cont) { if (amount > bii.Amount) { amount = bii.Amount; } if (amount < 1) { return; } bii.Amount -= amount; object o = bii.GetObject(); if (o is Item) { Item item = (Item)o; item.Hue = bii.Hue; if (item.Stackable) { item.Amount = amount; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } else { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } for (int i = 1; i < amount; i++) { item = bii.GetObject() as Item; if (item != null) { item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { item.MoveToWorld(buyer.Location, buyer.Map); } } } } } else if (o is Mobile) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); m.PlaySound(m.GetIdleSound()); m.Hue = bii.Hue; if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } for (int i = 1; i < amount; ++i) { m = bii.GetObject() as Mobile; if (m != null) { m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } } } } }
private void ProcessValidPurchase(int amount, IBuyItemInfo bii, Mobile buyer, Container cont, Container bankbox) { if (amount > bii.Amount) { amount = bii.Amount; } if (amount < 1) { return; } bii.Amount -= amount; IEntity o = bii.GetEntity(); if (o is Item) { Item item = (Item)o; if (item.Stackable) { item.Amount = amount; if (cont == null || !cont.TryDropItem(buyer, item, false)) { if (bankbox.TryDropItem(buyer, item, false)) { buyer.PrivateOverheadMessage(MessageType.Regular, 0x22, true, "Because of overweight your purchase was delivered to your bankbox.", buyer.NetState); } else { item.MoveToWorld(buyer.Location, buyer.Map); } } } else { item.Amount = 1; item.Quality = Quality.Low; if (cont == null || !cont.TryDropItem(buyer, item, false)) { if (bankbox.TryDropItem(buyer, item, false)) { buyer.PrivateOverheadMessage(MessageType.Regular, 0x22, true, "Because of overencumbrance your purchase was delivered to your bankbox.", buyer.NetState); } else { item.MoveToWorld(buyer.Location, buyer.Map); } } for (int i = 1; i < amount; i++) { if (item != null) { item = bii.GetEntity() as Item; item.Amount = 1; if (cont == null || !cont.TryDropItem(buyer, item, false)) { if (bankbox.TryDropItem(buyer, item, false)) { buyer.PrivateOverheadMessage(MessageType.Regular, 0x22, true, "Because of overencumbrance your purchase was delivered to your bankbox.", buyer.NetState); } else { item.MoveToWorld(buyer.Location, buyer.Map); } } } } } } else if (o is Mobile) { Mobile m = (Mobile)o; m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); m.PlaySound(m.GetIdleSound()); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } for (int i = 1; i < amount; ++i) { m = bii.GetEntity() as Mobile; if (m != null) { m.Direction = (Direction)Utility.Random(8); m.MoveToWorld(buyer.Location, buyer.Map); if (m is BaseCreature) { ((BaseCreature)m).SetControlMaster(buyer); } } } } }
public virtual void VendorSell(Mobile from) { if (!IsActiveBuyer) { return; } if (!from.CheckAlive()) { return; } if (!CheckVendorAccess(from)) { Say(501522); // I shall not treat with scum like thee! return; } //TEST: Figure Out Budgets Concept if (m_Budgets.ContainsKey(from.Serial)) { /* * if ( from.AccessLevel >= AccessLevel.GameMaster ) * { * SayTo( from, true, "Your current budget is {0}, which resets at {1}", * m_Budgets[from.Serial].CurrentBudget, m_Budgets[from.Serial].ResetBudgetAt ); * } */ if (DateTime.UtcNow < m_Budgets[from.Serial].ResetBudgetAt) { } else { m_Budgets[from.Serial].CurrentBudget = 0; m_Budgets[from.Serial].ResetBudgetAt = DateTime.UtcNow + Budget.TimeFrame; } } else { m_Budgets.Add(from.Serial, new Budget(0, DateTime.UtcNow + Budget.TimeFrame)); } Container pack = from.Backpack; if (pack != null) { IShopSellInfo[] info = GetSellInfo(); IBuyItemInfo[] buyinfo = GetBuyInfo(); Hashtable table = new Hashtable(); int numItemsNotCraftedBySeller = 0; foreach (IShopSellInfo ssi in info) { Item[] items = pack.FindItemsByType(ssi.Types); foreach (Item item in items) { if (item is Container && ((Container)item).Items.Count != 0) { continue; } if (item.IsStandardLoot() && item.Movable && ssi.IsSellable(item)) { int price = ssi.GetSellPriceFor(item); for (int idx = 0; idx < buyinfo.Length; idx++) { IBuyItemInfo buyItem = (IBuyItemInfo)buyinfo[idx]; GenericBuyInfo gbi = (GenericBuyInfo)buyItem; if (item.GetType().IsAssignableFrom(gbi.Type) && !(item is BaseWeapon) && !(item is BaseArmor)) { if (price >= buyItem.Price) { price = buyItem.Price - 1; } } } table[item] = new SellItemState(item, price, ssi.GetNameFor(item)); } } } if (table.Count > 0) { SendPacksTo(from); from.Send(new VendorSellList(this, table)); } else { Say(true, "You have nothing I would be interested in."); } } }
public int GetSellPriceFor(Item item, BaseVendor vendor) { int price = 0; m_Table.TryGetValue(item.GetType(), out price); if (vendor != null && BaseVendor.UseVendorEconomy) { IBuyItemInfo buyInfo = vendor.GetBuyInfo().OfType <GenericBuyInfo>().FirstOrDefault(info => info.EconomyItem && info.Type == item.GetType()); if (buyInfo != null) { int sold = buyInfo.TotalSold; price = (int)(buyInfo.Price * .75); return(Math.Max(1, price)); } } if (item is BaseArmor) { BaseArmor armor = (BaseArmor)item; if (armor.Quality == ItemQuality.Low) { price = (int)(price * 0.60); } else if (armor.Quality == ItemQuality.Exceptional) { price = (int)(price * 1.25); } price += 100 * (int)armor.Durability; price += 100 * (int)armor.ProtectionLevel; if (price < 1) { price = 1; } } else if (item is BaseWeapon) { BaseWeapon weapon = (BaseWeapon)item; if (weapon.Quality == ItemQuality.Low) { price = (int)(price * 0.60); } else if (weapon.Quality == ItemQuality.Exceptional) { price = (int)(price * 1.25); } price += 100 * (int)weapon.DurabilityLevel; price += 100 * (int)weapon.DamageLevel; if (price < 1) { price = 1; } } else if (item is BaseBeverage) { int price1 = price, price2 = price; if (item is Pitcher) { price1 = 3; price2 = 5; } else if (item is BeverageBottle) { price1 = 3; price2 = 3; } else if (item is Jug) { price1 = 6; price2 = 6; } BaseBeverage bev = (BaseBeverage)item; if (bev.IsEmpty || bev.Content == BeverageType.Milk) { price = price1; } else { price = price2; } } return(price); }
public virtual void VendorBuy(Mobile from) { if (!IsActiveSeller) { return; } if (!from.CheckAlive()) { return; } if (this.Home != Point3D.Zero && !this.InRange(this.Home, this.RangeHome + 5)) { this.Say("Please allow me to return to my shop so that I might assist thee."); this.Location = this.Home; return; } if (DateTime.Now - m_LastRestock > RestockDelay) { Restock(); } double discount = GetBuyDiscountFor(from); int count = 0; List <BuyItemState> list; IBuyItemInfo[] buyInfo = this.GetBuyInfo(); IShopSellInfo[] sellInfo = this.GetSellInfo(); list = new List <BuyItemState>(buyInfo.Length); Container cont = this.BuyPack; for (int idx = 0; idx < buyInfo.Length; idx++) { IBuyItemInfo buyItem = (IBuyItemInfo)buyInfo[idx]; if (buyItem.Amount > 0) { if (list.Count < 250) { int price = (int)Math.Round(buyItem.Price * discount); if (price < 1) { price = 1; } list.Add(new BuyItemState(buyItem.Name, cont.Serial, 0x7FFFFEFF - idx, price, buyItem.Amount, buyItem.ItemID, buyItem.Hue)); count++; } } } List <Item> 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 = (int)Math.Round(ssi.GetBuyPriceFor(item) * discount); name = ssi.GetNameFor(item); break; } } if (name != null && list.Count < 250) { if (price < 1) { price = 1; } list.Add(new BuyItemState(name, cont.Serial, item.Serial, price, item.Amount, item.ItemID, item.Hue)); count++; } } //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 foreach (BuyItemState bis in list) { int loc; try { loc = Utility.ToInt32(bis.Description); } catch { loc = 0; } if (loc > 500000) { from.Send(new FakeOPL(bis.MySerial, loc)); } else { from.Send(new FakeOPL(bis.MySerial, bis.Description)); } } SayTo(from, true, "Greetings. Have a look around."); } }