77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using Framework;
|
|
using Gameplay.Area;
|
|
using Gameplay.Unit;
|
|
using Gameplay.Unit.Data;
|
|
using Gameplay.Vehicle.Impl;
|
|
namespace Gameplay.Buff
|
|
{
|
|
public class BuffChangeReadyArea : BaseBuff
|
|
{
|
|
|
|
private NormalVehicle _vehicle;
|
|
private int _oldRange;
|
|
|
|
protected override void _OnAdd()
|
|
{
|
|
base._OnAdd();
|
|
|
|
_vehicle = owner as NormalVehicle;
|
|
if (_vehicle == null)
|
|
{
|
|
throw new Exception("该buff只能给载具添加: " + configData.ID);
|
|
}
|
|
|
|
_oldRange = _vehicle.aroundReadyRange;
|
|
|
|
var range = _TryGetIntParam(0);
|
|
_vehicle.aroundReadyRange = range;
|
|
|
|
// 修改上阵区域
|
|
AreaManager.instance.readyAreaManager.isVehicleBuffActive = true;
|
|
AreaManager.instance.readyAreaManager.followVehicle = _vehicle;
|
|
|
|
EventManager.Instance.Register<GameUnit>(EventManager.EventName.INFIGHT_UNIT_READY, _OnUnitEnterBattle);
|
|
}
|
|
|
|
private void _OnUnitEnterBattle(GameUnit unit)
|
|
{
|
|
// 仅监听己方
|
|
if (unit.commonData.troopId != owner.commonData.troopId)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 仅监听角色
|
|
if (unit.gameunitType != EGameUnitType.Character)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var unitCellIndex = unit.transData.cellIndex;
|
|
var vehicleCellIndex = owner.transData.cellIndex;
|
|
var distance = AreaManager.instance.GetDistance(unitCellIndex, vehicleCellIndex);
|
|
if (distance > _vehicle.aroundReadyRange)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 标记为删除
|
|
owner.buffManager.AddNeedRemoveBuff(this);
|
|
}
|
|
|
|
protected override void _OnRemove()
|
|
{
|
|
base._OnRemove();
|
|
// 恢复上阵区域
|
|
_vehicle.aroundReadyRange = _oldRange;
|
|
AreaManager.instance.readyAreaManager.isVehicleBuffActive = false;
|
|
|
|
EventManager.Instance.Unregister<GameUnit>(EventManager.EventName.INFIGHT_UNIT_READY, _OnUnitEnterBattle);
|
|
|
|
AreaManager.instance.readyAreaManager.isVehicleBuffActive = false;
|
|
}
|
|
|
|
}
|
|
}
|