71 lines
2.0 KiB
C#
71 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using Gameplay.Common;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
|
|
namespace Gameplay.Summon
|
|
{
|
|
using Gameplay.Area;
|
|
using Gameplay.Bullet;
|
|
using LTGame;
|
|
|
|
public class SummonStateTent : BaseSummonState
|
|
{
|
|
|
|
private readonly SummonTent _tent;
|
|
|
|
private float _remainTriggerTime;
|
|
|
|
public SummonStateTent(SummonTent tent) : base(tent, ESummonState.Tent)
|
|
{
|
|
_tent = tent;
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState, object param)
|
|
{
|
|
base._OnEnter(exitState, param);
|
|
_remainTriggerTime = _tent.triggerInterval;
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
_remainTriggerTime -= deltaTime;
|
|
if (_remainTriggerTime <= 0)
|
|
{
|
|
_remainTriggerTime += _tent.triggerInterval;
|
|
_DoLogic();
|
|
}
|
|
}
|
|
|
|
private void _DoLogic()
|
|
{
|
|
var checkDistance = _tent.checkDistance;
|
|
|
|
// 根据作用区域筛选目标
|
|
var selectIndexs = AreaManager.instance.GetCellIndexsAround(owner.transData.cellIndex, checkDistance);
|
|
|
|
for (var i = 0; i < selectIndexs.Count; ++i)
|
|
{
|
|
var cellIndex = selectIndexs[i];
|
|
var units = AreaManager.instance.GetUnitsByCellIndex(cellIndex);
|
|
_TryEmitBulletToUnits(units);
|
|
}
|
|
|
|
}
|
|
|
|
private void _TryEmitBulletToUnits(List<GameUnit> units)
|
|
{
|
|
var bulletId = _tent.bulletId;
|
|
for (int i = 0; i < units.Count; i++)
|
|
{
|
|
var unit = units[i];
|
|
if (unit.gameunitType != EGameUnitType.Character) continue;
|
|
if (unit.commonData.troopId != owner.creator.commonData.troopId) continue;
|
|
BulletManager.instance.EmitBullet(bulletId, unit, owner.creator);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|