Example #1
0
        private bool CheckExchangeVipResult()
        {
            var res = _requestExchangeVipResult.Read(true);

            if (res == null)
            {
                return(false);
            }

            Waiting(false);

            if (res.result.code == ResultCode.OK)
            {
                // 提示玩家成功购买VIP。
                string content;
                if (_lastVipExchangeRequest != null)
                {
                    content = string.Format("恭喜您,成功{0}VIP!", VipExchangeType.LabelOf(_lastVipExchangeRequest.type));
                }
                else
                {
                    content = "恭喜您,成功购买VIP!";
                }
                _dialogManager.ShowConfirmBox(content);

                // 重新请求一遍Vip列表。
                RequestVipExchangeList();
                // 这里重新请求玩家数据,会比较保险。
                // 重新请求一下用户数据。
                RequestUserInfo();

                // 播放一下使用金蛋的声音。
                _soundController.PlayUseGoldSound();

                var count = 0L;
                if (_lastVipExchangeRequest != null)
                {
                    var price = _lastVipExchangeRequest.price;
                    if (price != null)
                    {
                        count = DataUtil.CalculateGeValue(price.type, price.count);
                    }
                }

                _analyticManager.Buy("vip", 1, count);
                _analyticManager.Event("exchange_vip_ok");
            }
            else
            {
                if (!string.IsNullOrEmpty(res.result.msg))
                {
                    Toast(res.result.msg, true);
                }

                _analyticManager.Event("exchange_vip_fail");
            }

            _lastVipExchangeRequest = null;
            return(true);
        }
Example #2
0
        private bool CheckBuyCommodityResult()
        {
            var res = _buyCommodityResult.Read();

            if (res == null)
            {
                return(false);
            }

            _dialogManager.ShowWaitingDialog(false);

            if (res.result == ResultCode.OK)
            {
                // 购买成功。
                AddCommodity(res.name);

                // 更新玩家的钱。
                var user = _user.Read();
                GameUtil.SetMyCurrency(user, CurrencyType.GOLDEN_EGG, res.current_money);
                GameUtil.SetMyCurrency(user, CurrencyType.YIN_PIAO, res.current_second_money);
                _user.Invalidate(Time.time);

                // 播放用钱的声音。
                _soundController.PlayUseGoldSound();
                _dialogManager.ShowConfirmBox(
                    "恭喜您,成功购买商品^_^",
                    true, "立即使用", () => UseCommodity(res.name, true),
                    false, null, null,
                    true, true, true);

                // 统计
                var commodityList = _commodityList.Read();
                var commodity     = GameUtil.GetCommodity(commodityList, res.name);
                if (commodity != null)
                {
                    var type  = CommodityHelper.GetCurrencyType(commodity);
                    var price = CommodityHelper.GetPrice(commodity);
                    var count = DataUtil.CalculateGeValue(type, price);
                    _analyticManager.Buy(res.name, 1, count);
                }
            }
            else
            {
                // 购买失败,显示错误信息。
                switch (res.result)
                {
                case ResultCode.COMMODITY_NOT_FOUND:
                    _dialogManager.ShowToast("购买失败,商品不存在!", 2, true);
                    break;

                case ResultCode.COMMODITY_BUY_LEVEL_LIMIT:
                    _dialogManager.ShowToast("购买失败,您的等级不够!", 2, true);
                    break;

                case ResultCode.COMMODITY_BUY_VIP_LIMIT:
                    _dialogManager.ShowToast("购买失败,您的VIP等级不够!", 2, true);
                    break;

                case ResultCode.COMMODITY_BUY_MONEY_LIMIT:
                    _dialogManager.ShowToast("购买失败,您的钱不够!", 2, true);
                    break;

                case ResultCode.CURRENCY_NOT_SUPPORTED:
                    _dialogManager.ShowToast("购买失败,商品数据错误!", 2, true);
                    break;

                    // 默认情况下等待服务器端发送的Toast。
                }
            }

            // 读取过结果之后,就可以清空这个结果了。
            _buyCommodityResult.ClearAndInvalidate(Time.time);
            return(true);
        }