using System; using System.Collections.Generic; using System.Linq; using Cal; using Cal.DataTable; namespace ET { public class UnitSkillComponentDestroySystem: DestroySystem { public override void Destroy(UnitSkillComponent self) { self.SkillLearnedDic.Clear(); self.SkillUnLearnedDic.Clear(); } } public static class UnitSkillComponentSystem { public static bool InitSkill(this UnitSkillComponent self, JobType jobType) { Dictionary.KeyCollection skillLogicConfig = SkillConfigComponent.SkillLogicCollection.skillDic.Keys; foreach (int skillId in skillLogicConfig) { if (skillId / 100000 == (int) jobType) { UnitSkill unitSkill = new UnitSkill { Id = skillId }; if (skillId % 100000 == 1) { unitSkill.Level = 1; self.SkillLearnedDic.Add(skillId, unitSkill); } else { unitSkill.Level = 0; self.SkillUnLearnedDic.Add(skillId, unitSkill); } } } return true; } public static async ETTask ResetSkill(this UnitSkillComponent self) { Unit unit = self.GetParent(); PlayerData data = self.Parent.GetComponent(); KeyValuePair kv = data.SkillPointKV; data.SkillPointKV = KeyValuePair.Create(kv.Value, kv.Value); Dictionary retdic = new Dictionary(); Dictionary dic = self.SkillLearnedDic; UnitSkill unitSkill = null; foreach (KeyValuePair dicKV in dic) { try { if (dicKV.Key % 100000 == 1) { unitSkill = dicKV.Value; continue; } for (int i = 1; i <= dicKV.Value.Level; i++) { int nextSkillId = dicKV.Key * 100 + i; SkillLearn skillLearn = SkillLearnCategory.Instance.Get(nextSkillId); foreach (SkillLearn.Material item in skillLearn.MaterialArr) { if (!retdic.ContainsKey(item._Id)) { retdic[item._Id] = 0; } retdic[item._Id] += item.Count; } } dicKV.Value.Level = 0; self.SkillUnLearnedDic.Add(dicKV.Key, dicKV.Value); } catch (Exception e) { Log.Error(e); } } dic.Clear(); if (unitSkill != null) { dic.TryAdd(unitSkill.Id, unitSkill); } else Log.Error($"skill == null where id = {unit.Id}"); foreach (KeyValuePair item in retdic) { try { await MailHelper.AddItem(unit.Id, item.Key, item.Value, true, "", "重置技能", "技能书返还", ""); } catch (Exception e) { Log.Error(e); } } UnitHelper.SaveComponenet(data).Coroutine(); UnitHelper.SaveComponenet(self).Coroutine(); UnitHelper.Save(unit).Coroutine(); } public static void ResetFreeSkill(this UnitSkillComponent self) { Unit unit = self.GetParent(); PlayerData data = self.Parent.GetComponent(); KeyValuePair kv = data.SkillPointKV; data.SkillPointKV = KeyValuePair.Create(kv.Value, kv.Value); Dictionary dic = self.SkillLearnedDic; UnitSkill unitSkill = null; foreach (KeyValuePair dicKV in dic) { try { if (dicKV.Key % 100000 == 1) { unitSkill = dicKV.Value; continue; } dicKV.Value.Level = 0; self.SkillUnLearnedDic.Add(dicKV.Key, dicKV.Value); } catch (Exception e) { Log.Error(e); } } dic.Clear(); if (unitSkill != null) { dic.TryAdd(unitSkill.Id, unitSkill); } else Log.Error($"skill == null where id = {unit.Id}"); UnitHelper.SaveComponenet(data).Coroutine(); UnitHelper.SaveComponenet(self).Coroutine(); UnitHelper.Save(unit).Coroutine(); } public static void TransferJob(this UnitSkillComponent self, int job) { self.SkillLearnedDic.Clear(); self.SkillUnLearnedDic.Clear(); try { self.InitSkill((JobType) job); } catch (Exception e) { Log.Error(e); } PlayerData data = self.Parent.GetComponent(); KeyValuePair kv = data.SkillPointKV; data.SkillPointKV = KeyValuePair.Create(kv.Value, kv.Value); UnitHelper.SaveComponenet(data).Coroutine(); UnitHelper.SaveComponenet(self).Coroutine(); } public static bool InitMonsterSkill(this UnitSkillComponent self, int skillId) { UnitSkill unitSkill = new UnitSkill { Id = skillId }; self.SkillUnLearnedDic.TryAdd(skillId, unitSkill); return true; } public static void LearnMonsterSkill(this UnitSkillComponent self, int skillId) { UnitSkill unitSkill = self.GetUnlearnedSkill(skillId); if (unitSkill == UnitSkill.Null) { Log.Error($"未找到技能,Id为{skillId}"); return; } unitSkill.Level = 1; //unitSkill.UpdateSkillLevel(self.GetParent()); self.SkillLearnedDic.TryAdd(skillId, unitSkill); self.SkillUnLearnedDic.Remove(skillId); } public static string LearnSkill(this UnitSkillComponent self, int skillId, int level) { //var unitSkill = self.GetSkill(skillId); //if (unitSkill == null) //{ // return "技能书使用错误"; //} //var ret = unitSkill.UpdateSkillLevel(self.GetParent(), level); //if (!ret.Equals(string.Empty)) //{ // return ret; //} //if (level == 1) //{ // self.SkillLearnedDic.Add(skillId, unitSkill); // self.SkillUnLearnedDic.Remove(skillId); //} //return string.Empty; return "系统错误"; } public static string LearnSkill(this UnitSkillComponent self, int skillId) { UnitSkill unitSkill = self.GetSkill(skillId); if (unitSkill == UnitSkill.Null) { Log.Error($"unitSkill == null where id = {skillId}"); return "系统错误"; } SkillConfig skillConfig = DataTableHelper.Get(skillId * 100); if (skillConfig == null) { Log.Error($"skillConfig == null where id = {skillId}"); return "系统错误"; } int maxLevel = skillConfig.MaxLevel; if (unitSkill.Level == maxLevel) { return "等级达到最大级"; } NumericComponent num = self.Parent.GetComponent(); int nextLevel = unitSkill.Level + 1; int nextSkillId = skillId * 100 + unitSkill.Level + 1; SkillConfig skillConfig_Level = DataTableHelper.Get(nextSkillId); if (skillConfig_Level == null) { Log.Error($"skillConfig_Level == null where id = {nextSkillId}"); return "系统错误"; } if (skillConfig_Level.LearnLevel > num.GetAsInt(NumericType.Level)) { return "等级不足"; } PlayerData data = self.Parent.GetComponent(); int currPoint = data.SkillPointKV.Key; int totalPoint = data.SkillPointKV.Value; if (currPoint <= 0) { return "技能点不足"; } //!判断前置 if (skillConfig.PreSkillId != 0) { SkillConfig skillConfig_PreSkill = DataTableHelper.Get(skillConfig.PreSkillId * 100); if (skillConfig_PreSkill == null) { Log.Error($"skillConfig_PreSkill == null where id = {skillConfig.PreSkillId}"); return "系统错误"; } int maxPreLevel = skillConfig_PreSkill.MaxLevel; UnitSkill unitPreSkill = self.GetSkill(skillConfig.PreSkillId); if (unitPreSkill == UnitSkill.Null) { Log.Error($"unitPreSkill == null where id = {skillConfig.PreSkillId}"); return "系统错误"; } if (unitPreSkill.Level < maxPreLevel) { return $"前置技能{skillConfig_PreSkill.Name}未完全掌握!"; } } SkillLearn skillLearn = SkillLearnCategory.Instance.Get(nextSkillId); Unit unit = self.GetParent(); Bag bag = unit.GetComponent(); if (!AppConfig.inst.isTest) { foreach (SkillLearn.Material needMaterial in skillLearn.MaterialArr) { if (!BagHelper.HasItem(bag, needMaterial._Id, needMaterial.Count)) { return $"材料不足:{BagHelper.GetName(needMaterial._Id)} X {needMaterial.Count}"; } } foreach (SkillLearn.Material needMaterial in skillLearn.MaterialArr) { BagHelper.DeleteItem(bag, needMaterial._Id, needMaterial.Count); } } currPoint--; data.SkillPointKV = new KeyValuePair(currPoint, totalPoint); unitSkill.Level++; unitSkill.IsPassive = skillConfig.SkillType == 1; if (unitSkill.Level == 1) { self.SkillLearnedDic.Add(skillId, unitSkill); self.SkillUnLearnedDic.Remove(skillId); } UnitHelper.SaveComponenet(data).Coroutine(); UnitHelper.SaveComponenet(self).Coroutine(); return null; } public static UnitSkill GetLearnedSkill(this UnitSkillComponent self, int skillId) { self.SkillLearnedDic.TryGetValue(skillId, out UnitSkill unitSkill); return unitSkill; } public static IEnumerable GetLearnedSkills(this UnitSkillComponent self) { return self.SkillLearnedDic.Values; } public static UnitSkill GetSkill(this UnitSkillComponent self, int skillId) { if (!self.SkillLearnedDic.TryGetValue(skillId, out UnitSkill unitSkill)) { self.SkillUnLearnedDic.TryGetValue(skillId, out unitSkill); } return unitSkill; } public static UnitSkill GetUnlearnedSkill(this UnitSkillComponent self, int skillId) { self.SkillUnLearnedDic.TryGetValue(skillId, out UnitSkill unitSkill); return unitSkill; } public static UnitSkill GetFirstUnlearnedSkill(this UnitSkillComponent self) { UnitSkill[] arr = self.SkillUnLearnedDic.Values.ToArray(); return arr[0]; } public static IEnumerable GetUnlearnedSkills(this UnitSkillComponent self) { return self.SkillUnLearnedDic.Values; } } }