public static void InitConfig() { XiLianTypeDict.Clear(); XiLianShuXingDict.Clear(); PropsIds.Clear(); PropsIds.Add((int)ExtPropIndexes.MaxLifeV); PropsIds.Add((int)ExtPropIndexes.AddAttackInjure); PropsIds.Add((int)ExtPropIndexes.DecreaseInjureValue); PropsIds.Add((int)ExtPropIndexes.AddAttack); PropsIds.Add((int)ExtPropIndexes.AddDefense); PropsIds.Add((int)ExtPropIndexes.HitV); PropsIds.Add((int)ExtPropIndexes.Dodge); PropsIds.Add((int)ExtPropIndexes.LifeSteal); XElement xml = null; string fileName = "Config/XiLianType.xml"; try { string fullPathFileName = fullPathFileName = Global.GameResPath("Config/XiLianType.xml"); //Global.IsolateResPath(fileName); xml = XElement.Load(fullPathFileName); if (null == xml) { throw new Exception(string.Format("加载系统xml配置文件:{0}, 失败。没有找到相关XML配置文件!", fullPathFileName)); } IEnumerable <XElement> nodes = null; nodes = xml.Elements(); foreach (var node in nodes) { XiLianType xiLianType = new XiLianType(); xiLianType.ID = (int)Global.GetSafeAttributeLong(node, "ID"); xiLianType.Color = Global.GetSafeAttributeStr(node, "Color"); xiLianType.ShuXingNum = (int)Global.GetSafeAttributeLong(node, "ShuXingNum"); xiLianType.Text = Global.GetSafeAttributeStr(node, "Text"); xiLianType.FirstShuXing = 0;// Global.GetSafeAttributeDouble(node, "FirstShuXing"); xiLianType.ShuXingLimitMultiplying = Global.GetSafeAttributeDouble(node, "Multiplying"); XiLianTypeDict.Add(xiLianType.ID, xiLianType); } } catch (Exception) { throw new Exception(string.Format("加载系统xml配置文件:{0}, 失败。", fileName)); } fileName = "Config/XiLianShuXing.xml"; try { string fullPathFileName = fullPathFileName = Global.GameResPath(fileName); //Global.IsolateResPath(fileName); xml = XElement.Load(fullPathFileName); if (null == xml) { throw new Exception(string.Format("加载系统xml配置文件:{0}, 失败。没有找到相关XML配置文件!", fullPathFileName)); } IEnumerable <XElement> nodes = null; nodes = xml.Elements(); foreach (var node in nodes) { ParseXiLianShuXing(node); } } catch (Exception ex) { throw new Exception(string.Format("加载系统xml配置文件:{0}, 失败。{1}", fileName, ex.ToString())); } try { XiLianChuanChengGoodsRates = GameManager.systemParamsList.GetParamValueIntArrayByName("XiLianChuanChengGoodsRates"); XiLianChuanChengXiaoHaoJinBi = GameManager.systemParamsList.GetParamValueIntArrayByName("XiLianChuanChengXiaoHaoJinBi"); XiLianChuanChengXiaoHaoZhuanShi = GameManager.systemParamsList.GetParamValueIntArrayByName("XiLianChuanChengXiaoHaoZhuanShi"); } catch (Exception ex) { throw new Exception(string.Format("加载系统xml配置文件:{0}, 失败。{1}", fileName, ex.ToString())); } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="leftGoodsDbID">左边物品ID,提供传承属性的物品,传承提供者</param> /// <param name="rightGoodsDbID">右边物品ID,获得传承属性的物品,传承接受者</param> /// <param name="nSubMoneyType">消耗钱类型 -- 1银两 2元宝</param> /// <returns></returns> public static bool WashPropsInherit(GameClient client, int leftGoodsDbID, int rightGoodsDbID, int nSubMoneyType) { int roleID = client.ClientData.RoleID; int nID = (int)TCPGameServerCmds.CMD_SPR_EXEC_WASHPROPSINHERIT; List <int> result = new List <int>(); result.Add(StdErrorCode.Error_Success); result.Add(leftGoodsDbID); result.Add(rightGoodsDbID); result.Add(0); //从物品包中获取传承提供者装备 GoodsData leftGoodsData = Global.GetGoodsByDbID(client, leftGoodsDbID); if (null == leftGoodsData) //没有找到物品 { result[0] = StdErrorCode.Error_Invalid_DBID; client.sendCmd(nID, result); return(true); } //从物品包中获取传承接受者装备 GoodsData rightGoodsData = Global.GetGoodsByDbID(client, rightGoodsDbID); if (null == rightGoodsData) //没有找到物品 { result[0] = StdErrorCode.Error_Invalid_DBID; client.sendCmd(nID, result); return(true); } SystemXmlItem xml; if (!GameManager.SystemGoods.SystemXmlItemDict.TryGetValue(rightGoodsData.GoodsID, out xml)) { //错误的参数 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } int id = xml.GetIntValue("XiLian"); XiLianShuXing xiLianShuXing; if (!XiLianShuXingDict.TryGetValue(id, out xiLianShuXing)) { //配置错误 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } /* 规则: * 1.剥离追加的装备颜色不能低于继承追加的装备颜色 * 2.剥离追加的装备追加级别不能低于继承追加的装备追加级别 * */ int nLeftColor = Global.GetEquipColor(leftGoodsData); int nRigthColor = Global.GetEquipColor(rightGoodsData); if (nLeftColor < 2 || nRigthColor < 2 || null == leftGoodsData.WashProps /* || null == rightGoodsData.WashProps*/) { result[0] = StdErrorCode.Error_Operation_Denied; client.sendCmd(nID, result); return(true); } XiLianType xiLianType = null; if (!XiLianTypeDict.TryGetValue(nRigthColor, out xiLianType)) { //配置错误 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } int OccupationLeft = Global.GetMainOccupationByGoodsID(leftGoodsData.GoodsID); int OccupationRight = Global.GetMainOccupationByGoodsID(rightGoodsData.GoodsID); // 装备职业 if (OccupationLeft != OccupationRight) { result[0] = StdErrorCode.Error_Operation_Denied; client.sendCmd(nID, result); return(true); } int categoryLeft = Global.GetGoodsCatetoriy(leftGoodsData.GoodsID); int categoryRight = Global.GetGoodsCatetoriy(rightGoodsData.GoodsID); if (categoryLeft >= 0 && categoryLeft <= 6 && categoryLeft == categoryRight) { //装备类型相同 } else if (categoryLeft == 10 && categoryLeft == categoryRight) { //装备类型相同 } else if (categoryLeft >= (int)ItemCategories.WuQi_Jian && categoryLeft <= (int)ItemCategories.WuQi_NuJianTong && categoryRight >= (int)ItemCategories.WuQi_Jian && categoryRight <= (int)ItemCategories.WuQi_NuJianTong) { //11到21都算相同(武器类) } else { result[0] = StdErrorCode.Error_Type_Not_Match; client.sendCmd(nID, result); return(true); } //如果物品不在背包中,拒绝操作 if (leftGoodsData.Site != 0 || rightGoodsData.Site != 0) { result[0] = StdErrorCode.Error_Goods_Not_Find; client.sendCmd(nID, result); return(true); } // 检测 银两或元宝 if (nSubMoneyType < 1 || nSubMoneyType > 2) { result[0] = StdErrorCode.Error_MoneyType_Not_Select; client.sendCmd(nID, result); return(true); } if (nSubMoneyType == 1) { if (XiLianChuanChengXiaoHaoJinBi[0] > 0 && !Global.SubBindTongQianAndTongQian(client, XiLianChuanChengXiaoHaoJinBi[0], "洗练属性传承")) { result[0] = StdErrorCode.Error_JinBi_Not_Enough; client.sendCmd(nID, result); return(true); } } else if (nSubMoneyType == 2) { if (XiLianChuanChengXiaoHaoZhuanShi[0] > 0 && !GameManager.ClientMgr.SubUserMoney(client, XiLianChuanChengXiaoHaoZhuanShi[0], "洗练属性传承")) { result[0] = StdErrorCode.Error_ZuanShi_Not_Enough; client.sendCmd(nID, result); return(true); } } //判断是否有需要传承的属性,没有就不传承了 当前只传承 强化 int nBinding = 0; if (rightGoodsData.Binding == 1 || leftGoodsData.Binding == 1) { nBinding = 1; } int rnd = Global.GetRandomNumber(0, 101); if (null != XiLianChuanChengGoodsRates && rnd > XiLianChuanChengGoodsRates[nLeftColor]) { result[0] = StdErrorCode.Error_Operation_Faild; client.sendCmd(nID, result); return(true); } UpdateGoodsArgs argsLeft = new UpdateGoodsArgs() { RoleID = roleID, DbID = leftGoodsDbID }; argsLeft.WashProps = new List <int>(leftGoodsData.WashProps); UpdateGoodsArgs argsRight = new UpdateGoodsArgs() { RoleID = roleID, DbID = rightGoodsDbID }; //如果没有洗练属性,先生成一份 if (null == rightGoodsData.WashProps || rightGoodsData.WashProps.Count == 0) { argsRight.WashProps = new List <int>(xiLianType.ShuXingNum * 2); int maxCount = 0; foreach (var kv in xiLianShuXing.PromotePropLimit) { if (kv.Value > 0) { argsRight.WashProps.Add(kv.Key); argsRight.WashProps.Add(0); if (++maxCount >= xiLianType.ShuXingNum) { break; } } } } else { argsRight.WashProps = new List <int>(rightGoodsData.WashProps); } //尝试纠正错误的属性 List <int> correctPropsList = new List <int>(); for (int i = 0; i < argsRight.WashProps.Count - 1; i += 2) { int propID = argsRight.WashProps[i]; int propLimit = 0; //如果属性列表已经包含了一次(不应该重复),或这个装备的培养属性不应该有这个属性(上限为0),则重新随机个属性给他 if (correctPropsList.Contains(propID) || !xiLianShuXing.PromotePropLimit.TryGetValue(propID, out propLimit) || propLimit <= 0) { foreach (var kv in xiLianShuXing.PromotePropLimit) { if (kv.Value > 0) { argsRight.WashProps[i] = kv.Key; argsRight.WashProps[i + 1] = 0; correctPropsList.Add(kv.Key); } } } else { correctPropsList.Add(propID); } } //两层循环,找到两件装备对应的属性,并传承(之所以写这么复杂,是因为dictionary的foreach枚举顺序是没有保证的,虽然绝大多数情况下是不变的) List <int> inhertPropsList = new List <int>(); for (int i = 0; i < argsLeft.WashProps.Count - 1; i += 2) { for (int j = 0; j < argsRight.WashProps.Count - 1; j += 2) { if (argsLeft.WashProps[i] == argsRight.WashProps[j]) { int propID = argsLeft.WashProps[i]; int propLimit = 0; inhertPropsList.Add(propID); argsRight.WashProps[j] = propID; if (xiLianShuXing.PromotePropLimit.TryGetValue(propID, out propLimit)) { argsRight.WashProps[j + 1] = (int)Math.Round(Global.Clamp(argsLeft.WashProps[i + 1], 0, propLimit * xiLianType.ShuXingLimitMultiplying)); } else { argsRight.WashProps[j + 1] = 0; } } } } //两层循环,找到两件装备不对应的装备(之所以写这么复杂,是因为dictionary的foreach枚举顺序是没有保证的,虽然绝大多数情况下是不变的) for (int i = 0; i < argsLeft.WashProps.Count - 1; i += 2) { if (!inhertPropsList.Contains(argsLeft.WashProps[i])) { inhertPropsList.Add(argsLeft.WashProps[i]); for (int j = 0; j < argsRight.WashProps.Count - 1; j += 2) { if (!inhertPropsList.Contains(argsRight.WashProps[j])) { inhertPropsList.Add(argsRight.WashProps[j]); int propID = argsRight.WashProps[j]; int propLimit = 0; argsRight.WashProps[i] = propID; if (xiLianShuXing.PromotePropLimit.TryGetValue(propID, out propLimit)) { //击中恢复和附加攻击之间按比例1:10转换,其他的类型的值不能传承。 if (argsLeft.WashProps[i] == (int)ExtPropIndexes.LifeSteal && argsRight.WashProps[j] == (int)ExtPropIndexes.AddAttack) { argsRight.WashProps[j + 1] = (int)Math.Floor(Global.Clamp(argsLeft.WashProps[i + 1] * 10, 0, propLimit * xiLianType.ShuXingLimitMultiplying)); } else if (argsLeft.WashProps[i] == (int)ExtPropIndexes.AddAttack && argsRight.WashProps[j] == (int)ExtPropIndexes.LifeSteal) { argsRight.WashProps[j + 1] = (int)Math.Floor(Global.Clamp(argsLeft.WashProps[i + 1] / 10, 0, propLimit * xiLianType.ShuXingLimitMultiplying)); } else { argsRight.WashProps[j + 1] = 0; } } else { argsRight.WashProps[j + 1] = 0; } } } } } argsLeft.WashProps = null; argsRight.Binding = nBinding; //清除已传承装备的上次培养记录属性 client.ClientData.TempWashPropsDict.Remove(argsLeft.DbID); client.ClientData.TempWashPropsDict.Remove(argsRight.DbID); if (Global.UpdateGoodsProp(client, leftGoodsData, argsLeft) < 0) { result[0] = StdErrorCode.Error_DB_Faild; client.sendCmd(nID, result); return(true); } if (Global.UpdateGoodsProp(client, rightGoodsData, argsRight) < 0) { result[0] = StdErrorCode.Error_DB_Faild; client.sendCmd(nID, result); return(true); } //写入角色物品的得失行为日志(扩展) Global.ModRoleGoodsEvent(client, leftGoodsData, 0, "装备洗炼传承_提供方"); Global.ModRoleGoodsEvent(client, rightGoodsData, 0, "装备洗炼传承_接受方"); EventLogManager.AddGoodsEvent(client, OpTypes.Forge, OpTags.None, leftGoodsData.GoodsID, leftGoodsData.Id, 0, leftGoodsData.GCount, "装备洗炼传承_提供方"); EventLogManager.AddGoodsEvent(client, OpTypes.Forge, OpTags.None, rightGoodsData.GoodsID, rightGoodsData.Id, 0, rightGoodsData.GCount, "装备洗炼传承_接受方"); //Global.BroadcastAppendChuanChengOk(client, leftGoodsData, rightGoodsData); //如果有物品是穿戴的,更新角色属性 if (leftGoodsData.Using > 0 || rightGoodsData.Using > 0) { Global.RefreshEquipPropAndNotify(client); } // 更新成就 //ChengJiuManager.OnFirstJiCheng(client); // 七日活动 GlobalEventSource.getInstance().fireEvent(SevenDayGoalEvPool.Alloc(client, ESevenDayGoalFuncType.EquipChuanChengTimes)); result[3] = nBinding; result.AddRange(rightGoodsData.WashProps); client.sendCmd(nID, result); return(true); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="leftGoodsDbID">左边物品ID,提供传承属性的物品,传承提供者</param> /// <param name="rightGoodsDbID">右边物品ID,获得传承属性的物品,传承接受者</param> /// <param name="nSubMoneyType">消耗钱类型 -- 1银两 2元宝</param> /// <returns></returns> public static bool WashPropsInherit(GameClient client, int leftGoodsDbID, int rightGoodsDbID, int nSubMoneyType) { int roleID = client.ClientData.RoleID; int nID = (int)TCPGameServerCmds.CMD_SPR_EXEC_WASHPROPSINHERIT; List <int> result = new List <int>(); result.Add(StdErrorCode.Error_Success); result.Add(leftGoodsDbID); result.Add(rightGoodsDbID); result.Add(0); //从物品包中获取传承提供者装备 GoodsData leftGoodsData = Global.GetGoodsByDbID(client, leftGoodsDbID); if (null == leftGoodsData) //没有找到物品 { result[0] = StdErrorCode.Error_Invalid_DBID; client.sendCmd(nID, result); return(true); } //从物品包中获取传承接受者装备 GoodsData rightGoodsData = Global.GetGoodsByDbID(client, rightGoodsDbID); if (null == rightGoodsData) //没有找到物品 { result[0] = StdErrorCode.Error_Invalid_DBID; client.sendCmd(nID, result); return(true); } SystemXmlItem xml; if (!GameManager.SystemGoods.SystemXmlItemDict.TryGetValue(rightGoodsData.GoodsID, out xml)) { //错误的参数 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } int id = xml.GetIntValue("XiLian"); XiLianShuXing xiLianShuXing; if (!XiLianShuXingDict.TryGetValue(id, out xiLianShuXing)) { //配置错误 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } /* 规则: * 1.剥离追加的装备颜色不能低于继承追加的装备颜色 * 2.剥离追加的装备追加级别不能低于继承追加的装备追加级别 * */ int nLeftColor = Global.GetEquipColor(leftGoodsData); int nRigthColor = Global.GetEquipColor(rightGoodsData); if (nLeftColor < 2 || nRigthColor < 2 || null == leftGoodsData.WashProps /* || null == rightGoodsData.WashProps*/) { result[0] = StdErrorCode.Error_Operation_Denied; client.sendCmd(nID, result); return(true); } XiLianType xiLianType = null; if (!XiLianTypeDict.TryGetValue(nRigthColor, out xiLianType)) { //配置错误 result.Add(StdErrorCode.Error_Config_Fault); client.sendCmd(nID, result); return(true); } int OccupationLeft = Global.GetGoodsToOccupation(leftGoodsData.GoodsID); int OccupationRight = Global.GetGoodsToOccupation(rightGoodsData.GoodsID); // 装备职业 if (OccupationLeft != OccupationRight) { result[0] = StdErrorCode.Error_Operation_Denied; client.sendCmd(nID, result); return(true); } int categoryLeft = Global.GetGoodsCatetoriy(leftGoodsData.GoodsID); int categoryRight = Global.GetGoodsCatetoriy(rightGoodsData.GoodsID); if (categoryLeft >= 0 && categoryLeft <= 6 && categoryLeft == categoryRight) { //装备类型相同 } else if (categoryLeft == 10 && categoryLeft == categoryRight) { //装备类型相同 } else if (categoryLeft >= (int)ItemCategories.WuQi_Jian && categoryLeft <= (int)ItemCategories.WuQi_NuJianTong && categoryRight >= (int)ItemCategories.WuQi_Jian && categoryRight <= (int)ItemCategories.WuQi_NuJianTong) { //11到21都算相同(武器类) } else { result[0] = StdErrorCode.Error_Type_Not_Match; client.sendCmd(nID, result); return(true); } //如果物品不在背包中,拒绝操作 if (leftGoodsData.Site != 0 || rightGoodsData.Site != 0) { result[0] = StdErrorCode.Error_Goods_Not_Find; client.sendCmd(nID, result); return(true); } // 检测 银两或元宝 if (nSubMoneyType < 1 || nSubMoneyType > 2) { result[0] = StdErrorCode.Error_MoneyType_Not_Select; client.sendCmd(nID, result); return(true); } if (nSubMoneyType == 1) { if (XiLianChuanChengXiaoHaoJinBi[0] > 0 && !Global.SubBindTongQianAndTongQian(client, XiLianChuanChengXiaoHaoJinBi[0], "洗练属性传承")) { result[0] = StdErrorCode.Error_JinBi_Not_Enough; client.sendCmd(nID, result); return(true); } } else if (nSubMoneyType == 2) { if (XiLianChuanChengXiaoHaoZhuanShi[0] > 0 && !GameManager.ClientMgr.SubUserMoney(client, XiLianChuanChengXiaoHaoZhuanShi[0], "洗练属性传承")) { result[0] = StdErrorCode.Error_ZuanShi_Not_Enough; client.sendCmd(nID, result); return(true); } } //判断是否有需要传承的属性,没有就不传承了 当前只传承 强化 int nBinding = 0; if (rightGoodsData.Binding == 1 || leftGoodsData.Binding == 1) { nBinding = 1; } int rnd = Global.GetRandomNumber(0, 101); if (null != XiLianChuanChengGoodsRates && rnd > XiLianChuanChengGoodsRates[nLeftColor]) { result[0] = StdErrorCode.Error_Operation_Faild; client.sendCmd(nID, result); return(true); } UpdateGoodsArgs argsLeft = new UpdateGoodsArgs() { RoleID = roleID, DbID = leftGoodsDbID }; argsLeft.WashProps = null; UpdateGoodsArgs argsRight = new UpdateGoodsArgs() { RoleID = roleID, DbID = rightGoodsDbID }; if (null == rightGoodsData.WashProps) { argsRight.WashProps = new List <int>(leftGoodsData.WashProps.GetRange(0, xiLianType.ShuXingNum * 2)); for (int i = 0; i < xiLianType.ShuXingNum; i++) { if (i * 2 + 1 >= leftGoodsData.WashProps.Count || i * 2 + 1 >= xiLianType.ShuXingNum * 2) { break; } int propID = leftGoodsData.WashProps[i * 2]; int propLimit = 0; if (xiLianShuXing.PromotePropLimit.TryGetValue(propID, out propLimit)) { argsRight.WashProps[i * 2] = propID; argsRight.WashProps[i * 2 + 1] = (int)Math.Round(Global.Clamp(leftGoodsData.WashProps[i * 2 + 1], 0, propLimit * xiLianType.ShuXingLimitMultiplying)); } } } else { argsRight.WashProps = new List <int>(rightGoodsData.WashProps); for (int i = 0; i < xiLianType.ShuXingNum; i++) { if (i * 2 + 1 >= leftGoodsData.WashProps.Count || i * 2 + 1 >= rightGoodsData.WashProps.Count) { break; } int propID = leftGoodsData.WashProps[i * 2]; int propLimit = 0; if (xiLianShuXing.PromotePropLimit.TryGetValue(propID, out propLimit)) { argsRight.WashProps[i * 2] = propID; argsRight.WashProps[i * 2 + 1] = (int)Math.Round(Global.Clamp(leftGoodsData.WashProps[i * 2 + 1], 0, propLimit * xiLianType.ShuXingLimitMultiplying)); } } } argsRight.Binding = nBinding; if (Global.UpdateGoodsProp(client, leftGoodsData, argsLeft) < 0) { result[0] = StdErrorCode.Error_DB_Faild; client.sendCmd(nID, result); return(true); } if (Global.UpdateGoodsProp(client, rightGoodsData, argsRight) < 0) { result[0] = StdErrorCode.Error_DB_Faild; client.sendCmd(nID, result); return(true); } //写入角色物品的得失行为日志(扩展) Global.ModRoleGoodsEvent(client, leftGoodsData, 0, "装备洗炼传承_提供方"); Global.ModRoleGoodsEvent(client, rightGoodsData, 0, "装备洗炼传承_接受方"); //Global.BroadcastAppendChuanChengOk(client, leftGoodsData, rightGoodsData); //如果有物品是穿戴的,更新角色属性 if (leftGoodsData.Using > 0 || rightGoodsData.Using > 0) { Global.RefreshEquipPropAndNotify(client); } // 更新成就 //ChengJiuManager.OnFirstJiCheng(client); result[3] = nBinding; result.AddRange(rightGoodsData.WashProps); client.sendCmd(nID, result); return(true); }