public static void Buy_Req(InPacket lea, Client c) { int CharacterID = lea.ReadInt(); int ItemID = lea.ReadInt(); int Slot = lea.ReadShort(); int Quantity = lea.ReadShort(); var chr = c.Character; try { Map map = MapFactory.GetMap(chr.MapX, chr.MapY); Character Seller = null; foreach (Character find in map.Characters) { if (find.CharacterID == CharacterID) { Seller = find; } } ShopData Item = Seller.Shop.Find(i => ItemID == i.ItemID && Slot == i.TargetSlot); byte Type = InventoryType.getItemType(ItemID); byte FreeSlot = chr.Items.GetNextFreeSlot((InventoryType.ItemType)Type); if (Item.Quantity < Quantity || Item == null) { PlayerShopPacket.Buy(c, 0); return; } chr.Money -= (Item.Price * Quantity); InventoryPacket.getInvenMoney(c, chr.Money, -(Item.Price * Quantity)); chr.Items.Add(new Item(Item.ItemID, (short)Quantity, Item.Spirit, Item.Level1, Item.Level2, Item.Level3, Item.Level4, Item.Level5, Item.Level6, Item.Level7, Item.Level8, Item.Level9, Item.Level10, Item.Fusion, Item.IsLocked, Item.Icon, Item.Term, Type, FreeSlot)); InventoryHandler.UpdateInventory(c, Type); //Seller.Shop.Remove(Item); Seller.Items.Remove((byte)Item.SourceType, (byte)Item.SourceSlot); Seller.Items.Add(new Item(Item.ItemID, (short)(Item.Quantity - Quantity), Item.Spirit, Item.Level1, Item.Level2, Item.Level3, Item.Level4, Item.Level5, Item.Level6, Item.Level7, Item.Level8, Item.Level9, Item.Level10, Item.Fusion, Item.IsLocked, Item.Icon, Item.Term, (byte)Item.SourceType, (byte)Item.SourceSlot)); Item.Quantity = Item.Quantity - Quantity; Seller.Shop.Money += (Item.Price * Quantity); Seller.Money += (Item.Price * Quantity); PlayerShopPacket.ShopInfo(c, Seller, CharacterID); InventoryHandler.UpdateInventory(Seller.Client, (byte)Item.SourceType); PlayerShopPacket.SellInfo(Seller.Client); InventoryPacket.getInvenMoney(Seller.Client, Seller.Money, Item.Price * Quantity); PlayerShopPacket.Buy(c, 1); } catch { PlayerShopPacket.Buy(c, 0); return; } }
public static void ShopInfo_Req(InPacket lea, Client c) { int CharacterID = lea.ReadInt(); Map map = MapFactory.GetMap(c.Character.MapX, c.Character.MapY); Character Seller = null; foreach (Character chr in map.Characters) { if (chr.CharacterID == CharacterID) { Seller = chr; } } PlayerShopPacket.ShopInfo(c, Seller, CharacterID); }