private static void HandleOpen(GameSession session, PacketReader packet) { int itemId = packet.ReadInt(); Item item = session.Player.Inventory.Items.Values.FirstOrDefault(x => x.Id == itemId); if (item == null) { return; } ShopMetadata shop = ShopMetadataStorage.GetShop(item.ShopID); if (shop == null) { Console.WriteLine($"Unknown shop ID: {item.ShopID}"); return; } session.Send(ShopPacket.Open(shop)); foreach (ShopItem shopItem in shop.Items) { session.Send(ShopPacket.LoadProducts(shopItem)); } session.Send(ShopPacket.Reload()); session.Send(SystemShopPacket.Open()); }
private static void HandleBuy(GameSession session, PacketReader packet) { int itemUid = packet.ReadInt(); int quantity = packet.ReadInt(); ShopItem shopItem = ShopMetadataStorage.GetItem(itemUid); switch (shopItem.TokenType) { case ShopCurrencyType.Meso: session.Player.Wallet.Meso.Modify(-(shopItem.Price * quantity)); break; case ShopCurrencyType.ValorToken: session.Player.Wallet.ValorToken.Modify(-(shopItem.Price * quantity)); break; case ShopCurrencyType.Treva: session.Player.Wallet.Treva.Modify(-(shopItem.Price * quantity)); break; case ShopCurrencyType.Rue: session.Player.Wallet.Rue.Modify(-(shopItem.Price * quantity)); break; case ShopCurrencyType.HaviFruit: session.Player.Wallet.HaviFruit.Modify(-(shopItem.Price * quantity)); break; case ShopCurrencyType.Meret: case ShopCurrencyType.GameMeret: case ShopCurrencyType.EventMeret: session.Player.Wallet.RemoveMerets(shopItem.Price * quantity); break; case ShopCurrencyType.Item: Item itemCost = session.Player.Inventory.Items.FirstOrDefault(x => x.Value.Id == shopItem.RequiredItemId).Value; if (itemCost.Amount < shopItem.Price) { return; } InventoryController.Consume(session, itemCost.Uid, shopItem.Price); break; default: session.SendNotice($"Unknown currency: {shopItem.TokenType}"); return; } // add item to inventory Item item = new(shopItem.ItemId) { Amount = quantity * shopItem.Quantity }; InventoryController.Add(session, item, true); // complete purchase session.Send(ShopPacket.Buy(shopItem.ItemId, quantity, shopItem.Price, shopItem.TokenType)); }
public static void HandleOpen(GameSession session, IFieldObject <Npc> npcFieldObject) { NpcMetadata metadata = NpcMetadataStorage.GetNpc(npcFieldObject.Value.Id); ShopMetadata shop = ShopMetadataStorage.GetShop(metadata.ShopId); if (shop == null) { Console.WriteLine($"Unknown shop ID: {metadata.ShopId}"); return; } session.Send(ShopPacket.Open(shop)); session.Send(ShopPacket.LoadProducts(shop.Items)); session.Send(ShopPacket.Reload()); session.Send(NpcTalkPacket.Respond(npcFieldObject, NpcType.Default, DialogType.None, 0)); }
private static void HandleOpenViaItem(GameSession session, PacketReader packet) { byte unk = packet.ReadByte(); int itemId = packet.ReadInt(); List <Item> playerInventory = new(session.Player.Inventory.Items.Values); Item item = playerInventory.FirstOrDefault(x => x.Id == itemId); if (item == null) { return; } ShopMetadata shop = ShopMetadataStorage.GetShop(item.ShopID); session.Send(ShopPacket.Open(shop)); session.Send(ShopPacket.LoadProducts(shop.Items)); }
private static void HandleMapleArenaShop(GameSession session, PacketReader packet) { bool openShop = packet.ReadBool(); if (!openShop) { return; } ShopMetadata shop = ShopMetadataStorage.GetShop(168); session.Send(ShopPacket.Open(shop)); foreach (ShopItem shopItem in shop.Items) { session.Send(ShopPacket.LoadProducts(shopItem)); } session.Send(ShopPacket.Reload()); session.Send(SystemShopPacket.Open()); }