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

72 lines
2.7 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
using System.Text;
using Cal;
2021-04-08 20:09:59 +08:00
namespace ET
{
public class BattleStartEvent: AEvent<EventType.BattleStart>
2021-04-08 20:09:59 +08:00
{
public override async ETTask Run(EventType.BattleStart args)
{
2021-04-11 19:50:39 +08:00
IEnumerable<Unit> teamList = args.teamList;
IEnumerable<Unit> targetTeamList = args.targetTeamList;
2021-04-08 20:09:59 +08:00
int index = 0;
2021-04-11 19:50:39 +08:00
foreach (Unit unit in teamList)
2021-04-08 20:09:59 +08:00
{
unit.GetComponent<Position>().pos = index++;
2021-04-11 19:50:39 +08:00
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
2021-04-08 20:09:59 +08:00
brocastComponent.ClearInternal();
brocastComponent.AddInternal(teamList);
if (args.isPvp)
brocastComponent.AddInternal(targetTeamList);
CheckState(unit);
}
2021-04-08 20:09:59 +08:00
index = 0;
2021-04-11 19:50:39 +08:00
foreach (Unit unit in targetTeamList)
2021-04-08 20:09:59 +08:00
{
unit.GetOrAddComponent<Position>().pos = index++;
2021-04-11 19:50:39 +08:00
BrocastComponent brocastComponent = unit.GetComponent<BrocastComponent>();
2021-04-08 20:09:59 +08:00
brocastComponent.ClearInternal();
brocastComponent.AddInternal(teamList);
if (args.isPvp)
{
brocastComponent.AddInternal(targetTeamList);
CheckState(unit);
}
}
await ETTask.CompletedTask;
}
2021-04-08 20:09:59 +08:00
private static void CheckState(Unit unit)
{
unit.Stop();
2021-04-11 19:50:39 +08:00
NumericComponent num = unit.GetComponent<NumericComponent>();
2021-04-08 20:09:59 +08:00
if (!unit.IsAlive)
{
Log.Error($"玩家{unit.Id} name={UserComponent.Instance.Get(unit.Id)?.NickName}已经死亡");
2021-04-08 20:09:59 +08:00
unit.Live(num);
}
2021-04-08 20:09:59 +08:00
if (num.GetAsInt(NumericType.Hp) <= 0)
{
Log.Error($"玩家{unit.Id} name={UserComponent.Instance.Get(unit.Id)?.NickName}生命值小于等于0");
2021-04-08 20:09:59 +08:00
num.Set(NumericType.Hp, 1);
}
// if (unit.UnitType == UnitType.Player)
// CharacterHelper.ResetAddNumeric(unit, num);
2021-04-11 19:50:39 +08:00
SkillAI skillAi = unit.GetComponent<SkillAI>();
2021-04-08 20:09:59 +08:00
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}");
Game.EventSystem.Publish(new ET.EventType.UpdateAutoSkillList { skillAI = unit.GetComponent<SkillAI>(), }).Coroutine();
2021-04-08 20:09:59 +08:00
if (unit.GetComponent<UnitEnermy>() == null)
unit.AddComponent<UnitEnermy>();
}
}
}