104 lines
2.8 KiB
C#
104 lines
2.8 KiB
C#
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Unit;
|
|
namespace Gameplay.Summon.Logic
|
|
{
|
|
public class SLogicTaunt : BaseSummonLogic
|
|
{
|
|
|
|
public int tauntRange;
|
|
private bool _needCheckAllEnemy;
|
|
|
|
public SLogicTaunt(BaseSummon summon) : base(summon)
|
|
{
|
|
}
|
|
|
|
protected override void _OnInit()
|
|
{
|
|
base._OnInit();
|
|
|
|
_needCheckAllEnemy = true;
|
|
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnUnitCellChange);
|
|
}
|
|
|
|
protected override void _OnLogicUpdate(float dt)
|
|
{
|
|
base._OnLogicUpdate(dt);
|
|
|
|
if (_needCheckAllEnemy)
|
|
{
|
|
_needCheckAllEnemy = false;
|
|
_CheckAllEnemy();
|
|
}
|
|
}
|
|
|
|
protected override void _OnDispose()
|
|
{
|
|
base._OnDispose();
|
|
EventManager.Instance.Unregister<GameUnit>(EventManager.EventName.INFIGHT_UNIT_CELLINDEX_CHANGE, _OnUnitCellChange);
|
|
}
|
|
|
|
private void _OnUnitCellChange(GameUnit unit)
|
|
{
|
|
if (unit == _summon)
|
|
{
|
|
// 自己发生了变动,需要重新检查
|
|
_needCheckAllEnemy = true;
|
|
}
|
|
else
|
|
{
|
|
_CheckEnemy(unit);
|
|
}
|
|
}
|
|
|
|
private void _CheckAllEnemy()
|
|
{
|
|
var allUnits = GameUnitManager.instance.infightUnits.unitList;
|
|
for (int i = 0; i < allUnits.Count; i++)
|
|
{
|
|
var searchUnit = allUnits[i];
|
|
_CheckEnemy(searchUnit);
|
|
}
|
|
}
|
|
|
|
private void _CheckEnemy(GameUnit unit)
|
|
{
|
|
if (unit.isDisposed)
|
|
{
|
|
return;
|
|
}
|
|
if (!unit.statusData.CheckCanBeTarget(null))
|
|
{
|
|
return;
|
|
}
|
|
if (unit.commonData.troopId == _summon.creator.commonData.troopId)
|
|
{
|
|
return;
|
|
}
|
|
// 先计算距离
|
|
var selfIndex = _summon.transData.cellIndex;
|
|
var targetIndex = unit.transData.cellIndex;
|
|
var distance = AreaManager.instance.GetDistance(selfIndex, targetIndex);
|
|
if (distance <= tauntRange)
|
|
{
|
|
// 嘲讽
|
|
if (unit.controlData.tauntUnit != _summon)
|
|
{
|
|
unit.controlData.tauntUnit = _summon;
|
|
unit.UpdateTargets();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 取消嘲讽
|
|
if (unit.controlData.tauntUnit == _summon)
|
|
{
|
|
unit.controlData.tauntUnit = null;
|
|
unit.UpdateTargets();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|