You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

55 lines
2.2 KiB

using System.Collections.Generic;
using CoreGame;
using Entitas;
namespace CoreGame.Render
{
public class AttractorStartWaitCatchSystem : IExecuteSystem
{
private readonly IGroup<CombatEntity> m_AttractorGroup;
private readonly IGroup<CombatEntity> m_BeAttractGroup;
private readonly List<CombatEntity> m_AttractorEntities = new();
private readonly List<CombatEntity> 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;
}
}
}
}
}