public static Type GetRandomTrade(City originCity, City dest, ref int worth, ref string name) { Region region = CityLoyaltySystem.GetCityInstance(originCity).Definition.Region; List <BaseVendor> list = new List <BaseVendor>(region.GetEnumeratedMobiles().OfType <BaseVendor>().Where(bv => bv.GetBuyInfo() != null && bv.GetBuyInfo().Length > 0)); if (list.Count == 0) { return(null); } do { BaseVendor vendor = list[Utility.Random(list.Count)]; IBuyItemInfo[] buyInfo = vendor.GetBuyInfo(); GenericBuyInfo info = buyInfo[Utility.Random(buyInfo.Length)] as GenericBuyInfo; if (!(info is BeverageBuyInfo) && !(info is AnimalBuyInfo) && info != null && info.Type != null && info.Args == null && info.Price < 5000) { list.Clear(); list.TrimExcess(); worth = info.Price; name = info.Name; return(info.Type); } else { list.Remove(vendor); } }while (list.Count > 0); list.Clear(); list.TrimExcess(); return(null); }
public override bool OnBuyItems(Mobile buyer, List <BuyItemResponse> list) { if (!Trading || TokenType == null || !TokenType.IsNotNull) { return(false); } 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(); var info = GetSellInfo(); int totalCost = 0; var validBuy = new List <BuyItemResponse>(list.Count); 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 != BuyPack && item.IsChildOf(BuyPack)) { if (amount > item.Amount) { amount = item.Amount; } if (amount <= 0) { continue; } foreach (IShopSellInfo ssi in info.Where(ssi => ssi.IsSellable(item)).Where(ssi => 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); } } } if (fullPurchase && validBuy.Count == 0) { // Thou hast bought nothing! SayTo(buyer, 500190); } else if (validBuy.Count == 0) { // Your order cannot be fulfilled, please try again. SayTo(buyer, 500187); } if (validBuy.Count == 0) { return(false); } bool bought = (buyer.AccessLevel >= AccessLevel.GameMaster); Container cont = buyer.Backpack; if (!bought && cont != null) { if (cont.ConsumeTotal(TokenType, totalCost)) { bought = true; } else if (totalCost < 2000) { // Begging thy pardon, but thou casnt afford that. SayTo(buyer, 500192); } } if (!bought && totalCost >= 2000) { cont = buyer.FindBankNoCreate(); if (cont != null && cont.ConsumeTotal(TokenType, totalCost)) { bought = true; fromBank = true; } else { // Begging thy pardon, but thy bank account lacks these funds. SayTo(buyer, 500191); } } if (!bought) { return(false); } buyer.PlaySound(0x32); cont = buyer.Backpack ?? 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; } if (info.Where(ssi => ssi.IsSellable(item)).Any(ssi => ssi.IsResellable(item))) { Item buyItem; if (amount >= item.Amount) { buyItem = item; } else { buyItem = LiftItemDupe(item, item.Amount - amount) ?? item; } if (cont == null || !cont.TryDropItem(buyer, buyItem, false)) { buyItem.MoveToWorld(buyer.Location, buyer.Map); } } } } 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); } } } 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} {1}, which has been withdrawn from your bank account. My thanks for the patronage.", totalCost, TokenName); } else { SayTo(buyer, true, "The total of thy purchase is {0} {1}. My thanks for the patronage.", totalCost, TokenName); } } 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} {1}, 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, TokenName); } else { SayTo( buyer, true, "The total of thy purchase is {0} {1}. My thanks for the patronage. Unfortunately, I could not sell you all the goods you requested.", totalCost, TokenName); } } return(true); }
public override bool OnBuyItems(Mobile buyer, List <BuyItemResponse> list) { if (!Trading || !IsActiveSeller || CashType == null || !CashType.IsNotNull) { return(false); } if (!buyer.CheckAlive()) { return(false); } if (!CheckVendorAccess(buyer)) { Say("My shop is closed!"); //Say(501522); // I shall not treat with scum like thee! return(false); } UpdateBuyInfo(); var info = GetSellInfo(); int totalCost = 0; var validBuy = new List <BuyItemResponse>(list.Count); 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 != BuyPack && item.IsChildOf(BuyPack)) { if (amount > item.Amount) { amount = item.Amount; } if (amount <= 0) { continue; } foreach (IShopSellInfo ssi in info.Where(ssi => ssi.IsSellable(item)).Where(ssi => 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); } } } if (fullPurchase && validBuy.Count == 0) { // Thou hast bought nothing! SayTo(buyer, 500190); } else if (validBuy.Count == 0) { // Your order cannot be fulfilled, please try again. SayTo(buyer, 500187); } if (validBuy.Count == 0) { return(false); } bool bought = buyer.AccessLevel >= AccessLevel.GameMaster; if (!bought && CashType.TypeEquals <ObjectProperty>()) { object cashSource = GetCashObject(buyer) ?? buyer; bought = CashProperty.Consume(cashSource, totalCost); if (!bought) { // Begging thy pardon, but thou cant afford that. SayTo(buyer, 500192); return(false); } SayTo(buyer, "{0:#,0} {1} has been deducted from your total.", totalCost, CashName.GetString(buyer)); } Container cont = buyer.Backpack; if (!bought && cont != null && CashType.TypeEquals <Gold>()) { VitaNexCore.TryCatch( () => { var lt = Type.GetType("GoldLedger") ?? ScriptCompiler.FindTypeByName("GoldLedger"); if (lt == null) { return; } var ledger = cont.FindItemByType(lt); if (ledger == null || ledger.Deleted) { return; } var lp = lt.GetProperty("Gold"); if (lp == null || !lp.PropertyType.TypeEquals <Int32>()) { return; } int lg = (int)lp.GetValue(ledger, null); if (lg < totalCost) { return; } lp.SetValue(ledger, lg - totalCost, null); bought = true; buyer.SendMessage(2125, "{0:#,0} gold has been withdrawn from your ledger.", totalCost); }); } if (!bought && cont != null) { if (cont.ConsumeTotal(CashType, totalCost)) { bought = true; } else { // Begging thy pardon, but thou cant afford that. SayTo(buyer, 500192); } } if (!bought) { cont = buyer.FindBankNoCreate(); if (cont != null && cont.ConsumeTotal(CashType, totalCost)) { bought = true; fromBank = true; } else { // Begging thy pardon, but thy bank account lacks these funds. SayTo(buyer, 500191); } } if (!bought) { return(false); } buyer.PlaySound(0x32); cont = buyer.Backpack ?? 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; } if (info.Where(ssi => ssi.IsSellable(item)).Any(ssi => ssi.IsResellable(item))) { Item buyItem; if (amount >= item.Amount) { buyItem = item; } else { buyItem = LiftItemDupe(item, item.Amount - amount) ?? item; } if (cont == null || !cont.TryDropItem(buyer, buyItem, false)) { buyItem.MoveToWorld(buyer.Location, buyer.Map); } } } } 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); } } } 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:#,0} {1}, which has been withdrawn from your bank account. My thanks for the patronage.", totalCost, CashName.GetString(buyer)); } else { SayTo( buyer, true, "The total of thy purchase is {0:#,0} {1}. My thanks for the patronage.", totalCost, CashName.GetString(buyer)); } } 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:#,0} {1}, 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, CashName.GetString(buyer)); } else { SayTo( buyer, true, "The total of thy purchase is {0:#,0} {1}. My thanks for the patronage. Unfortunately, I could not sell you all the goods you requested.", totalCost, CashName.GetString(buyer)); } } return(true); }