public static void Buy(int vendorSerial, int itemID, int amount) { if (LastVendor == null) { return; } if (LastBuyList == null) { return; } if (LastVendor.Serial == vendorSerial) { List <VendorBuyItem> buyList = new List <VendorBuyItem>(); foreach (Assistant.Item listItem in LastBuyList) { if (listItem.ItemID == itemID) { int buyAmount = Math.Min(amount, listItem.Amount); VendorBuyItem item = new VendorBuyItem(listItem.Serial, buyAmount, 0); buyList.Add(item); Assistant.Client.Instance.SendToServer(new VendorBuyResponse(vendorSerial, buyList)); int price = listItem.Price * buyAmount; string message = "Buy Function: bought " + buyAmount.ToString() + " items for " + price.ToString() + " gold coins"; World.Player.Journal.Enqueue(new RazorEnhanced.Journal.JournalEntry(message, "System", 1, "Vendor", vendorSerial)); // Journal buffer World.Player.SendMessage(message); return; } } } }
private static void EndVendorBuy(PacketReader p, PacketHandlerEventArgs args) { if (!Client.Instance.AllowBit(FeatureBit.BuyAgent) || World.Player == null) { return; } uint serial = p.ReadUInt32(); if (BuyLists.TryGetValue(serial, out var list)) { BuyLists.Remove(serial); Mobile vendor = World.FindMobile(serial); if (vendor == null) { return; } Item pack = vendor.GetItemOnLayer(Layer.ShopBuy); if (pack == null || pack.Contains == null || pack.Contains.Count <= 0) { return; } for (int i = list.Count - 1; i >= 0; --i) { VendorBuyItem vbi = list[i]; Item item = World.FindItem(vbi.Serial); if (item == null || !pack.Contains.Contains(item)) { continue; } item.Amount -= (ushort)vbi.Amount; if (item.Amount <= 0) { item.Remove(); } } } }
private static void DisplayBuy(PacketReader p, PacketHandlerEventArgs args) { Serial serial = p.ReadUInt32(); ushort gump = p.ReadUInt16(); if (gump != 0x30 || !serial.IsMobile || !Client.Instance.AllowBit(FeatureBit.BuyAgent) || World.Player == null) { return; } Mobile vendor = World.FindMobile(serial); if (vendor == null) { return; } Item pack = vendor.GetItemOnLayer(Layer.ShopBuy); if (pack == null || pack.Contains == null || pack.Contains.Count <= 0) { return; } pack.Contains.Sort(ItemXYComparer.Instance); int total = 0; int cost = 0; List <VendorBuyItem> buyList = new List <VendorBuyItem>(); Dictionary <ushort, int> found = new Dictionary <ushort, int>(); bool lowGoldWarn = false; for (int i = 0; i < pack.Contains.Count; i++) { Item item = (Item)pack.Contains[i]; if (item == null) { continue; } foreach (BuyAgent ba in m_Instances) { if (ba == null || ba.m_Items == null || !ba.m_Enabled) { continue; } for (int a = 0; a < ba.m_Items.Count; a++) { BuyEntry b = (BuyEntry)ba.m_Items[a]; if (b == null) { continue; } bool dupe = false; foreach (VendorBuyItem vbi in buyList) { if (vbi.Serial == item.Serial) { dupe = true; } } if (dupe) { continue; } // f*****g osi and their blank scrolls if (b.Id == item.ItemID.Value || (b.Id == 0x0E34 && item.ItemID.Value == 0x0EF3) || (b.Id == 0x0EF3 && item.ItemID.Value == 0x0E34)) { int count = World.Player.Backpack.GetCount(b.Id); if (found.ContainsKey(b.Id)) { count += (int)found[b.Id]; } if (count < b.Amount && b.Amount > 0) { count = b.Amount - count; if (count >= item.Amount) { count = item.Amount; } else if (count <= 0) { continue; } if (!found.ContainsKey(b.Id)) { found.Add(b.Id, (int)count); } else { found[b.Id] = (int)found[b.Id] + (int)count; } buyList.Add(new VendorBuyItem(item.Serial, count, item.Price)); total += count; cost += item.Price * count; } } } } } if (!Config.GetBool("BuyAgentsIgnoreGold")) { if (cost > World.Player.Gold && cost < 2000 && buyList.Count > 0) { lowGoldWarn = true; do { VendorBuyItem vbi = (VendorBuyItem)buyList[0]; if (cost - vbi.TotalCost <= World.Player.Gold) { while (cost > World.Player.Gold && vbi.Amount > 0) { cost -= vbi.Price; --vbi.Amount; --total; } if (vbi.Amount <= 0) { buyList.RemoveAt(0); } } else { cost -= vbi.TotalCost; total -= vbi.Amount; buyList.RemoveAt(0); } } while (cost > World.Player.Gold && buyList.Count > 0); } } if (buyList.Count > 0) { args.Block = true; BuyLists[serial] = buyList; Client.Instance.SendToServer(new VendorBuyResponse(serial, buyList)); if (Config.GetBool("BuyAgentsIgnoreGold")) { World.Player.SendMessage(MsgLevel.Force, LocString.BuyAgentAttempt, total, cost); } else { World.Player.SendMessage(MsgLevel.Force, LocString.BuyTotals, total, cost); } } if (lowGoldWarn) { World.Player.SendMessage(MsgLevel.Force, LocString.BuyLowGold); } }