public void BuyValidate(ClientSession Session, KeyValuePair <long, MapShop> shop, short slot, short amount) { PersonalShopItem itemshop = Session.CurrentMap.ShopUserList[shop.Key].Items.FirstOrDefault(i => i.Slot.Equals(slot)); Session.CurrentMap.ShopUserList[shop.Key].Items.FirstOrDefault(i => i.Slot.Equals(slot)).Amount -= amount; PersonalShopItem itemDelete = Session.CurrentMap.ShopUserList[shop.Key].Items.FirstOrDefault(i => i.Slot.Equals(slot)); if (itemDelete.Amount <= 0) { Session.CurrentMap.ShopUserList[shop.Key].Items.Remove(itemDelete); } ClientSession session = sessions.FirstOrDefault(s => s.Character.CharacterId.Equals(shop.Value.OwnerId)); { if (session != null) { session.Character.Gold += itemshop.Price * amount; session.Client.SendPacket(session.Character.GenerateGold()); session.Client.SendPacket(session.Character.GenerateShopMemo(1, String.Format(Language.Instance.GetMessageFromKey("BUY_ITEM"), session.Character.Name, ServerManager.GetItem(itemshop.ItemVNum).Name, amount))); Session.CurrentMap.ShopUserList[shop.Key].Sell += itemshop.Price * amount; session.Client.SendPacket(String.Format("sell_list {0} {1}.{2}.{3}", shop.Value.Sell, slot, amount, itemshop.Amount)); Inventory inv = session.Character.InventoryList.AmountMinusFromSlotAndType(amount, itemshop.InvSlot, itemshop.InvType); if (inv != null) { session.Client.SendPacket(session.Character.GenerateInventoryAdd(inv.InventoryItem.ItemVNum, inv.InventoryItem.Amount, inv.Type, inv.Slot, inv.InventoryItem.Rare, inv.InventoryItem.Color, inv.InventoryItem.Upgrade)); } else { session.Client.SendPacket(session.Character.GenerateInventoryAdd(-1, 0, itemshop.InvType, itemshop.InvSlot, 0, 0, 0)); } } } }
//PacketHandler public void BuyValidate(ClientSession clientSession, KeyValuePair <long, MapShop> shop, short slot, byte amount) { PersonalShopItem itemshop = clientSession.CurrentMap.UserShops[shop.Key].Items.FirstOrDefault(i => i.Slot.Equals(slot)); if (itemshop == null) { return; } Guid id = itemshop.Id; itemshop.Amount -= amount; if (itemshop.Amount <= 0) { clientSession.CurrentMap.UserShops[shop.Key].Items.Remove(itemshop); } ClientSession shopOwnerSession = Sessions.FirstOrDefault(s => s.Character.CharacterId.Equals(shop.Value.OwnerId)); if (shopOwnerSession == null) { return; } shopOwnerSession.Character.Gold += itemshop.Price * amount; shopOwnerSession.SendPacket(shopOwnerSession.Character.GenerateGold()); shopOwnerSession.SendPacket(shopOwnerSession.Character.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM"), shopOwnerSession.Character.Name, (itemshop.ItemInstance as ItemInstance).Item.Name, amount))); clientSession.CurrentMap.UserShops[shop.Key].Sell += itemshop.Price * amount; shopOwnerSession.SendPacket($"sell_list {shop.Value.Sell} {slot}.{amount}.{itemshop.Amount}"); Inventory inv = shopOwnerSession.Character.InventoryList.RemoveItemAmountFromInventory(amount, id); if (inv != null) { // Send reduced-amount to owners inventory shopOwnerSession.SendPacket(shopOwnerSession.Character.GenerateInventoryAdd(inv.ItemInstance.ItemVNum, inv.ItemInstance.Amount, inv.Type, inv.Slot, inv.ItemInstance.Rare, inv.ItemInstance.Design, inv.ItemInstance.Upgrade, 0)); } else { // Send empty slot to owners inventory shopOwnerSession.SendPacket(shopOwnerSession.Character.GenerateInventoryAdd(-1, 0, itemshop.Type, itemshop.Slot, 0, 0, 0, 0)); if (clientSession.CurrentMap.UserShops[shop.Key].Items.Count == 0) { clientSession.SendPacket("shop_end 0"); Broadcast(shopOwnerSession, shopOwnerSession.Character.GenerateShopEnd(), ReceiverType.All); Broadcast(shopOwnerSession, shopOwnerSession.Character.GeneratePlayerFlag(0), ReceiverType.AllExceptMe); shopOwnerSession.Character.LoadSpeed(); shopOwnerSession.Character.IsSitting = false; shopOwnerSession.SendPacket(shopOwnerSession.Character.GenerateCond()); Broadcast(shopOwnerSession, shopOwnerSession.Character.GenerateRest(), ReceiverType.All); } } }
public void BuyValidate(ClientSession clientSession, KeyValuePair <long, MapShop> shop, short slot, byte amount) { PersonalShopItem itemshop = clientSession.CurrentMap.ShopUserList[shop.Key].Items.FirstOrDefault(i => i.Slot.Equals(slot)); if (itemshop == null) { return; } itemshop.Amount -= amount; if (itemshop.Amount <= 0) { clientSession.CurrentMap.ShopUserList[shop.Key].Items.Remove(itemshop); } ClientSession shopOwnerSession = Sessions.FirstOrDefault(s => s.Character.CharacterId.Equals(shop.Value.OwnerId)); if (shopOwnerSession == null) { return; } shopOwnerSession.Character.Gold += itemshop.Price * amount; shopOwnerSession.Client.SendPacket(shopOwnerSession.Character.GenerateGold()); shopOwnerSession.Client.SendPacket(shopOwnerSession.Character.GenerateShopMemo(1, string.Format(Language.Instance.GetMessageFromKey("BUY_ITEM"), shopOwnerSession.Character.Name, ServerManager.GetItem(itemshop.ItemVNum).Name, amount))); clientSession.CurrentMap.ShopUserList[shop.Key].Sell += itemshop.Price * amount; shopOwnerSession.Client.SendPacket($"sell_list {shop.Value.Sell} {slot}.{amount}.{itemshop.Amount}"); Inventory inv = shopOwnerSession.Character.InventoryList.AmountMinusFromSlotAndType(amount, itemshop.InvSlot, itemshop.InvType); if (inv != null) { // Send reduced-amount to owners inventory shopOwnerSession.Client.SendPacket(shopOwnerSession.Character.GenerateInventoryAdd(inv.InventoryItem.ItemVNum, inv.InventoryItem.Amount, inv.Type, inv.Slot, inv.InventoryItem.Rare, inv.InventoryItem.Design, inv.InventoryItem.Upgrade)); } else { // Send empty slot to owners inventory shopOwnerSession.Client.SendPacket(shopOwnerSession.Character.GenerateInventoryAdd(-1, 0, itemshop.InvType, itemshop.InvSlot, 0, 0, 0)); } }
public void CreateShop(string packet) { Logger.Debug(packet, Session.SessionId); string[] packetsplit = packet.Split(' '); InventoryType[] type = new InventoryType[20]; long[] gold = new long[20]; short[] slot = new short[20]; byte[] qty = new byte[20]; string shopname = String.Empty; if (packetsplit.Length > 2) { short typePacket; short.TryParse(packetsplit[2], out typePacket); if ((Session.Character.HasShopOpened && typePacket != 1) || !Session.HasCurrentMap) { return; } foreach (PortalDTO por in Session.CurrentMap.Portals) { if (Session.Character.MapX < por.SourceX + 6 && Session.Character.MapX > por.SourceX - 6 && Session.Character.MapY < por.SourceY + 6 && Session.Character.MapY > por.SourceY - 6) { Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_NEAR_PORTAL"), 0)); return; } } if (!Session.CurrentMap.ShopAllowed) { Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_NOT_ALLOWED"), 0)); return; } if (typePacket == 2) { Session.SendPacket("ishop"); } else if (typePacket == 0) { if (Session.CurrentMap.UserShops.Count(s => s.Value.OwnerId == Session.Character.CharacterId) != 0) { return; } MapShop myShop = new MapShop(); if (packetsplit.Length > 82) { short shopSlot = 0; for (short j = 3, i = 0; j < 82; j += 4, i++) { Enum.TryParse(packetsplit[j], out type[i]); short.TryParse(packetsplit[j + 1], out slot[i]); byte.TryParse(packetsplit[j + 2], out qty[i]); long.TryParse(packetsplit[j + 3], out gold[i]); if (gold[i] < 0) { return; } if (qty[i] > 0) { ItemInstance inv = Session.Character.Inventory.LoadBySlotAndType(slot[i], type[i]); if (inv.Amount < qty[i]) { return; } if (!inv.Item.IsTradable || inv.IsBound) { Session.SendPacket(Session.Character.GenerateMsg(Language.Instance.GetMessageFromKey("SHOP_ONLY_TRADABLE_ITEMS"), 0)); Session.SendPacket("shop_end 0"); return; } PersonalShopItem personalshopitem = new PersonalShopItem() { ShopSlot = shopSlot, Price = gold[i], ItemInstance = inv, SellAmount = qty[i] }; myShop.Items.Add(personalshopitem); shopSlot++; } } } if (myShop.Items.Count != 0) { if (!myShop.Items.Any(s => !s.ItemInstance.Item.IsSoldable || s.ItemInstance.IsBound)) { for (int i = 83; i < packetsplit.Length; i++) { shopname += $"{packetsplit[i]} "; } // trim shopname shopname = shopname.TrimEnd(' '); // create default shopname if it's empty if (string.IsNullOrWhiteSpace(shopname) || string.IsNullOrEmpty(shopname)) { shopname = Language.Instance.GetMessageFromKey("SHOP_PRIVATE_SHOP"); } // truncate the string to a max-length of 20 shopname = StringHelper.Truncate(shopname, 20); myShop.OwnerId = Session.Character.CharacterId; myShop.Name = shopname; Session.CurrentMap.UserShops.Add(Session.CurrentMap.LastUserShopId++, myShop); Session.Character.HasShopOpened = true; Session.CurrentMap?.Broadcast(Session, Session.Character.GeneratePlayerFlag(Session.CurrentMap.LastUserShopId), ReceiverType.AllExceptMe); Session.CurrentMap?.Broadcast(Session.Character.GenerateShop(shopname)); Session.SendPacket(Session.Character.GenerateInfo(Language.Instance.GetMessageFromKey("SHOP_OPEN"))); Session.Character.IsSitting = true; Session.Character.IsShopping = true; Session.Character.LoadSpeed(); Session.SendPacket(Session.Character.GenerateCond()); Session.CurrentMap?.Broadcast(Session.Character.GenerateRest()); } else { Session.SendPacket("shop_end 0"); Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("ITEM_NOT_SOLDABLE"), 10)); } } else { Session.SendPacket("shop_end 0"); Session.SendPacket(Session.Character.GenerateSay(Language.Instance.GetMessageFromKey("SHOP_EMPTY"), 10)); } } else if (typePacket == 1) { Session.Character.CloseShop(true); } } }
public void createShop(string packet) { string[] packetsplit = packet.Split(' '); short[] type = new short[20]; long[] gold = new long[20]; short[] slot = new short[20]; short[] qty = new short[20]; string shopname = ""; if (packetsplit.Length > 2) { short typePacket; short.TryParse(packetsplit[2], out typePacket); if (typePacket == 2) { Session.Client.SendPacket("ishop"); } else if (typePacket == 0) { MapShop myShop = new MapShop(); if (packetsplit.Length > 2) for (short j = 3, i = 0; j <= packetsplit.Length - 5; j += 4, i++) { short.TryParse(packetsplit[j], out type[i]); short.TryParse(packetsplit[j + 1], out slot[i]); short.TryParse(packetsplit[j + 2], out qty[i]); long.TryParse(packetsplit[j + 3], out gold[i]); if (qty[i] != 0) { Inventory inv = Session.Character.InventoryList.LoadBySlotAndType(slot[i], type[i]); PersonalShopItem personalshopitem = new PersonalShopItem() { InvSlot = slot[i], InvType = type[i], Amount = qty[i], Price = gold[i], Slot = i, Color = inv.InventoryItem.Color, Concentrate = inv.InventoryItem.Concentrate, CriticalLuckRate = inv.InventoryItem.CriticalLuckRate, CriticalRate = inv.InventoryItem.CriticalRate, DamageMaximum = inv.InventoryItem.DamageMaximum, DamageMinimum = inv.InventoryItem.DamageMinimum, DarkElement = inv.InventoryItem.DarkElement, DistanceDefence = inv.InventoryItem.DistanceDefence, DistanceDefenceDodge = inv.InventoryItem.DistanceDefenceDodge, DefenceDodge = inv.InventoryItem.DefenceDodge, ElementRate = inv.InventoryItem.ElementRate, FireElement = inv.InventoryItem.FireElement, HitRate = inv.InventoryItem.HitRate, InventoryItemId = inv.InventoryItemId, ItemVNum = inv.InventoryItem.ItemVNum, LightElement = inv.InventoryItem.LightElement, MagicDefence = inv.InventoryItem.MagicDefence, RangeDefence = inv.InventoryItem.RangeDefence, Rare = inv.InventoryItem.Rare, SpXp = inv.InventoryItem.SpXp, SpLevel = inv.InventoryItem.SpLevel, SlDefence = inv.InventoryItem.SlDefence, SlElement = inv.InventoryItem.SlElement, SlHit = inv.InventoryItem.SlHit, SlHP = inv.InventoryItem.SlHP, Upgrade = inv.InventoryItem.Upgrade, WaterElement = inv.InventoryItem.WaterElement }; myShop.Items.Add(personalshopitem); } } for (int i = 83; i < packetsplit.Length; i++) shopname += String.Format("{0} ", packetsplit[i]); shopname.TrimEnd(' '); myShop.OwnerId = Session.Character.CharacterId; myShop.Name = shopname; Session.CurrentMap.ShopUserList.Add(Session.CurrentMap.ShopUserList.Count(), myShop); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GeneratePlayerFlag(Session.CurrentMap.ShopUserList.Count()), ReceiverType.AllOnMapExceptMe); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateShop(shopname), ReceiverType.AllOnMap); Session.Client.SendPacket(Session.Character.GenerateInfo(Language.Instance.GetMessageFromKey("SHOP_OPEN"))); Session.Character.Rested = 1; Session.Character.LastSpeed = Session.Character.Speed; Session.Character.Speed = 0; Session.Client.SendPacket(Session.Character.GenerateCond()); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateRest(), ReceiverType.AllOnMap); } else if (typePacket == 1) { KeyValuePair<long, MapShop> shop = Session.CurrentMap.ShopUserList.FirstOrDefault(mapshop => mapshop.Value.OwnerId.Equals(Session.Character.CharacterId)); Session.CurrentMap.ShopUserList.Remove(shop.Key); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateShopEnd(), ReceiverType.AllOnMap); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GeneratePlayerFlag(0), ReceiverType.AllOnMapExceptMe); Session.Character.Speed = Session.Character.LastSpeed; Session.Character.Rested = 0; Session.Client.SendPacket(Session.Character.GenerateCond()); ClientLinkManager.Instance.Broadcast(Session, Session.Character.GenerateRest(), ReceiverType.AllOnMap); } } }