80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using Framework;
|
|
using Gameplay.Fight.Flag;
|
|
namespace Gameplay.Buff
|
|
{
|
|
public class BuffHoldFlag : BaseBuff
|
|
{
|
|
|
|
private bool _isSuccess;
|
|
private int _lastCellIndex;
|
|
|
|
protected override void _OnAdd()
|
|
{
|
|
base._OnAdd();
|
|
_isSuccess = false;
|
|
_lastCellIndex = owner.transData.cellIndex;
|
|
|
|
owner.statusData.isHoldFlag = true;
|
|
|
|
if (DebugUtil.LogEnable)
|
|
{
|
|
DebugUtil.Log($"角色 {owner.GetID()} 拿到了旗子");
|
|
}
|
|
}
|
|
|
|
protected override void _OnLogicUpdate(float dt)
|
|
{
|
|
base._OnLogicUpdate(dt);
|
|
|
|
if (!owner.statusData.CheckCanPickFlag())
|
|
{
|
|
owner.buffManager.RemoveBuff(this);
|
|
return;
|
|
}
|
|
|
|
if (_lastCellIndex != owner.transData.cellIndex)
|
|
{
|
|
_lastCellIndex = owner.transData.cellIndex;
|
|
// 判断是否达到终点
|
|
if (FlagManager.instance.CheckArrived(_lastCellIndex))
|
|
{
|
|
_isSuccess = true;
|
|
owner.buffManager.RemoveBuff(this);
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
protected override void _OnRemove()
|
|
{
|
|
base._OnRemove();
|
|
|
|
owner.statusData.isHoldFlag = false;
|
|
|
|
if (_isSuccess)
|
|
{
|
|
// 运到了终点,增加状态
|
|
owner.aliveData.FullStatus();
|
|
if (DebugUtil.LogEnable)
|
|
{
|
|
DebugUtil.Log($"角色 {owner.GetID()} 将 旗子 运到了终点");
|
|
}
|
|
|
|
EventManager.Instance.Send(EventManager.EventName.INFIGHT_FLAG_COLLECTED, owner);
|
|
}
|
|
else
|
|
{
|
|
// 没有运到终点,掉落到地上
|
|
FlagManager.instance.AddFlag(owner.transData.cellIndex);
|
|
|
|
if (DebugUtil.LogEnable)
|
|
{
|
|
DebugUtil.Log($"角色 {owner.GetID()} 掉落了 旗子 到 {owner.transData.cellIndex} 格子");
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|