189 lines
7.7 KiB
C#
Executable File
189 lines
7.7 KiB
C#
Executable File
using Cal;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace ET
|
||
{
|
||
public class AttackComponentAwakeSystem : AwakeSystem<AttackComponent>
|
||
{
|
||
public override void Awake(AttackComponent self)
|
||
{
|
||
self.multipleDamageX10000 = 1;
|
||
self.playAmount = 1;
|
||
self.isFirstAtk = true;
|
||
}
|
||
}
|
||
public class AttackComponentDstroySystem : DestroySystem<AttackComponent>
|
||
{
|
||
public override void Destroy(AttackComponent self)
|
||
{
|
||
self.attacker = null;
|
||
}
|
||
}
|
||
public static class AttackComponentSystem
|
||
{
|
||
public static void Clear(this AttackComponent self)
|
||
{
|
||
self.attacker = null;
|
||
self.attackData = default;
|
||
self.isFirstAtk = false;
|
||
}
|
||
/// <summary>
|
||
/// 《选择目标》
|
||
/// </summary>
|
||
/// <param name="self"></param>
|
||
/// <returns></returns>
|
||
public static bool StartSpellSkill(this AttackComponent self, SkillLogic skillLogic)
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
self.isFirstAtk = true;
|
||
TargetableUnitComponent targetCompoennt = self.Parent.GetComponent<TargetableUnitComponent>();
|
||
List<Unit> allList = targetCompoennt.GetAllTarget();
|
||
|
||
var config = skillLogic.skillLogicConfig;
|
||
SkillTypes skillTypes = config.skillType;
|
||
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能施法前, new SkillSender(unit,skillLogic.skillConfigId));
|
||
return skillTypes switch
|
||
{
|
||
SkillTypes.普通 => SpellGeneralSkill(self, unit, skillLogic, allList),
|
||
SkillTypes.被动 => false,
|
||
SkillTypes.引导 => SpellChannelSkill(self, unit, skillLogic, allList),
|
||
SkillTypes.开关 => SpellToggleSkill(self, unit, skillLogic, allList),
|
||
_ => false,
|
||
};
|
||
}
|
||
|
||
private static bool SpellGeneralSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List<Unit> allList)
|
||
{
|
||
int playAmount = self.playAmount;
|
||
for (int i = playAmount - 1; i >= 0; i--)
|
||
{
|
||
SpellSkill(self, unit, skillLogic, allList).Coroutine();
|
||
}
|
||
return true;
|
||
}
|
||
private static bool SpellChannelSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List<Unit> allList)
|
||
{
|
||
SkillLogicConfig skillConfig = skillLogic.skillLogicConfig;
|
||
int duration = skillConfig.duration;
|
||
int interval = skillConfig.interval;
|
||
SpellChannelSkillAsync(self, unit, skillLogic, duration, interval, allList).Coroutine();
|
||
return true;
|
||
}
|
||
|
||
private static async ETVoid SpellChannelSkillAsync(AttackComponent self, Unit unit, SkillLogic skillLogic, int duration, int interval, List<Unit> allList)
|
||
{
|
||
if (AppConfig.inst.showBattleSkillInfo)
|
||
Log.Info($"{unit}释放技能:【{skillLogic.skillLogicConfig.skillName}({skillLogic.skillConfigId})】");
|
||
//!广播释放技能
|
||
foreach (Unit u in allList)
|
||
{
|
||
M2C_PlaySkill m2C_PlayerSkill = new M2C_PlaySkill
|
||
{
|
||
SkillId = skillLogic.skillId,
|
||
UnitId = unit.Id,
|
||
};
|
||
MessageHelper.SendActor(u, m2C_PlayerSkill);
|
||
|
||
}
|
||
//!动画开始到产生特效的时间
|
||
int delayTime = 1000;
|
||
await TimerComponent.Instance.WaitAsync(delayTime);
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能引导开始, new SkillSender(unit,skillLogic.skillConfigId));
|
||
long start = TimeHelper.ClientNow();
|
||
long now = start;
|
||
do
|
||
{
|
||
await TimerComponent.Instance.WaitTillAsync(now + interval);
|
||
now = TimeHelper.ClientNow();
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能引导时, new SkillSender(unit,skillLogic.skillConfigId));
|
||
} while (now + interval <= start + duration);
|
||
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能引导完成, new SkillSender(unit,skillLogic.skillConfigId));
|
||
}
|
||
|
||
private static bool SpellToggleSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List<Unit> allList)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
private static async ETVoid SpellSkill(AttackComponent self, Unit unit, SkillLogic skillLogic, List<Unit> allList)
|
||
{
|
||
if (AppConfig.inst.showBattleSkillInfo)
|
||
Log.Info($"{unit}释放技能:【{skillLogic.skillLogicConfig.skillName}({skillLogic.skillConfigId})】");
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能施法开始, new SkillSender(unit,skillLogic.skillConfigId));
|
||
|
||
//!广播释放技能
|
||
foreach (Unit u in allList)
|
||
{
|
||
M2C_PlaySkill m2C_PlayerSkill = new M2C_PlaySkill
|
||
{
|
||
SkillId = skillLogic.skillId,
|
||
UnitId = unit.Id,
|
||
};
|
||
MessageHelper.SendActor(u, m2C_PlayerSkill);
|
||
|
||
}
|
||
//!动画开始到产生特效的时间
|
||
int delayTime = 1000;
|
||
await TimerComponent.Instance.WaitAsync(delayTime);
|
||
if(unit.teamState != TeamState.Fight)
|
||
return;
|
||
self.EndSpellSkill(unit, skillLogic);
|
||
}
|
||
public static void EndSpellSkill(this AttackComponent self, Unit unit, SkillLogic skillLogic)
|
||
{
|
||
skillLogic.HandleEvent(SkillEventCondition.当技能施法时, new SkillSender(unit,skillLogic.skillConfigId));
|
||
}
|
||
/// <summary>
|
||
/// 获取子弹数据,里面包含伤害等
|
||
/// </summary>
|
||
public static BallisticData GetAttackData(this AttackComponent self)
|
||
{
|
||
return self.attackData;
|
||
}
|
||
/// <summary>
|
||
/// 执行伤害
|
||
/// </summary>
|
||
public static void AttackTarget(this AttackComponent self, Unit target, BallisticData data, ISkillSender skillSender, bool
|
||
applyBallisticData
|
||
= true)
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
if (AppConfig.inst.showBattleDamageInfo)
|
||
Log.Debug($"{unit.Id}对{target.Id},伤害数据2:{data}");
|
||
if (data.value == 0)
|
||
{
|
||
|
||
}
|
||
if (applyBallisticData)
|
||
self.attackData = data;
|
||
|
||
if (!target || !target.IsAlive)
|
||
{
|
||
// if(AppConfig.inst.isTest)
|
||
// Log.Warning($"目标{target.Id}已经死亡 ");
|
||
return;
|
||
}
|
||
AttackComponent attackComponent = target.GetComponent<AttackComponent>();
|
||
if (attackComponent!=null)
|
||
attackComponent.attacker = unit;
|
||
target.GetComponent<UnitEnermy>().unit = unit;
|
||
target.GetComponent<BattleComponent>().Damage(data, skillSender);
|
||
}
|
||
/// <summary>
|
||
/// 执行治疗
|
||
/// </summary>
|
||
public static void TreatTarget(this AttackComponent self, Unit target, BallisticData ballisticData, ISkillSender skillSender)
|
||
{
|
||
Unit unit = self.GetParent<Unit>();
|
||
if (AppConfig.inst.showBattleDamageInfo)
|
||
Log.Debug($"{self.GetParent<Unit>().Id}对{target.Id},治疗数据:{ballisticData}");
|
||
AttackComponent attackComponent = target.GetComponent<AttackComponent>();
|
||
attackComponent.attacker = unit;
|
||
target.GetComponent<BattleComponent>().Treat(ballisticData, skillSender);
|
||
}
|
||
}
|
||
}
|