CTT/Server/Hotfix/Game/System/Battle/BattleMgrCompnentSystem.cs

92 lines
3.3 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
namespace ET
{
public class BattleMgrCompnentAwakeSystem : AwakeSystem<BattleMgrCompnent>
{
public override void Awake(BattleMgrCompnent self)
{
BattleMgrCompnent.Instance = self;
}
}
public static class BattleMgrCompnentSystem
{
2021-05-01 11:27:41 +08:00
public static CopyBattle CreateBattle(this BattleMgrCompnent self,Team team)
2021-04-08 20:09:59 +08:00
{
2021-05-01 11:27:41 +08:00
CopyBattle entity = EntityFactory.CreateWithParent<CopyBattle, Team>(self, team);
2021-04-11 19:50:39 +08:00
foreach (Unit unit in team.GetUnits())
2021-04-08 20:09:59 +08:00
{
unit.BattleId = entity.Id;
}
2021-05-01 11:27:41 +08:00
entity.team = team;
2021-04-08 20:09:59 +08:00
if (!self.teamBattleTypeDic.TryAdd(entity.Id, entity))
{
self.teamBattleTypeDic[entity.Id] = entity;
Log.Error($"************\n***********\n 【{team.GetMemberName()}】 teamBattleTypeDic has the key {entity.Id} ,battleType is {entity.battleType}\n************\n***********");
}
return entity;
}
2021-05-01 11:27:41 +08:00
public static CopyBattle GetBattle(this BattleMgrCompnent self,Unit unit)
2021-04-08 20:09:59 +08:00
{
2021-05-01 11:27:41 +08:00
if (!self.teamBattleTypeDic.TryGetValue(unit.BattleId, out CopyBattle battle))
2021-04-08 20:09:59 +08:00
{
Log.Error($"battleType is null");
return null;
}
return battle;
}
public static void NotifyUnitDead(this BattleMgrCompnent self,Unit unit)
{
try
{
2021-05-01 11:27:41 +08:00
if (!self.teamBattleTypeDic.TryGetValue(unit.BattleId, out CopyBattle battleBase))
2021-04-08 20:09:59 +08:00
{
Log.Error($"battleType is null");
return;
}
BattleHelper.UnitDead(battleBase, unit).Coroutine();
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-01 11:27:41 +08:00
public static async ETVoid NotifyUnitHurt(this BattleMgrCompnent self,Unit unit, int hp)
2021-04-08 20:09:59 +08:00
{
try
{
2021-05-01 11:27:41 +08:00
AttackComponent attackComponent = unit.GetComponent<AttackComponent>();
Unit attacker = attackComponent.attacker;
2021-05-01 12:18:16 +08:00
if(!attacker)
return;
2021-05-01 11:27:41 +08:00
if (!self.teamBattleTypeDic.TryGetValue(attacker.BattleId, out CopyBattle battleBase))
2021-04-08 20:09:59 +08:00
{
Log.Error($"battleType is null");
return;
}
2021-05-01 11:27:41 +08:00
if (battleBase.battleType == BattleType.FamilyBoss)
2021-04-08 20:09:59 +08:00
{
2021-05-01 11:27:41 +08:00
MonsterInfo monsterInfo = unit.GetComponent<MonsterInfo>();
User user =await UserComponent.Instance.Query(attacker.Id);
FamilyBoss familyBoss = await FamilyBossComponent.instance.Query(user.Family);
familyBoss.SetBossHp(monsterInfo.configId, hp);
2021-04-08 20:09:59 +08:00
}
}
catch (Exception e)
{
Log.Error(e);
}
}
2021-05-01 11:27:41 +08:00
public static void RemoveBattle<T>(this BattleMgrCompnent self,T entity) where T : CopyBattle
2021-04-08 20:09:59 +08:00
{
if (!self.teamBattleTypeDic.Remove(entity.Id))
{
Log.Error($"【{entity.team}】 teamBattleTypeDic con't remove the battle which entityId :{entity.Id}");
}
entity.Dispose();
}
}
}