NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Buff/Impl/BuffHoldFlag.cs

80 lines
2.2 KiB
C#
Raw Normal View History

2024-06-04 19:12:45 +08:00
using Framework;
using Gameplay.Fight.Flag;
2024-05-31 19:44:10 +08:00
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;
2024-06-03 12:22:29 +08:00
2024-06-05 14:38:13 +08:00
owner.statusData.isHoldFlag = true;
2024-06-03 12:22:29 +08:00
if (DebugUtil.LogEnable)
{
DebugUtil.Log($"角色 {owner.GetID()} 拿到了旗子");
}
2024-05-31 19:44:10 +08:00
}
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;
// 判断是否达到终点
2024-11-25 14:34:18 +08:00
if (FlagManager.instance.CheckArrived(_lastCellIndex))
2024-05-31 19:44:10 +08:00
{
_isSuccess = true;
owner.buffManager.RemoveBuff(this);
return;
}
}
}
protected override void _OnRemove()
{
base._OnRemove();
2024-06-05 14:38:13 +08:00
owner.statusData.isHoldFlag = false;
2024-05-31 19:44:10 +08:00
if (_isSuccess)
{
// 运到了终点,增加状态
owner.aliveData.FullStatus();
2024-06-03 12:22:29 +08:00
if (DebugUtil.LogEnable)
{
DebugUtil.Log($"角色 {owner.GetID()} 将 旗子 运到了终点");
}
2024-06-04 19:12:45 +08:00
EventManager.Instance.Send(EventManager.EventName.INFIGHT_FLAG_COLLECTED, owner);
2024-05-31 19:44:10 +08:00
}
else
{
// 没有运到终点,掉落到地上
FlagManager.instance.AddFlag(owner.transData.cellIndex);
2024-06-03 12:22:29 +08:00
if (DebugUtil.LogEnable)
{
DebugUtil.Log($"角色 {owner.GetID()} 掉落了 旗子 到 {owner.transData.cellIndex} 格子");
}
2024-05-31 19:44:10 +08:00
}
}
}
}