127 lines
4.2 KiB
C#
127 lines
4.2 KiB
C#
using System.Collections.Generic;
|
|
using cfg.BulletCfg;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Bullet;
|
|
using Gameplay.Common;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using LTGame;
|
|
namespace Gameplay.Summon
|
|
{
|
|
public class BulletBoxStateIdle : BaseSummonState
|
|
{
|
|
|
|
private SummonBulletBox _bulletBox;
|
|
|
|
private float _remainCheckTime;
|
|
private DataBullet _bulletConfig;
|
|
private List<GameUnit> _cacheUnits = new List<GameUnit>();
|
|
|
|
public BulletBoxStateIdle(SummonBulletBox bulletBox) : base(bulletBox, ESummonState.Idle)
|
|
{
|
|
this._bulletBox = bulletBox;
|
|
}
|
|
|
|
private bool _isInBuilding = false;
|
|
private void _WaitCreateEndAndSetInBuilding()
|
|
{
|
|
if (_isInBuilding) return;
|
|
var creator = owner.creator;
|
|
if (creator == null) return;
|
|
if (creator is Character.Character unitCharacter)
|
|
{
|
|
if (creator.statusData.isInSkilling) return;
|
|
unitCharacter.EnterBuilding(owner);
|
|
_isInBuilding = true;
|
|
}
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnEnter(exitState, param);
|
|
_remainCheckTime = _bulletBox.checkTime;
|
|
_bulletConfig = TableManager.Instance.Tables.BulletConfig.GetOrDefault(_bulletBox.emitBulletId);
|
|
if (_bulletConfig == null)
|
|
{
|
|
DebugUtil.LogError($"子弹配置不存在, ID: {_bulletBox.emitBulletId}");
|
|
return;
|
|
}
|
|
|
|
_isInBuilding = false;
|
|
|
|
EventManager.Instance.Register<EDExitUnitContainer>(EventManager.EventName.INFIGHT_EXIT_UNITCONTAINER, _OnUnitExitUnitContainer);
|
|
|
|
}
|
|
|
|
private void _OnUnitExitUnitContainer(EDExitUnitContainer ed)
|
|
{
|
|
if (ed.fromUnit == owner)
|
|
{
|
|
// 创建者退出了帐篷, 帐篷直接销毁
|
|
owner.needRemove = true;
|
|
}
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
|
|
if (_isInBuilding)
|
|
{
|
|
_remainCheckTime -= deltaTime;
|
|
if (_remainCheckTime <= 0)
|
|
{
|
|
_remainCheckTime = _bulletBox.checkTime;
|
|
_CheckAndEmitBullet();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_WaitCreateEndAndSetInBuilding();
|
|
}
|
|
}
|
|
|
|
private void _CheckAndEmitBullet()
|
|
{
|
|
var checkDistance = _bulletBox.checkDistance;
|
|
|
|
var selfCellIndex = owner.transData.cellIndex;
|
|
var aroundCellIndexList = AreaManager.instance.GetCellIndexsAround(selfCellIndex, checkDistance, false);
|
|
_cacheUnits.Clear();
|
|
for (int i = 0; i < aroundCellIndexList.Count; i++)
|
|
{
|
|
var checkCellIndex = aroundCellIndexList[i];
|
|
var units = AreaManager.instance.GetUnitsByCellIndex(checkCellIndex);
|
|
for (int j = 0; j < units.Count; j++)
|
|
{
|
|
var checkUnit = units[j];
|
|
if (!checkUnit.statusData.isOnFloor) continue;
|
|
if (checkUnit.commonData.troopId != owner.creator.commonData.troopId) continue;
|
|
if (BulletManagerHelper.CheckBulletFilter(owner.creator, checkUnit, _bulletConfig))
|
|
{
|
|
_cacheUnits.Add(checkUnit);
|
|
}
|
|
}
|
|
}
|
|
|
|
var bulletId = _bulletBox.emitBulletId;
|
|
for (int i = 0; i < _cacheUnits.Count; i++)
|
|
{
|
|
var checkUnit = _cacheUnits[i];
|
|
BulletManager.instance.EmitBullet(bulletId, checkUnit, owner.creator);
|
|
}
|
|
}
|
|
|
|
protected override void _OnExit(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnExit(exitState, param);
|
|
|
|
EventManager.Instance.Unregister<EDExitUnitContainer>(EventManager.EventName.INFIGHT_EXIT_UNITCONTAINER, _OnUnitExitUnitContainer);
|
|
}
|
|
|
|
}
|
|
}
|