139 lines
4.9 KiB
C#
139 lines
4.9 KiB
C#
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.skillDic.Clear();
|
|
}
|
|
}
|
|
public static class SkillMgrComponentSystem
|
|
{
|
|
public static void AddSkill(this SkillMgrComponent self, Unit skillFrom, UnitSkill unitSkill)
|
|
{
|
|
if (unitSkill == UnitSkill.Null)
|
|
{
|
|
Log.Error($"unitSkill==null where unitId ={skillFrom.Id}");
|
|
return;
|
|
}
|
|
int skillId = (int)unitSkill.Id;
|
|
Unit unit = self.GetParent<Unit>();
|
|
if (self.skillDic.TryGetValue(skillId, out SkillLogic skillLogic))
|
|
{
|
|
ExecuteEvent();
|
|
return;
|
|
}
|
|
skillLogic = EntityFactory.CreateWithParent<SkillLogic>(skillFrom.DomainScene());
|
|
if (!SkillConfigComponent.SkillLogicCollection.skillDic.TryGetValue(skillId, out SkillLogicConfig skillLogicConfig))
|
|
{
|
|
Log.Error($"skillLogicConfig==null where skillId = {skillId}");
|
|
return;
|
|
}
|
|
skillLogic.skillLogicConfig = skillLogicConfig;
|
|
skillLogic.owner = skillFrom;
|
|
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();
|
|
|
|
void ExecuteEvent()
|
|
{
|
|
if (unitSkill.IsPassive)
|
|
skillLogic.HandleEvent(SkillEventCondition.当技能添加, new SkillSender
|
|
{
|
|
caster = skillFrom,
|
|
skillLogic = skillLogic
|
|
});
|
|
}
|
|
}
|
|
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
|
|
{
|
|
caster = skillFrom,
|
|
skillLogic = skillLogic
|
|
});
|
|
}
|
|
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
|
|
{
|
|
caster = skillFrom,
|
|
skillLogic = skillLogic
|
|
});
|
|
}
|
|
}
|
|
}
|