NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Summon/Logic/SLogicEmitBulletDistance.cs

110 lines
3.2 KiB
C#

using System.Collections.Generic;
using cfg.SkillCfg;
using Framework;
using Gameplay.Bullet;
using Gameplay.Unit;
namespace Gameplay.Summon.Logic
{
public class SLogicEmitBulletDistance : BaseSummonLogic
{
public int emitDistance;
public float emitInterval;
public int bulletId;
public bool onlyCharacter;
private float _emitTimer;
private ETargetType _preSelectTargetType;
private List<GameUnit> _preSelectTargets;
public SLogicEmitBulletDistance(BaseSummon summon) : base(summon)
{
_preSelectTargets = new List<GameUnit>();
}
protected override void _OnInit()
{
base._OnInit();
var bulletCfg = TableManager.Instance.Tables.BulletConfig.Get(bulletId);
if (bulletCfg == null)
{
DebugUtil.LogError("找不到子弹配置:{0}", bulletId);
return;
}
_preSelectTargetType = bulletCfg.FilterType;
_emitTimer = 0;
_preSelectTargets.Clear();
}
protected override void _OnLogicUpdate(float dt)
{
base._OnLogicUpdate(dt);
_emitTimer -= dt;
if (_emitTimer < 0)
{
_emitTimer += emitInterval;
_PreFilterTargets();
// 发射子弹
for (int i = 0; i < _preSelectTargets.Count; i++)
{
var target = _preSelectTargets[i];
BulletManager.instance.EmitBulletFromSummon(bulletId, target, _summon);
}
}
}
protected override void _OnDispose()
{
base._OnDispose();
_preSelectTargets.Clear();
}
private void _PreFilterTargets()
{
_preSelectTargets.Clear();
var creator = _summon.creator;
var allUnits = GameUnitManager.instance.infightUnits.unitList;
for (int i = 0; i < allUnits.Count; i++)
{
var unit = allUnits[i];
if (unit == null)
{
continue;
}
if (unit.isDisposed)
{
continue;
}
if (!unit.statusData.CheckCanBeTarget(null))
{
continue;
}
switch (_preSelectTargetType)
{
case ETargetType.SelfSide:
if (creator.commonData.troopId == unit.commonData.troopId)
{
_preSelectTargets.Add(unit);
}
break;
case ETargetType.EnemySide:
if (creator.commonData.troopId != unit.commonData.troopId)
{
_preSelectTargets.Add(unit);
}
break;
default:
DebugUtil.LogError("暂未处理的目标类型:{0}", _preSelectTargetType);
break;
}
}
}
}
}