Пример #1
0
        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));
        }
Пример #2
0
    private static void HandleBuy(GameSession session, PacketReader packet)
    {
        int itemUid  = packet.ReadInt();
        int quantity = packet.ReadInt();

        ShopItem shopItem = DatabaseManager.ShopItems.FindByUid(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.Account.RemoveMerets(shopItem.Price * quantity);
            break;

        case ShopCurrencyType.Item:
            Item itemCost = session.Player.Inventory.GetById(shopItem.RequiredItemId);
            if (itemCost.Amount < shopItem.Price)
            {
                return;
            }
            session.Player.Inventory.ConsumeItem(session, itemCost.Uid, shopItem.Price);
            break;

        default:
            session.SendNotice($"Unknown currency: {shopItem.TokenType}");
            return;
        }

        // add item to inventory
        Item item = new(shopItem.ItemId, quantity *shopItem.Quantity, shopItem.ItemRank);

        session.Player.Inventory.AddItem(session, item, true);

        // complete purchase
        session.Send(ShopPacket.Buy(shopItem.ItemId, quantity, shopItem.Price, shopItem.TokenType));
    }