CTT/Server/Hotfix/Game/Event/Battle/BattleStartEvent.cs

89 lines
3.4 KiB
C#
Executable File

using System;
using System.Collections.Generic;
using System.Text;
using Cal;
namespace ET
{
public class BattleStartEvent: AEvent<EventType.BattleStart>
{
public override async ETTask Run(EventType.BattleStart args)
{
IEnumerable<Unit> teamList = args.teamList;
IEnumerable<Unit> targetTeamList = args.targetTeamList;
int index = 0;
foreach (Unit unit in teamList)
{
unit.GetComponent<Position>().pos = index++;
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
brocastComponent.ClearInternal();
brocastComponent.AddInternal(teamList);
if (args.isPvp)
brocastComponent.AddInternal(targetTeamList);
CheckState(unit);
}
index = 0;
foreach (Unit unit in targetTeamList)
{
unit.GetOrAddComponent<Position>().pos = index++;
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
brocastComponent.ClearInternal();
brocastComponent.AddInternal(teamList);
if (args.isPvp)
{
brocastComponent.AddInternal(targetTeamList);
CheckState(unit);
}
}
await ETTask.CompletedTask;
}
private static void CheckState(Unit unit)
{
unit.Stop();
NumericComponent num = unit.GetComponent<NumericComponent>();
if (!unit.IsAlive)
{
Log.Error($"玩家{unit.Id} name={UserComponent.Instance.Get(unit.Id)?.NickName}已经死亡");
unit.Live(num);
}
if (num.GetAsInt(NumericType.Hp) <= 0)
{
Log.Error($"玩家{unit.Id} name={UserComponent.Instance.Get(unit.Id)?.NickName}生命值小于等于0");
num.Set(NumericType.Hp, 1);
}
// if (unit.UnitType == UnitType.Player)
// CharacterHelper.ResetAddNumeric(unit, num);
SkillAI skillAi = unit.GetComponent<SkillAI>();
skillAi.roundCD = CharacterHelper.GetSkillCD(num.Get(NumericType.Spd));
if (AppConfig.inst.showBattleSkillInfo)
Log.Info($"【{UserComponent.Instance.Get(unit.Id)?.NickName} ({unit.Id})】cd = {skillAi.roundCD}");
if (unit.UnitType == UnitType.Player)
{
SkillMgrComponent skillMgr = unit.GetComponent<SkillMgrComponent>();
UnitSkillComponent skillComponent = unit.GetComponent<UnitSkillComponent>();
foreach (UnitSkill unitSkill in skillComponent.GetLearnedSkills())
{
if (skillMgr.GetSkill(unitSkill.Id) == null)
{
skillMgr.AddSkill(unit, unitSkill);
}
}
foreach (var keyValuePair in skillMgr.skillDic)
{
keyValuePair.Value.Clear();
}
}
Game.EventSystem.Publish(new ET.EventType.UpdateAutoSkillList { skillAI = unit.GetComponent<SkillAI>(), }).Coroutine();
if (unit.GetComponent<UnitEnermy>() == null)
unit.AddComponent<UnitEnermy>();
}
}
}