75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using System;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Common;
|
|
using LTGame;
|
|
namespace Gameplay.Summon
|
|
{
|
|
public class SummonStateMine2Idle : BaseSummonState
|
|
{
|
|
|
|
private SummonMine2 _mine2;
|
|
|
|
private bool _needCheckSelfCell;
|
|
|
|
public SummonStateMine2Idle(SummonMine2 owner) : base(owner, ESummonState.Mine2Idle)
|
|
{
|
|
_mine2 = owner;
|
|
}
|
|
|
|
protected override void _OnEnter(NBaseState exitState,
|
|
object param)
|
|
{
|
|
base._OnEnter(exitState, param);
|
|
_needCheckSelfCell = true;
|
|
|
|
EventManager.Instance.Register(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
|
}
|
|
|
|
private void _OnAnyCharacterCellIndexChange(GameUnit unit)
|
|
{
|
|
_needCheckSelfCell = true;
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
|
|
if (_needCheckSelfCell)
|
|
{
|
|
_needCheckSelfCell = false;
|
|
_CheckSelfCell();
|
|
}
|
|
}
|
|
|
|
private void _CheckSelfCell()
|
|
{
|
|
var cellIds = AreaManager.instance.GetCellIndexsAround(owner.transData.cellIndex, _mine2.checkDistance);
|
|
for (int i = 0; i < cellIds.Count; i++)
|
|
{
|
|
var cellId = cellIds[i];
|
|
var units = AreaManager.instance.GetUnitsByCellIndex(cellId);
|
|
for (var j = 0; j < units.Count; ++j)
|
|
{
|
|
var unit = units[j];
|
|
if (unit.commonData.troopId != owner.commonData.troopId)
|
|
{
|
|
// 爆炸
|
|
isFinished = true;
|
|
nextState = ESummonState.Mine2Boom;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
protected override void _OnExit(NBaseState exitState, object param)
|
|
{
|
|
base._OnExit(exitState, param);
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
|
}
|
|
|
|
}
|
|
}
|