zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Hotfix/Game/SkillSystem/NewSkill/System/SkillMgrComponentSystem.cs

136 lines
4.9 KiB
C#
Executable File

using Cal;
using Cal.DataTable;
using System;
using System.Collections.Generic;
namespace ET
{
public class SkillMgrComponentLoadSystem : LoadSystem<SkillMgrComponent>
{
public override void Load(SkillMgrComponent self)
{
foreach (KeyValuePair<int, SkillLogic> kv in self.skillDic)
{
try
{
if (!SkillConfigComponent.SkillLogicCollection.skillDic.TryGetValue(kv.Key, out SkillLogicConfig skillLogicConfig))
{
Log.Error($"skillLogicConfig==null where skillId = {kv.Key}");
return;
}
kv.Value.skillLogicConfig = skillLogicConfig;
SkillConfig skillConfig = DataTableHelper.Get<SkillConfig>(kv.Key * 100);
if (skillConfig == null)
{
Log.Error($"skillConfig == null where id = {kv.Key}");
}
kv.Value.skillConfig = skillConfig;
}
catch (Exception e)
{
Log.Error(e);
}
}
Log.Info($"替换技能配置成功");
}
}
public class SkillMgrComponentDstroySystem : DestroySystem<SkillMgrComponent>
{
public override void Destroy(SkillMgrComponent self)
{
self.ClearSkill();
}
}
public static class SkillMgrComponentSystem
{
public static void AddSkill(this SkillMgrComponent self, Unit unit, UnitSkill unitSkill)
{
if (unitSkill == UnitSkill.Null)
{
Log.Error($"unitSkill==null where unitId ={unit.Id}");
return;
}
int skillId = (int)unitSkill.Id;
if (self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic))
{
ExecuteEvent(unitSkill, skillLogic, unit);
return;
}
skillLogic = EntityFactory.CreateWithParent<SkillLogic>(unit.DomainScene());
if (!SkillConfigComponent.SkillLogicCollection.skillDic.TryGetValue(skillId, out SkillLogicConfig skillLogicConfig))
{
Log.Error($"skillLogicConfig==null where skillId = {skillId}");
return;
}
skillLogic.skillLogicConfig = skillLogicConfig;
skillLogic.owner = unit;
skillLogic.skillLevel = unitSkill.Level;
SkillConfig skillConfig = DataTableHelper.Get<SkillConfig>(skillId*100);
if (skillConfig == null)
{
Log.Error($"skillConfig == null where id = {skillId}");
}
skillLogic.skillConfig = skillConfig;
if (!self.skillDic.TryAdd(skillId, skillLogic))
{
Log.Error($"[上面已经判断了不含有这个键]");
return;
}
//!执行添加技能的事件
ExecuteEvent(unitSkill, skillLogic, unit);
}
private static void ExecuteEvent(UnitSkill unitSkill, SkillLogic skillLogic, Unit unit)
{
if (unitSkill.IsPassive)
skillLogic.HandleEvent(SkillEventCondition., new SkillSender (unit,skillLogic.skillConfigId));
}
public static SkillLogic GetSkill(this SkillMgrComponent self, int skillId)
{
self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic);
return skillLogic;
}
public static void UpdateSkill(this SkillMgrComponent self, Unit skillFrom, int skillId)
{
if (!self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic))
{
Log.Error($"skillLogic == null where skillid = {skillId}");
return;
}
//!升级
skillLogic.UpdateLevel();
Unit unit = self.GetParent<Unit>();
//!执行添加技能的事件
skillLogic.HandleEvent(SkillEventCondition., new SkillSender (skillFrom,skillLogic.skillConfigId));
}
public static void RemoveSkill(this SkillMgrComponent self, Unit skillFrom, int skillId)
{
if (!self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic))
{
Log.Error($"skillLogic == null where skillid = {skillId}");
return;
}
skillLogic.Dispose();
self.skillDic.Remove(skillId);
Unit unit = self.GetParent<Unit>();
//!执行添加技能的事件
skillLogic.HandleEvent(SkillEventCondition., new SkillSender(skillFrom,skillLogic.skillConfigId));
}
public static void ClearSkill(this SkillMgrComponent self)
{
foreach (var keyValuePair in self.skillDic)
{
keyValuePair.Value.Dispose();
}
self.skillDic.Clear();
}
}
}