/// <summary> /// 请求消耗物品 /// </summary> /// <param name="callback"></param> /// <param name="cost_goods_types"></param> /// <param name="cost_goods_counts"></param> /// <param name="cost_goods_params"></param> public void RequestCostGameGoods(RequestCostGameGoodsCallback callback, int[] cost_goods_types, int[] cost_goods_counts, int[] cost_goods_params) { RequestCostGameGoods(callback, cost_goods_types, ConvertIntArrToBigIntegerArr(cost_goods_counts), cost_goods_params); }
/// <summary> /// 请求消耗物品 /// </summary> /// <param name="callback"></param> /// <param name="cost_goods_types"></param> /// <param name="cost_goods_counts"></param> /// <param name="cost_goods_params"></param> public void RequestCostGameGoods(RequestCostGameGoodsCallback callback, int[] cost_goods_types, BigInteger[] cost_goods_counts, int[] cost_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, ((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; } } if (netCostResults.Count <= 0) { ApplyCostResults(localCostResults); callback?.Invoke(GoodsRequestResult.Success, 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); } //打开联网遮罩 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); callback?.Invoke(GoodsRequestResult.Success, null); } break; case ServerMgr.RequestCallbackState.DataFail: { GoodsRequestResult failResult = GoodsRequestResult.Undefine; string detail = 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; detail = ((int)costResult.costGoods.type).ToString(); break; } } callback?.Invoke(failResult, detail); } break; case ServerMgr.RequestCallbackState.NetFail: { callback?.Invoke(GoodsRequestResult.NetFail, null); } break; default: { callback?.Invoke(GoodsRequestResult.Undefine, null); } break; } }); } }
/// <summary> /// 请求消耗物品 /// </summary> /// <param name="callback"></param> /// <param name="cost_goods_type"></param> /// <param name="cost_goods_count"></param> /// <param name="cost_goods_param"></param> public void RequestCostGameGoods(RequestCostGameGoodsCallback callback, int cost_goods_type, BigInteger cost_goods_count, int cost_goods_param = 0) { RequestCostGameGoods(callback, new int[] { cost_goods_type }, new BigInteger[] { cost_goods_count }, new int[] { cost_goods_param }); }