CTT/Server/Hotfix/Game/SkillSystem/NewSkill/System/AttackComponentSystem.cs

210 lines
8.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
caster = unit,
skillLogic = skillLogic,
});
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 = skillLogic.GetPlayAmount();
Log.Info($"{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
{
caster = unit,
skillLogic = skillLogic,
});
long start = TimeHelper.ClientNow();
long now = start;
do
{
await TimerComponent.Instance.WaitTillAsync(now + interval);
now = TimeHelper.ClientNow();
skillLogic.HandleEvent(SkillEventCondition., new SkillSender
{
caster = unit,
skillLogic = skillLogic
});
} while (now + interval <= start + duration);
skillLogic.HandleEvent(SkillEventCondition., new SkillSender
{
caster = unit,
skillLogic = skillLogic,
});
}
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
{
caster = unit,
skillLogic = skillLogic
});
//!广播释放技能
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);
self.EndSpellSkill(unit, skillLogic);
}
public static void EndSpellSkill(this AttackComponent self, Unit unit, SkillLogic skillLogic)
{
skillLogic.HandleEvent(SkillEventCondition., new SkillSender
{
caster = unit,
skillLogic = skillLogic
});
}
/// <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);
}
}
}