92 lines
3.3 KiB
C#
92 lines
3.3 KiB
C#
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
|
|
{
|
|
public static CopyBattle CreateBattle(this BattleMgrCompnent self,Team team)
|
|
{
|
|
CopyBattle entity = EntityFactory.CreateWithParent<CopyBattle, Team>(self, team);
|
|
foreach (Unit unit in team.GetUnits())
|
|
{
|
|
unit.BattleId = entity.Id;
|
|
}
|
|
|
|
entity.team = team;
|
|
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;
|
|
}
|
|
public static CopyBattle GetBattle(this BattleMgrCompnent self,Unit unit)
|
|
{
|
|
if (!self.teamBattleTypeDic.TryGetValue(unit.BattleId, out CopyBattle battle))
|
|
{
|
|
Log.Error($"battleType is null");
|
|
return null;
|
|
}
|
|
return battle;
|
|
}
|
|
public static void NotifyUnitDead(this BattleMgrCompnent self,Unit unit)
|
|
{
|
|
try
|
|
{
|
|
if (!self.teamBattleTypeDic.TryGetValue(unit.BattleId, out CopyBattle battleBase))
|
|
{
|
|
Log.Error($"battleType is null");
|
|
return;
|
|
}
|
|
BattleHelper.UnitDead(battleBase, unit).Coroutine();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
public static async ETVoid NotifyUnitHurt(this BattleMgrCompnent self,Unit unit, int hp)
|
|
{
|
|
try
|
|
{
|
|
AttackComponent attackComponent = unit.GetComponent<AttackComponent>();
|
|
Unit attacker = attackComponent.attacker;
|
|
if(!attacker)
|
|
return;
|
|
if (!self.teamBattleTypeDic.TryGetValue(attacker.BattleId, out CopyBattle battleBase))
|
|
{
|
|
Log.Error($"battleType is null");
|
|
return;
|
|
}
|
|
if (battleBase.battleType == BattleType.FamilyBoss)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
public static void RemoveBattle<T>(this BattleMgrCompnent self,T entity) where T : CopyBattle
|
|
{
|
|
if (!self.teamBattleTypeDic.Remove(entity.Id))
|
|
{
|
|
Log.Error($"【{entity.team}】 teamBattleTypeDic con't remove the battle which entityId :{entity.Id}");
|
|
}
|
|
entity.Dispose();
|
|
}
|
|
}
|
|
}
|