75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using System;
|
|
using Gameplay.Unit;
|
|
|
|
namespace Gameplay.Summon
|
|
{
|
|
using Framework;
|
|
using Area;
|
|
using Common;
|
|
using LTGame;
|
|
|
|
public class SummonStateMineIdle : BaseSummonState
|
|
{
|
|
|
|
private SummonMine _mine;
|
|
|
|
private bool _needCheckSelfCell;
|
|
|
|
public SummonStateMineIdle(SummonMine owner) : base(owner, ESummonState.MineIdle)
|
|
{
|
|
_mine = 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);
|
|
}
|
|
|
|
protected override void _OnRunning()
|
|
{
|
|
base._OnRunning();
|
|
|
|
if (_needCheckSelfCell)
|
|
{
|
|
_needCheckSelfCell = false;
|
|
_CheckSelfCell();
|
|
}
|
|
}
|
|
|
|
protected override void _OnExit(NBaseState exitState, object param)
|
|
{
|
|
base._OnExit(exitState, param);
|
|
EventManager.Instance.Unregister(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, (Action<GameUnit>)_OnAnyCharacterCellIndexChange);
|
|
}
|
|
|
|
private void _OnAnyCharacterCellIndexChange(GameUnit unit)
|
|
{
|
|
_needCheckSelfCell = true;
|
|
}
|
|
|
|
private void _CheckSelfCell()
|
|
{
|
|
var cellIds = AreaManager.instance.GetCellIndexsAround(owner.transData.cellIndex, _mine.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.MineBoom;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|