Пример #1
0
        /// <summary>
        /// 直接添加至本地
        /// </summary>
        /// <param name="goodsList"></param>
        public void AddLocalGameGoods(List <GameGoodData> goodsList)
        {
            List <GameGoodsAddResult> localAddResults = new List <GameGoodsAddResult>();

            for (int i = 0; i < goodsList.Count; i++)
            {
                GameGoodsAddResult addResult = CheckGoodsAddResult((int)goodsList[i].type, goodsList[i].count, goodsList[i].param);
                if (addResult == null || addResult.requestType == GoodsRequestType.Undefine)
                {
                    continue;
                }
                localAddResults.Add(addResult);
            }

            List <GameGoodData> realAddGoods = new List <GameGoodData>();
            HashSet <string>    tips         = new HashSet <string>();

            MergeGoodsAddResult(localAddResults, realAddGoods, tips);
            AddGameGoods(realAddGoods);
        }
Пример #2
0
        /// <summary>
        /// 请求消耗物品以添加物品
        /// </summary>
        /// <param name="callback"></param>
        /// <param name="cost_goods_types"></param>
        /// <param name="cost_goods_counts"></param>
        /// <param name="cost_goods_params"></param>
        /// <param name="add_goods_types"></param>
        /// <param name="add_goods_counts"></param>
        /// <param name="add_goods_params"></param>
        public void RequestCostAddGameGoods(RequestCostAddGameGoodsCallback callback,
                                            int[] cost_goods_types, BigInteger[] cost_goods_counts, int[] cost_goods_params,
                                            int[] add_goods_types, BigInteger[] add_goods_counts, int[] add_goods_params)
        {
            List <GameGoodsCostResult> localCostResults = new List <GameGoodsCostResult>();
            List <GameGoodsCostResult> netCostResults   = new List <GameGoodsCostResult>();

            for (int i = 0; i < cost_goods_types.Length; i++)
            {
                var costResult = CheckGoodsCostResult(cost_goods_types[i], cost_goods_counts[i], cost_goods_params[i]);
                if (costResult == null || costResult.requestType == GoodsRequestType.Undefine)
                {
                    continue;
                }
                if (!costResult.canCost)
                {
                    callback?.Invoke(GoodsRequestResult.DataFail_NotEnough, null, null, ((int)costResult.costGoods.type).ToString());
                    return;
                }

                switch (costResult.requestType)
                {
                case GoodsRequestType.Local:
                    localCostResults.Add(costResult);
                    break;

                case GoodsRequestType.Network:
                    netCostResults.Add(costResult);
                    break;

                default:
                    break;
                }
            }

            List <GameGoodsAddResult> localAddResults = new List <GameGoodsAddResult>();
            List <GameGoodsAddResult> netAddResults   = new List <GameGoodsAddResult>();

            for (int i = 0; i < add_goods_types.Length; i++)
            {
                GameGoodsAddResult addResult = CheckGoodsAddResult(add_goods_types[i], add_goods_counts[i], add_goods_params[i]);
                if (addResult == null || addResult.requestType == GoodsRequestType.Undefine)
                {
                    continue;
                }
                switch (addResult.requestType)
                {
                case GoodsRequestType.Local:
                    localAddResults.Add(addResult);
                    break;

                case GoodsRequestType.Network:
                    netAddResults.Add(addResult);
                    break;

                default:
                    break;
                }
            }

            if (netCostResults.Count <= 0 && netAddResults.Count <= 0)
            {
                List <GameGoodData> realAddGoods = new List <GameGoodData>();
                HashSet <string>    tips         = new HashSet <string>();
                MergeGoodsAddResult(localAddResults, realAddGoods, tips);
                AddGameGoods(realAddGoods);
                ApplyCostResults(localCostResults);
                callback?.Invoke(GoodsRequestResult.Success, realAddGoods, tips, null);
            }
            else
            {
                List <int> request_types  = new List <int>();
                List <int> request_counts = new List <int>();
                List <int> request_params = new List <int>();
                for (int i = 0; i < netCostResults.Count; i++)
                {
                    var goods = netCostResults[i].costGoods;
                    request_types.Add((int)goods.type);
                    request_counts.Add(-(int)goods.count);//暂时使用强制转换 之后有大数字请求 需与服务器进行商讨确定
                    request_params.Add(goods.param);
                }
                for (int i = 0; i < netAddResults.Count; i++)
                {
                    for (int j = 0; j < netAddResults[i].realAddGoods.Count; j++)
                    {
                        var goods = netAddResults[i].realAddGoods[j];
                        request_types.Add((int)goods.type);
                        request_counts.Add((int)goods.count);//暂时使用强制转换 之后有大数字请求 需与服务器进行商讨确定
                        request_params.Add(goods.param);
                    }
                }
                //打开联网遮罩
                Global.gApp.gUiMgr.OpenPanel(Wndid.LoadingUI);
                ServerMgr.singleton.RequestAddDelResource(request_types.ToArray(), request_counts.ToArray(), request_params.ToArray(), (state) =>
                {
                    //关闭联网遮罩
                    Global.gApp.gUiMgr.ClosePanel(Wndid.LoadingUI);
                    switch (state)
                    {
                    case ServerMgr.RequestCallbackState.Success:
                        {
                            ApplyCostResults(localCostResults);
                            BroadcastCostResults(netCostResults);
                            List <GameGoodData> realAddGoods = new List <GameGoodData>();
                            HashSet <string> tips            = new HashSet <string>();
                            MergeGoodsAddResult(localAddResults, realAddGoods, tips);
                            AddGameGoods(realAddGoods);    //之后本地物品需要实际添加
                            MergeGoodsAddResult(netAddResults, realAddGoods, tips);
                            callback?.Invoke(GoodsRequestResult.Success, realAddGoods, tips, null);
                        }
                        break;

                    case ServerMgr.RequestCallbackState.DataFail:
                        {
                            GoodsRequestResult failResult = GoodsRequestResult.Undefine;
                            string failDetail             = null;
                            for (int i = 0; i < cost_goods_types.Length; i++)
                            {
                                var costResult = CheckGoodsCostResult(cost_goods_types[i], cost_goods_counts[i], cost_goods_params[i]);
                                if (costResult == null || costResult.requestType == GoodsRequestType.Undefine)
                                {
                                    continue;
                                }
                                if (!costResult.canCost)
                                {
                                    failResult = GoodsRequestResult.DataFail_NotEnough;
                                    failDetail = ((int)costResult.costGoods.type).ToString();
                                    break;
                                }
                            }

                            BroadcastCostResults(netCostResults);
                            callback?.Invoke(failResult, null, null, failDetail);
                        }
                        break;

                    case ServerMgr.RequestCallbackState.NetFail:
                        {
                            callback?.Invoke(GoodsRequestResult.NetFail, null, null, null);
                        }
                        break;

                    default:
                        {
                            callback?.Invoke(GoodsRequestResult.Undefine, null, null, null);
                        }
                        break;
                    }
                });
            }
        }
Пример #3
0
        private GameGoodsAddResult CheckGoodsAddResult(int goods_type, BigInteger goods_count, int goods_param)
        {
            GameGoodsAddResult result    = null;
            GoodsType          goodsType = (GoodsType)goods_type;

            switch (goodsType)
            {
            case GoodsType.DIAMOND:
            {
                result = new GameGoodsAddResult();
#if SERVER_CHECK
                result.requestType = GoodsRequestType.Network;
#else
                result.requestType = GoodsRequestType.Local;
#endif
                result.realAddGoods = new List <GameGoodData>()
                {
                    new GameGoodData()
                    {
                        type  = (GoodsType)goods_type,
                        count = goods_count,
                        param = goods_param,
                    }
                };
            }
            break;

            case GoodsType.GOLD:
            case GoodsType.KEY:
            case GoodsType.CAMPSITE_REWARD:
            {
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>()
                {
                    new GameGoodData()
                    {
                        type  = (GoodsType)goods_type,
                        count = goods_count,
                        param = goods_param,
                    }
                };
            }
            break;

            case GoodsType.CARD:
            {
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>();
                result.tips         = new HashSet <string>();
                CheckCardRealAdd((int)goods_count, goods_param, result.realAddGoods, result.tips);
            }
            break;

            case GoodsType.CARD_CHIP:
            {
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>();
                result.tips         = new HashSet <string>();
                CheckCardClipRealAdd((int)goods_count, goods_param, result.realAddGoods, result.tips);
            }
            break;

            case GoodsType.RANDOM_CARD:
            {
                List <int> cardList = PlayerDataMgr.singleton.GetDropCardsByQuality(goods_param);
                var        index    = BaseRandom.Next(0, cardList.Count);
                var        id       = cardList[index];
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>();
                result.tips         = new HashSet <string>();
                CheckCardRealAdd((int)goods_count, id, result.realAddGoods, result.tips);
            }
            break;

            case GoodsType.RANDOM_CARD_CHIP:
            {
                List <int> cardList = PlayerDataMgr.singleton.GetDropCardsByQuality(goods_param);
                var        index    = BaseRandom.Next(0, cardList.Count);
                var        id       = cardList[index];
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>();
                result.tips         = new HashSet <string>();
                CheckCardClipRealAdd((int)goods_count, id, result.realAddGoods, result.tips);
            }
            break;

            case GoodsType.GOLD_MINUTE:
            {
                var count = goods_count * IdleRewardMgr.singleton.GetGoldPerMinute();
                result              = new GameGoodsAddResult();
                result.requestType  = GoodsRequestType.Local;
                result.realAddGoods = new List <GameGoodData>()
                {
                    new GameGoodData()
                    {
                        type  = GoodsType.GOLD,
                        count = count,
                        param = goods_param,
                    }
                };
            }
            break;

            default:
                break;
            }

            return(result);
        }