using System; using System.Collections.Generic; using Entitas; namespace CoreGame.Render { public class SummonExistSys : IExecuteSystem { private CombatContext m_Context; private IGroup m_SummonGroup; private readonly List m_CacheEntities = new List(); public SummonExistSys(CombatContext context) { m_Context = context; var matcher = (Matcher)Matcher.AllOf(CombatComponentsLookup.Summon); matcher.componentNames = CombatComponentsLookup.componentNames; m_SummonGroup = m_Context.GetGroup(matcher); } public void Execute(float deltaTime) { m_SummonGroup.GetEntities(m_CacheEntities); foreach (var ent in m_CacheEntities) { var summon = ent.summon; summon.maxExistTime -= deltaTime; if (summon.maxExistTime <= 0f) { ent.DispatchEvent(ClientEvent.OnEntityBeKill, null); } switch (summon.survivalType) { case SummonSurvivalType.AttackCount: if (summon.survivalParam1 <= 0.1f) { ent.DispatchEvent(ClientEvent.OnEntityBeKill, null); } break; case SummonSurvivalType.DurationTime: summon.survivalParam1 -= deltaTime; if (summon.survivalParam1 <= 0f) { ent.DispatchEvent(ClientEvent.OnEntityBeKill, null); } break; default: throw new ArgumentOutOfRangeException(); } } } } }