using System.Collections.Generic; using Entitas; namespace CoreGame.Render { /// /// 暴风雪等区域实体, 定时释放技能 /// public class ZoneSys : IExecuteSystem { private readonly IGroup m_ZoneGroup; private readonly List m_CacheEntities = new List(); public ZoneSys(CombatContext contexts) { m_ZoneGroup = contexts.GetGroup(CombatMatcher.Zone); } public void Execute(float deltaTime) { m_ZoneGroup.GetEntities(m_CacheEntities); for (int i = 0; i < m_CacheEntities.Count; i++) { ProcessZone(m_CacheEntities[i], deltaTime); } } private void ProcessZone(CombatEntity entity, float deltaTime) { var zone = entity.zone; if (zone.hasInvalidated) return; if (zone.duration < 0 || (zone.loopType == ZoneLoopType.Count && zone.loopCnt <= 0)) { var attachAbilityProcess = false; var endAbilityProcess = false; if (zone.attachAbilityCtxSeq > 0) { if (entity.abilitySystem.HasAbilityProcess(zone.attachAbilityCtxSeq)) { attachAbilityProcess = true; } else { entity.abilitySystem.UnGrantAbility(zone.attachAbilityCtxSeq); } } if (zone.endAbilityCtxSeq > 0) { if (entity.abilitySystem.HasAbilityProcess(zone.endAbilityCtxSeq)) { endAbilityProcess = true; } else if (ZoneSrv.ZoneActiveAbility(entity, zone.endAbilityCtxSeq, true)) { ZoneSrv.InvalidateZone(entity); endAbilityProcess = true; } } if (attachAbilityProcess == false && endAbilityProcess == false) { ZoneSrv.DestroyZone(entity); } return; } zone.duration -= deltaTime; if (zone.isFollow) { var targetEnt = Contexts.Combat.GetEntity(zone.targetEid); var entityTransformProxy = entity.logicTransform; if (targetEnt.IsValid()) { var targetEntTransformProxy = targetEnt.logicTransform; zone.lastPos = targetEntTransformProxy.position; zone.lastDir = targetEntTransformProxy.forward; } else { if (zone.entInvalidDestroy) { ZoneSrv.DestroyZone(entity); return; } } entityTransformProxy.SetPosition(zone.lastPos + zone.offsetPos); entityTransformProxy.SetDirection(zone.lastDir); } if (zone.loopType == ZoneLoopType.Time) { zone.accumulatedTime += deltaTime; if (zone.accumulatedTime >= zone.interval) { zone.accumulatedTime -= zone.interval; ZoneSrv.ZoneActiveAbility(entity, zone.attachAbilityCtxSeq, false); } } else if (zone.loopType == ZoneLoopType.Count) { if (zone.loopCnt > 0) { if (ZoneSrv.ZoneActiveAbility(entity, zone.attachAbilityCtxSeq, false)) { zone.loopCnt--; } } } } } }