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; 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()); 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; 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()); 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); } } } } }
//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); }
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); } } } }