2023-08-22 19:08:45 +08:00
|
|
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
|
|
|
|
using Framework;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Gameplay.AI;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
using Gameplay.BT.Variables;
|
|
|
|
|
|
using Gameplay.Character;
|
|
|
|
|
|
using Gameplay.Common;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
using Gameplay.Level;
|
2023-12-13 16:20:41 +08:00
|
|
|
|
using Gameplay.Unit;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Code.Scripts.Gameplay.BT.Conditional
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BTBeingAttacked : BehaviorDesigner.Runtime.Tasks.Conditional
|
|
|
|
|
|
{
|
|
|
|
|
|
public SharedBattleInfo SharedBattleInfo;
|
|
|
|
|
|
public bool _isBeingAttacked;
|
|
|
|
|
|
private bool _isRegistered;
|
|
|
|
|
|
private GameUnit _owner;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
private GameUnit _target;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnStart()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (!_isRegistered)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Register<EventDataGetDamaged>(EventManager.EventName.INFIGHT_GET_DAMAGED, OnDamaged);
|
|
|
|
|
|
_isRegistered = true;
|
|
|
|
|
|
_isBeingAttacked = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-14 18:25:52 +08:00
|
|
|
|
_owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerId);
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDamaged(EventDataGetDamaged data)
|
|
|
|
|
|
{
|
|
|
|
|
|
//data.sender 发送受伤的角色 data.owner 受到伤害的角色
|
|
|
|
|
|
if (data.owner.GetID() == _owner.GetID())
|
|
|
|
|
|
{
|
|
|
|
|
|
_isBeingAttacked = true;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (data.sender != null)
|
|
|
|
|
|
{
|
2024-01-04 18:55:53 +08:00
|
|
|
|
_target = _target != null
|
|
|
|
|
|
? _target = AIUtils.GetNearestGameUnit(data.owner, data.sender, _target)
|
|
|
|
|
|
: _target = data.sender;
|
|
|
|
|
|
_target = AIUtils.GetNearestGameUnit(data.owner, data.sender, _target);
|
|
|
|
|
|
SharedBattleInfo.Value.theChosenOneId = _target.GetID();
|
|
|
|
|
|
DebugUtil.LogG($"BT harmed by: {data.sender?.GetID()} ,But Target is :{_target.GetID()}, owner: {_owner?.GetID()}");
|
2023-10-19 15:00:19 +08:00
|
|
|
|
}
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (_isBeingAttacked && SharedBattleInfo.Value.theChosenOneId != Constants.INVALID_UINT_ID
|
|
|
|
|
|
&& SharedBattleInfo.Value.AIName == LevelData.AIType.FallBackAI)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
|
|
|
|
|
return TaskStatus.Success;
|
|
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
if (_isBeingAttacked && SharedBattleInfo.Value.theChosenOneId != Constants.INVALID_UINT_ID
|
|
|
|
|
|
&& SharedBattleInfo.Value.AIName == LevelData.AIType.FallBackIntensifyAI)
|
2023-08-22 19:08:45 +08:00
|
|
|
|
{
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return AIUtils.FindEnemiesInAttackDistance(_owner).Contains(_target) ? TaskStatus.Running : TaskStatus.Success;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
2023-10-19 15:00:19 +08:00
|
|
|
|
return TaskStatus.Running;
|
2023-08-22 19:08:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnEnd()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_isBeingAttacked)
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister<EventDataGetDamaged>(EventManager.EventName.INFIGHT_GET_DAMAGED, OnDamaged);
|
|
|
|
|
|
_isRegistered = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
_isBeingAttacked = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnBehaviorComplete()
|
|
|
|
|
|
{
|
|
|
|
|
|
EventManager.Instance.Unregister<EventDataGetDamaged>(EventManager.EventName.INFIGHT_GET_DAMAGED, OnDamaged);
|
|
|
|
|
|
_isBeingAttacked = false;
|
|
|
|
|
|
_isRegistered = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|