CTT/Server/Hotfix/Game/System/Other/MainStoryAIComponentSystem.cs

65 lines
1.9 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using System;
using System.Collections.Generic;
namespace ET
{
public class MainStoryAIComponentAwakeSystem: AwakeSystem<MainStoryAIComponent>
2021-04-08 20:09:59 +08:00
{
public override void Awake(MainStoryAIComponent self)
{
2021-04-08 20:09:59 +08:00
MainStoryAIComponent.instance = self;
}
2021-04-08 20:09:59 +08:00
}
2021-04-08 20:09:59 +08:00
public static class MainStoryAIComponentSystem
{
public static MainStoryAI CreateAI(this MainStoryAIComponent self, Team team, int mapId, AutoBattleAIType autoBattleAIType)
2021-04-08 20:09:59 +08:00
{
MainStoryAI ai = EntityFactory.CreateWithParentAndId<MainStoryAI>(self, team.LeaderId);
ai.Init(team, mapId,autoBattleAIType);
2021-04-11 19:50:39 +08:00
foreach (long item in team.GetUnitIds())
2021-04-08 20:09:59 +08:00
{
self.aiIdDic[item] = ai.Id;
}
2021-04-08 20:09:59 +08:00
return ai;
}
2021-04-08 20:09:59 +08:00
public static MainStoryAI GetAI(this MainStoryAIComponent self, long id)
{
2021-04-11 19:50:39 +08:00
MainStoryAI ai = self.GetChild<MainStoryAI>(id);
2021-04-08 20:09:59 +08:00
return ai;
}
2021-04-08 20:09:59 +08:00
public static MainStoryAI GetAI(this MainStoryAIComponent self, Unit unit)
{
if (!self.aiIdDic.TryGetValue(unit.Id, out long id))
2021-04-08 20:09:59 +08:00
{
return null;
}
2021-04-11 19:50:39 +08:00
MainStoryAI ai = self.GetChild<MainStoryAI>(id);
2021-04-08 20:09:59 +08:00
return ai;
}
2021-04-08 20:09:59 +08:00
public static bool DestoryAI(this MainStoryAIComponent self, MainStoryAI ai)
{
if (!ai) return false;
2021-04-11 19:50:39 +08:00
List<long> list = ai.team?.GetUnitIds();
2021-04-08 20:09:59 +08:00
if (list != null)
foreach (long item in list)
{
self.aiIdDic.Remove(item);
}
2021-04-08 20:09:59 +08:00
ai.Dispose();
return true;
}
2021-04-08 20:09:59 +08:00
public static bool DestoryAI(this MainStoryAIComponent self, Unit unit)
{
MainStoryAI ai = self.GetAI(unit);
2021-04-08 20:09:59 +08:00
return DestoryAI(self, ai);
}
}
}