Пример #1
0
        public async void BuyItem(CCashItemBuy message)
        {
            var category = (from c in cat
                            where c.Value.CategoryId == message.Category
                            select c.Value).First();

            var package = (from p in pack
                           where p.Value.GameId == message.ItemIndex
                           select p.Value).First();

            var products = (from p in prod
                            where package.ProductNodeId.Contains(p.Value.NodeId) || package.ProductRootId.Contains(p.Value.RootId)
                            select p.Value);

            var product = (from p in products
                           where message.ItemOpt == 0 || p.NodeId == message.ItemOpt
                           select p)
                          .Skip(Program.RandomProvider(package.ProductRootId.Length))
                          .First();

            var neededCoins = product.Coins != 0 ? product.Coins : package.Price;

            log.Debug("Buy CashItem Cat:{0}->{1} ID:{2}, {3}{4}", category.Name, product.Name, message.ItemID, neededCoins, message.Coin);

            CSResult result = CSResult.Ok;

            switch (message.Coin)
            {
            case CoinType.GPoints:
                if (_goblinPoints < neededCoins)
                {
                    //result = CSResult.InsuficientWCoint;
                    break;
                }
                break;

            case CoinType.WCoin:
                if (_wCoinC < neededCoins)
                {
                    //result = CSResult.InsuficientWCoint;
                    break;
                }
                break;
            }

            if (package.DataTimeStart > DateTime.Now)
            {
                result = CSResult.ItemIsNotCurrentAvailable;
            }

            if (package.DataTimeExpir < DateTime.Now)
            {
                //result = CSResult.ItemIsNotLongerAvailable;
            }

            if (CSResult.Ok == result)
            {
                _storage.Add(new Item((ushort)product.ItemId));
            }

            await _player.Session.SendAsync(new SCashItemBuy { Result = result });

            SendInventory(new CCashInventoryItem {
                Page = 0, InventoryType = 0
            });
        }
Пример #2
0
 public void CashItemBuy(GSSession session, CCashItemBuy message)
 {
     session.Player.Character.CashShop.BuyItem(message);
 }