using System.Collections.Generic; using CoreGame; using Entitas; namespace CoreGame.Render { public class AttractorStartWaitCatchSystem : IExecuteSystem { private readonly IGroup m_AttractorGroup; private readonly IGroup m_BeAttractGroup; private readonly List m_AttractorEntities = new(); private readonly List m_DropItemEntities = new(); public AttractorStartWaitCatchSystem(Contexts contexts) { var matcher = CombatMatcher.AllOf(CombatMatcher.Attractor).NoneOf(CombatMatcher.WaitPickUpDropItem); m_AttractorGroup = contexts.combat.GetGroup(matcher); m_BeAttractGroup = contexts.combat.GetGroup(MatcherExt.s_CanWaitToBeAttractedMatcher); } public void Execute(float deltaTime) { m_BeAttractGroup.GetEntities(m_DropItemEntities); if (m_DropItemEntities.Count == 0) return; m_AttractorGroup.GetEntities(m_AttractorEntities); if (m_AttractorEntities.Count == 0) return; for (int i = 0; i < m_AttractorEntities.Count; i++) { var attractorEnt = m_AttractorEntities[i]; if (attractorEnt.isDead) continue; var range = attractorEnt.property.PickupRange; for (int j = 0; j < m_DropItemEntities.Count; j++) { var dropItemEntity = m_DropItemEntities[j]; var waitToBeAttracted = dropItemEntity.waitToBeAttracted; var et = dropItemEntity.transformProxy; if (waitToBeAttracted.pickUpRange > 0.001f) { range = waitToBeAttracted.pickUpRange; } var attractorPos = attractorEnt.transformProxy.position; var inAreaRange = (attractorPos - et.position).SqrMagnitude() < range * range; if (!inAreaRange) continue; attractorEnt.AddWaitPickUpDropItem(dropItemEntity.creationIndex, 0f); break; } } } } }