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.
62 lines
2.7 KiB
62 lines
2.7 KiB
using System.Collections.Generic;
|
|
using CoreGame;
|
|
using Entitas;
|
|
|
|
namespace CoreGame.Render
|
|
{
|
|
public class AttractorInstantCatchSystem : 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 AttractorInstantCatchSystem(Contexts contexts)
|
|
{
|
|
m_AttractorGroup =
|
|
contexts.combat.GetGroup(CombatMatcher.AllOf(CombatMatcher.Attractor).NoneOf(CombatMatcher.Dead));
|
|
m_BeAttractGroup = contexts.combat.GetGroup(MatcherExt.s_CanInstantToBeAttractedMatcher);
|
|
}
|
|
|
|
public void Execute(float deltaTime)
|
|
{
|
|
m_BeAttractGroup.GetEntities(m_DropItemEntities);
|
|
if (m_DropItemEntities.Count == 0)
|
|
return;
|
|
m_AttractorGroup.GetEntities(m_AttractorEntities);
|
|
|
|
for (int i = 0; i < m_DropItemEntities.Count; i++)
|
|
{
|
|
var dropItemEntity = m_DropItemEntities[i];
|
|
var instantToBeAttracted = dropItemEntity.instantToBeAttracted;
|
|
var et = dropItemEntity.transformProxy;
|
|
if (instantToBeAttracted.specifiedAttractorEid != 0)
|
|
{
|
|
var specifiedAttractor = Contexts.Combat.GetEntity(instantToBeAttracted.specifiedAttractorEid);
|
|
if (specifiedAttractor.IsValid())
|
|
{
|
|
// dropItemEntity.AddBeAttracted(instantToBeAttracted.specifiedAttractorEid, et.position,
|
|
// et.GetLocalScale().x, BattleConst.DropItemScale, BattleConst.DropItemFlyDuration);
|
|
continue;
|
|
}
|
|
}
|
|
|
|
for (int j = 0; j < m_AttractorEntities.Count; j++)
|
|
{
|
|
var attractorEnt = m_AttractorEntities[j];
|
|
var range = attractorEnt.property.PickupRange;
|
|
if (instantToBeAttracted.pickUpRange > 0.001f)
|
|
{
|
|
range = instantToBeAttracted.pickUpRange;
|
|
}
|
|
|
|
var attractorPos = attractorEnt.transformProxy.position;
|
|
var inAreaRange = (attractorPos - et.position).SqrMagnitude() < range * range;
|
|
if (!inAreaRange) continue;
|
|
// dropItemEntity.AddBeAttracted(attractorEnt.creationIndex, et.position,
|
|
// et.GetLocalScale().x, BattleConst.DropItemScale, BattleConst.DropItemFlyDuration);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|