/// <summary> /// 处理用钥匙类物品打开箱子类物品挖宝的操作 /// </summary> /// <param name="client"></param> /// <param name="pool"></param> /// <param name="cmd"></param> /// <param name="idXiangZi"></param> /// <param name="idYaoShi"></param> /// <returns></returns> public static TCPOutPacket ProcessWaBaoByYaoShi(GameClient client, TCPOutPacketPool pool, int cmd, int idXiangZi, int idYaoShi, bool autoBuy) { GoodsData goodsData = new GoodsData() { Id = -1, }; //如果为开启挖宝,则返回 if ("1" != GameManager.GameConfigMgr.GetGameConfigItemStr("keydigtreasure", "1")) { goodsData.Id = -20; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } //返回可以开启箱子的钥匙ID列表 Dictionary <int, int> dictYaoShi = Global.GetYaoShiDiaoLuoForXiangZhi(idXiangZi); //非法的箱子ID if (null == dictYaoShi || dictYaoShi.Count <= 0) { goodsData.Id = -30; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } //判读钥匙是否能打开箱子 bool bCanOpen = false; foreach (var key in dictYaoShi.Keys) { if (key == idYaoShi) { bCanOpen = true; break; } } //钥匙不能打开箱子 if (!bCanOpen) { goodsData.Id = -50; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } //箱子和钥匙是否存在的判断 bool existXiangZi = true; bool existYaoShi = true; //是否需要扣除箱子, 钥匙 bool needSubXiangZi = true; bool needSubYaoShi = true; //判读背包是否有一个位置 if (!Global.CanAddGoodsNum(client, 1)) { goodsData.Id = -300; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } //需要自动购买的列表 Dictionary <int, int> needGoods = new Dictionary <int, int>(); //判断用户背包中是否有箱子类物品 if (Global.GetTotalGoodsCountByID(client, idXiangZi) <= 0) { existXiangZi = false; needGoods.Add(idXiangZi, 1); } //钥匙ID是0,表示直接打开,不用钥匙,钥匙ID不等于0的时候才需要进一步判断 if (0 != idYaoShi) { //判断用户背包中是否有钥匙类物品 if (Global.GetTotalGoodsCountByID(client, idYaoShi) <= 0) { existYaoShi = false; needGoods.Add(idYaoShi, 1); } } //扣除之前的钱 int oldMoney = client.ClientData.UserMoney; int subMoney = 0; //缺少物品时 if (needGoods.Count > 0) { //如果能自动购买 if (autoBuy) { //自动扣除元宝 subMoney = Global.SubUserMoneyForGoods(client, needGoods, "精雕细琢挖宝"); if (subMoney > 0) { //扣除成功后,本来没有的,就不用扣除 if (!existXiangZi) { needSubXiangZi = false; } if (!existYaoShi) { needSubYaoShi = false; } } else { //自动扣除元宝出错,返回值就是错误码 goodsData.Id = subMoney; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } } else//不能自动购买,则判断是哪出错了,提示客户端 { //没有箱子类物品 if (!existXiangZi) { goodsData.Id = -100; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } //没有钥匙类物品 if (!existYaoShi) { goodsData.Id = -200; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } } } //钥匙ID是0,表示直接打开,不用钥匙,钥匙ID不等于0的时候才需要进一步判断 if (0 == idYaoShi) { needSubYaoShi = false; } //采用开箱子的方式挖取到物品,挖取成功时顺便扣除物品,这样避免挖宝过程中出错先扣物品 GoodsData retGoodsData = null; int ret = GoodsBaoXiang.ProcessFallByYaoShiWaBao(client, dictYaoShi[idYaoShi], needSubYaoShi ? idYaoShi : -1, needSubXiangZi ? idXiangZi : -1, out retGoodsData, (0 == idYaoShi) ? 1 : 0, subMoney); //没有挖到物品 if (ret <= 0 || null == retGoodsData) { goodsData.Id = ret; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } goodsData = retGoodsData; //挖宝成功的提示 Global.BroadcastYaoShiWaBaoGoodsHint(client, goodsData, idYaoShi, idXiangZi); //记录挖宝成功日志 Global.AddDigTreasureWithYaoShiEvent(client, idYaoShi, idXiangZi, needSubYaoShi ? 1 : 0, needSubXiangZi ? 1 : 0, subMoney, oldMoney, client.ClientData.UserMoney, goodsData); return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); }
public static TCPOutPacket ProcessWaBaoByYaoShi(GameClient client, TCPOutPacketPool pool, int cmd, int idXiangZi, int idYaoShi, bool autoBuy) { GoodsData goodsData = new GoodsData { Id = -1 }; TCPOutPacket result; if ("1" != GameManager.GameConfigMgr.GetGameConfigItemStr("keydigtreasure", "1")) { goodsData.Id = -20; result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } else { Dictionary <int, int> dictYaoShi = Global.GetYaoShiDiaoLuoForXiangZhi(idXiangZi); if (dictYaoShi == null || dictYaoShi.Count <= 0) { goodsData.Id = -30; result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } else { bool bCanOpen = false; foreach (int key in dictYaoShi.Keys) { if (key == idYaoShi) { bCanOpen = true; break; } } if (!bCanOpen) { goodsData.Id = -50; result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } else { bool existXiangZi = true; bool existYaoShi = true; bool needSubXiangZi = true; bool needSubYaoShi = true; if (!Global.CanAddGoodsNum(client, 1)) { goodsData.Id = -300; result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } else { Dictionary <int, int> needGoods = new Dictionary <int, int>(); if (Global.GetTotalGoodsCountByID(client, idXiangZi) <= 0) { existXiangZi = false; needGoods.Add(idXiangZi, 1); } if (0 != idYaoShi) { if (Global.GetTotalGoodsCountByID(client, idYaoShi) <= 0) { existYaoShi = false; needGoods.Add(idYaoShi, 1); } } int oldMoney = client.ClientData.UserMoney; int subMoney = 0; if (needGoods.Count > 0) { if (autoBuy) { subMoney = Global.SubUserMoneyForGoods(client, needGoods, "精雕细琢挖宝"); if (subMoney <= 0) { goodsData.Id = subMoney; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } if (!existXiangZi) { needSubXiangZi = false; } if (!existYaoShi) { needSubYaoShi = false; } } else { if (!existXiangZi) { goodsData.Id = -100; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } if (!existYaoShi) { goodsData.Id = -200; return(DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd)); } } } if (0 == idYaoShi) { needSubYaoShi = false; } GoodsData retGoodsData = null; int ret = GoodsBaoXiang.ProcessFallByYaoShiWaBao(client, dictYaoShi[idYaoShi], needSubYaoShi ? idYaoShi : -1, needSubXiangZi ? idXiangZi : -1, out retGoodsData, (idYaoShi == 0) ? 1 : 0, subMoney); if (ret <= 0 || null == retGoodsData) { goodsData.Id = ret; result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } else { goodsData = retGoodsData; Global.BroadcastYaoShiWaBaoGoodsHint(client, goodsData, idYaoShi, idXiangZi); Global.AddDigTreasureWithYaoShiEvent(client, idYaoShi, idXiangZi, needSubYaoShi ? 1 : 0, needSubXiangZi ? 1 : 0, subMoney, oldMoney, client.ClientData.UserMoney, goodsData); result = DataHelper.ObjectToTCPOutPacket <GoodsData>(goodsData, pool, cmd); } } } } } return(result); }