Example #1
0
 public void OnBuyButtonClicked()
 {
     if (handler != null)
     {
         CBuyMessage message = handler.getBuyMessage();
         Client.Instance.Send(message);
         Debug.Log("FrontEnd: Receive BuyButtonClicked");
         foreach (var i in message.items)
         {
             handler.RemoveFromCart(i.name);
         }
     }
 }
Example #2
0
    public CBuyMessage getBuyMessage()
    {
        CBuyMessage message = new CBuyMessage();

        message.dbid = World.Instance.selfDbid;
        foreach (var kv in m_items)
        {
            var name     = kv.Key;
            var item     = kv.Value;
            int count    = m_count[name];
            var treasure = GetTreasureByName(name);
            for (int i = 0; i < count; ++i)
            {
                message.items.Add(treasure);
            }
        }
        return(message);
    }
Example #3
0
        private void OnRecvBuy(IChannel channel, Message message)
        {
            Player      player   = channel.GetContent() as Player;
            CBuyMessage request  = message as CBuyMessage;
            SBuyMessage response = new SBuyMessage();

            response.success = false;
            Console.WriteLine("Backend: OnRecvBuy.cs");
            var conn      = db.Instance.Connect();
            int totalCost = 0;
            int mark      = 0;
            int silver    = 0;
            int gold      = 0;

            foreach (var item in request.items)
            {
                totalCost += item.price;
                if (item.type != 'e')
                {
                    mark  = 1;
                    gold += item.price;
                }
                else
                {
                    silver += item.price;
                }
                Console.WriteLine(string.Format("item_name: {0}", item.name));
            }
            response.gold   = gold;
            response.silver = silver;
            Console.WriteLine(string.Format("player_goldcoin: {0}; player_silvercoin: {1}", Database.Instance.GetGoldCoins(player.dbid), Database.Instance.GetSilverCoins(player.dbid)));
            if (db.Instance.BuyItems(request.items, gold, silver, player.dbid, mark, conn))
            {
                response.success = true;
            }
            response.items = db.Instance.GetInventory(request.dbid, conn);
            channel.Send(response);
            Console.WriteLine("Backend : Finish OnRecvBuy");
        }