using System.Collections.Generic; using System.Linq; using Org.BouncyCastle.Bcpg; using Sog; using ProtoCSStruct; using Google.Protobuf.WellKnownTypes; namespace Game { public class EquipmentSvc { public static void OnPlayerOnline(PlayerOnGame player) { UpdateEquipEnchant(player, GameServerUtils.GetTimeSecond(), false); } public static void OnPlayerBorn(PlayerOnGame player) { //15 仓库 仓库解锁消耗道具数量(0为默认解锁) 0;10000;10000;10000 //16 仓库 仓库解锁消耗道具id Gold var list = CommParamDescMgr.Instance.WareRoomCostNum.int_list; for(int i = 0; i < list.Length;i++) { var g = list[i]; if(g == 0) { player.RoleData.PandoraBag.EuqipDepotCount++; } } if(CommParamDescMgr.Instance.DefaultWeapon.str_list.Length > 0) { var eidx = AddEquip(player, CommParamDescMgr.Instance.DefaultWeapon.str_list[0] + ""); if (eidx >= 0) { WearEquip(player, eidx, (int)EquipmentPos.LeftGun, false); } if(CommParamDescMgr.Instance.DefaultWeapon.str_list.Length > 1) { eidx = AddEquip(player, CommParamDescMgr.Instance.DefaultWeapon.str_list[1] + ""); if (eidx >= 0) { WearEquip(player, eidx, (int)EquipmentPos.RightGun, false); } } } //string str = "Helm_1001;Helm_1003;Armo_1003;Armo_1004;Glov_1002;Glov_1003;Trou_1002;Trou_1004;Shoe_1001;Shoe_1003;Atta_1001;Atta_1003;Acce_1003;Acce_1004;Chip_1002;Chip_1004;Chip_1006;Chip_1007;Chip_1008;Chip_1010;Chip_1012;721001;723001;725001;725002;731001;733001;735001;735002;761001;763001;765001;765002;741001;743001;745001;745002;711001;713001;715001;715002;751001;753001;755001;755002"; //var arr = str.Split(";"); //foreach(var s in arr) //{ // AddEquip(player, s); //} } public static bool IsValidEquip(ref DBEquipment equip) { if (equip.DescId == 0 || equip.Level <= 0 || equip.AddProp.Count == 0) { return false; } //if (! IsValidQuality(equip.Quality)) //{ // return false; //} //if (! IsValidPos(equip.Pos)) //{ // return false; //} return true; } // public static bool IsValidPos(int pos) // { // return (int) EquipmentPos.None < pos && pos < (int) EquipmentPos.Max; // } public static CSErrCode WearEquip(PlayerOnGame player, int equipId, int pos = -1, bool isNotify = true, bool calcProp = true) { if (pos <= (int)EquipmentPos.None && pos != -1 || pos >= (int)EquipmentPos.Max) { return CSErrCode.Fail; } //穿戴 var equip = new DBEquipment() { SerialNum = -1 }; int idx = -1; for (int i = 0; i < player.RoleData.PandoraBag.EquipList.Count; i++) { ref var eq = ref player.RoleData.PandoraBag.EquipList[i]; if (eq.SerialNum == equipId) { equip.CopyFrom(ref eq); idx = i; break; } } if (idx != -1) { var desc = EquipDescMgr.Instance.GetConfigByInternal(equip.DescId); if (pos == (int)EquipmentPos.RightGun) { if (desc.type != EquipType.Support) { return CSErrCode.Fail; } } if(pos == -1) { pos = (int)desc.type; } int existIndex = -1; //var del = new CSEquipDelSync(); for (int i = 0; i < player.RoleData.Knight.DbHero.WearEquip.Count; i++) { ref var eq = ref player.RoleData.Knight.DbHero.WearEquip[i]; if (eq.Pos == pos) { existIndex = i; //del.DelIds.Add(eq.SerialNum); break; } } //先删除背包 player.RoleData.PandoraBag.EquipList.RemoveAt(idx); var add = new CSEquipSync(); if (existIndex != -1) { ref var eeq = ref player.RoleData.Knight.DbHero.WearEquip[existIndex]; eeq.Pos = 0; eeq.NewGet = false; player.RoleData.PandoraBag.EquipList.Add(ref eeq); add.Add.CopyFrom(ref eeq); player.RoleData.Knight.DbHero.WearEquip.RemoveAt(existIndex); } equip.Pos = pos; player.RoleData.Knight.DbHero.WearEquip.Add(ref equip); if(pos == (int)EquipmentPos.LeftGun ) { player.RoleData.Knight.DbHero.Weapon1 = equip.DescId; } CheckEquipSuit(ref player.RoleData.Knight.DbHero); if (calcProp) { RolePropUtil.RecalRoleProp(player); } if (isNotify) { PlayerDataSvc.SendHeroInfoSync(player); //PlayerDataSvc.SendEquipListSync(player); //player.SendToClient((int)CSGameMsgID.EquipDelSync, ref del); if (existIndex != -1) { player.SendToClient((int)CSGameMsgID.EquipSync, ref add); } } return CSErrCode.None; } return CSErrCode.Fail; } public static CSErrCode UnWearEquip(PlayerOnGame player, int pos, bool notify = false, bool calcProp = false) { int existIndex = -1; for (int i = 0; i < player.RoleData.Knight.DbHero.WearEquip.Count; i++) { ref var eq = ref player.RoleData.Knight.DbHero.WearEquip[i]; if (eq.Pos == pos) { existIndex = i; break; } } if (existIndex != -1) { ref var eeq = ref player.RoleData.Knight.DbHero.WearEquip[existIndex]; eeq.Pos = 0; eeq.NewGet = false; player.RoleData.PandoraBag.EquipList.Add(ref eeq); if (notify) { var add = new CSEquipSync(); add.Add.CopyFrom(ref eeq); player.SendToClient((int)CSGameMsgID.EquipSync, ref add); } player.RoleData.Knight.DbHero.WearEquip.RemoveAt(existIndex); EquipmentSvc.CheckEquipSuit(ref player.RoleData.Knight.DbHero); if (calcProp) { RolePropUtil.RecalRoleProp(player); } if (notify) { PlayerDataSvc.SendHeroInfoSync(player); } return CSErrCode.None; } return CSErrCode.Fail; } private static long CalcEquipPropScore(ref ID32Value64 iD) { var config = CSPropIDTypeDescMgr.Instance.GetById(iD.Id); if(config != null) { return (long)(config.scoreNum / 10_000F * iD.Value/10_000); } return 0; } public static int CreateEquipProp(PlayerOnGame player, int level, CommonQuality quality, ref DBEquipment equip, long lucky = 0) { equip.AddProp.Clear(); equip.BaseProp.Clear(); var rand = GameServerUtils.GetApp().Rand; EquipDesc equipDesc = EquipDescMgr.Instance.GetConfigByInternal(equip.DescId); equip.Level = equipDesc.level; equip.Pos = 0; equip.Quality = (int)equipDesc.quality; equip.NewGet = true; equip.Lock = false; long atk = 0; long propscore = 0; { Dictionary excludeS = new Dictionary(); //{ // equipDesc.GetSkillAttr11(rand, out var propId, out var propValue, excludeS, lucky); // if (!string.IsNullOrEmpty(propId)) // { // ID32Value64 iD = new ID32Value64(); // iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; // iD.Value = propValue; // equip.SkillProp.Add(ref iD); // excludeS.Add(propId, true); // propscore += CalcEquipPropScore(ref iD); // } //} //{ // equipDesc.GetSkillAttr12(rand, out var propId, out var propValue, excludeS, lucky); // if (!string.IsNullOrEmpty(propId)) // { // ID32Value64 iD = new ID32Value64(); // iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; // iD.Value = propValue; // equip.SkillProp.Add(ref iD); // excludeS.Add(propId, true); // propscore += CalcEquipPropScore(ref iD); // } //} //{ // equipDesc.GetSkillAttr13(rand, out var propId, out var propValue, excludeS, lucky); // if (!string.IsNullOrEmpty(propId)) // { // ID32Value64 iD = new ID32Value64(); // iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; // iD.Value = propValue; // equip.SkillProp.Add(ref iD); // excludeS.Add(propId, true); // propscore += CalcEquipPropScore(ref iD); // } //} } var es = equipDesc.GetRandomElement(rand); switch (es) { case "Fire": equip.Element = (int)ElementType.Fire; break; case "Thunder": equip.Element = (int)ElementType.Thunder; break; case "Toxic": equip.Element = (int)ElementType.Toxic; break; default: equip.Element = (int)ElementType.None; break; } equip.DepotId = 0; equip.Score = 0; { var propValue = 0L; var propId = ""; var max = false; int c = 0; do { List rlist = RewardSvc.Reward(player, equipDesc.baseAttr, false, false); if (rlist.Count > 0) { var r = rlist[0]; EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(r.code); propValue = equipAttrDesc.GetPropValue(rand, lucky, out var max_); propId = equipAttrDesc.mainAttr; if (!string.IsNullOrEmpty(propId)) { max = max_; break; } } } while (c++ < 50); PropValue iD = new PropValue(); iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; iD.Value = propValue; iD.Max = max; equip.BaseProp.Add(ref iD); //propscore += CalcEquipPropScore(ref iD); if (propId.Equals("AtkFix")) { atk = propValue; } } Dictionary exclude = new Dictionary(); { var propValue = 0L; var propId = ""; var max = false; int c = 0; do { List rlist = RewardSvc.Reward(player, equipDesc.randomAttr1, false, false); if (rlist.Count > 0) { var r = rlist[0]; EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(r.code); propValue = equipAttrDesc.GetPropValue(rand, lucky, out var max_); if (exclude != null && exclude.ContainsKey(equipAttrDesc.mainAttr)) { continue; } propId = equipAttrDesc.mainAttr; max = max_; exclude.Add(propId, true); break; } else { break; } } while(c++ < 20); if (!string.IsNullOrEmpty(propId)) { { PropValue iD = new PropValue(); iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; iD.Value = propValue; iD.Max = max; equip.AddProp.Add(ref iD); //propscore += CalcEquipPropScore(ref iD); if (propId.Equals("AtkFix")) { atk += propValue; } } } } { var propValue = 0L; var propId = ""; var max = false; int c = 0; do { List rlist = RewardSvc.Reward(player, equipDesc.randomAttr2, false, false); if (rlist.Count > 0) { var r = rlist[0]; EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(r.code); propValue = equipAttrDesc.GetPropValue(rand, lucky, out var max_); if (exclude != null && exclude.ContainsKey(equipAttrDesc.mainAttr)) { continue; } propId = equipAttrDesc.mainAttr; exclude.Add(propId, true); max = max_; break; } else { break; } } while (c++ < 20); if (!string.IsNullOrEmpty(propId)) { { PropValue iD = new PropValue(); iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; iD.Value = propValue; iD.Max = max; equip.AddProp.Add(ref iD); //propscore += CalcEquipPropScore(ref iD); if (propId.Equals("AtkFix")) { atk += propValue; } } } } { var propValue = 0L; var propId = ""; var max = false; int c = 0; do { List rlist = RewardSvc.Reward(player, equipDesc.randomAttr3, false, false); if (rlist.Count > 0) { var r = rlist[0]; EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(r.code); propValue = equipAttrDesc.GetPropValue(rand, lucky, out var max_); if (exclude != null && exclude.ContainsKey(equipAttrDesc.mainAttr)) { continue; } propId = equipAttrDesc.mainAttr; exclude.Add(propId, true); max = max_; break; } else { break; } } while (c++ < 20); if (!string.IsNullOrEmpty(propId)) { { PropValue iD = new PropValue(); iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; iD.Value = propValue; iD.Max = max; equip.AddProp.Add(ref iD); //propscore += CalcEquipPropScore(ref iD); if (propId.Equals("AtkFix")) { atk += propValue; } } } } { var propValue = 0L; var propId = ""; var max = false; int c = 0; do { List rlist = RewardSvc.Reward(player, equipDesc.randomAttr4, false, false); if (rlist.Count > 0) { var r = rlist[0]; EquipAttrDesc equipAttrDesc = EquipAttrDescMgr.Instance.GetConfig(r.code); propValue = equipAttrDesc.GetPropValue(rand, lucky, out var max_); if (exclude != null && exclude.ContainsKey(equipAttrDesc.mainAttr)) { continue; } propId = equipAttrDesc.mainAttr; exclude.Add(propId, true); max = max_; break; } else { break; } } while (c++ < 20); if (!string.IsNullOrEmpty(propId)) { { PropValue iD = new PropValue(); iD.Id = (int)CSPropIDTypeDescMgr.Instance.GetConfig(propId).id; iD.Value = propValue; iD.Max = max; equip.AddProp.Add(ref iD); //propscore += CalcEquipPropScore(ref iD); if (propId.Equals("AtkFix")) { atk += propValue; } } } } //if(equipDesc.type == EquipType.Gun) //{ // var w = WeaponDescMgr.Instance.GetConfig(equipDesc.weaponId); // propscore += atk/10_000 * RolePropUtil.GetWeaponK(w.Type)/10_000; //} //equip.Score = (int)(propscore); return 0; } // 更新附魔状态, 减去附魔属性, 返回有效期内的附魔数量 public static int UpdateEquipEnchant(PlayerOnGame player, long nowSec, bool notifyClt) { int count = 0; //bool isBegin = false; //if (isBegin) //{ // var chgList = player.knight.prop.EndChange(); // PlayerNotify.NotifyHeroChgProp(player, chgList, (int)GoodsType.Equipment,0,notifyClt); //} return count; } private static int AddEquip(PlayerOnGame player, string equipId) { var equipDesc = EquipDescMgr.Instance.GetConfig(equipId); if (equipDesc == null) { TraceLog.Error("EquipmentSvc.AddEquip equipId {0} no conf", equipId); return -1; } var equip = new DBEquipment { Quality = (int)equipDesc.quality, }; equip.DescId = equipDesc.InternalId; equip.SerialNum = ++player.RoleData.PandoraBag.EquipIdSeq; CreateEquipProp(player, player.RoleData.Knight.DbHero.Level, equipDesc.quality, ref equip, player.knight.props.GetPropFinal(PropertyDef.Luck)/10_000); if (player.RoleData.PandoraBag.EquipList.Count < player.RoleData.PandoraBag.EquipList.GetMaxCount()) { player.RoleData.PandoraBag.EquipList.Add(ref equip); } TaskEXEvent.GetQualityEquipN(player,equipDesc.quality); player.MakeDirty(); return equip.SerialNum; } public static int AddEquip(PlayerOnGame player, string equipId, bool sendMsg = true) { var equipDesc = EquipDescMgr.Instance.GetConfig(equipId); if (equipDesc == null) { TraceLog.Error("EquipmentSvc.AddPayEquip equipId {0} no conf", equipId); return -1 ; } var equip = new DBEquipment { Quality = (int)equipDesc.quality, }; equip.DescId = equipDesc.InternalId; equip.SerialNum = ++player.RoleData.PandoraBag.EquipIdSeq; CreateEquipProp(player, player.RoleData.Knight.DbHero.Level, equipDesc.quality, ref equip, player.knight.props.GetPropFinal(PropertyDef.Luck) / 10_000); if (player.RoleData.PandoraBag.EquipList.Count < player.RoleData.PandoraBag.EquipList.GetMaxCount()) { player.RoleData.PandoraBag.EquipList.Add(ref equip); if (sendMsg) { var res = new CSEquipSync(); res.Add.CopyFrom(ref equip); player.SendToClient((int)CSGameMsgID.EquipSync, ref res); } } TaskEXEvent.GetQualityEquipN(player,equipDesc.quality); player.MakeDirty(); return equip.SerialNum; } public static void CollectEquipProp(ref DBRoleData roleDat, RoleProp roleProp) { for(int i = 0; i < roleDat.Knight.DbHero.WearEquip.Count; i++) { ref var equip = ref roleDat.Knight.DbHero.WearEquip[i]; ////不考虑枪的属性 2024.12.19 去除 //if(equip.Pos == (int)EquipmentPos.RightGun || equip.Pos == (int)EquipmentPos.LeftGun) //{ // continue; //} for(int j = 0; j < equip.BaseProp.Count; j++) { roleProp.AddProp(equip.BaseProp[j].Id, equip.BaseProp[j].Value); } for (int j = 0; j < equip.AddProp.Count; j++) { roleProp.AddProp(equip.AddProp[j].Id, equip.AddProp[j].Value); } //for (int j = 0; j < equip.SkillProp.Count; j++) //{ // roleProp.AddProp(equip.SkillProp[j].Id, equip.SkillProp[j].Value); //} } if(roleDat.Knight.DbHero.Suits.Count > 0) { for(int i = 0; i < roleDat.Knight.DbHero.Suits.Count; i++) { var suit = roleDat.Knight.DbHero.Suits[i]; var suitDesc = EquipSuitDescMgr.Instance.GetConfigByInternal(suit.Id); var lv = suit.Value; for (int j = 0; j < suitDesc.suit.Length; j++) { var pk = suitDesc.suit[j].CSProp; var pv = suitDesc.suit[j].CSPropValue; for( int k = 0; k < lv; k++) { if (pk[k] != "") { roleProp.AddProp(pk[k], pv[k]); } } } } } } /**计算套装数据*/ public static void CheckEquipSuit(ref DBHero hero) { hero.Suits.Clear(); Dictionary suitCount = new Dictionary(); for (int j = 0; j < hero.WearEquip.Count; j++) { var equipDesc = EquipDescMgr.Instance.GetConfigByInternal(hero.WearEquip[j].DescId); if(suitCount.ContainsKey(equipDesc.equipSuit)) { suitCount[equipDesc.equipSuit]++; } else { suitCount[equipDesc.equipSuit] = 1; } } var suitList = EquipSuitDescMgr.Instance.ItemTable.Values; foreach (var item in suitList) { if (suitCount.ContainsKey(item.id)) { int c = suitCount[item.id]; int level = 0; for(int j = item.suitEffectNum.Length - 1; j >= 0; j--) { if(c >= item.suitEffectNum[j]) { level = j + 1; break; } } if(level > 0) { var tidv = new TypeIDValue32(); tidv.Id = item.InternalId; tidv.Value = level; hero.Suits.Add(ref tidv); } } } } } }