62 lines
2.2 KiB
C#
62 lines
2.2 KiB
C#
using BehaviorDesigner.Runtime.Tasks;
|
|
using Framework;
|
|
using Gameplay.AI;
|
|
using Gameplay.BT.Variables;
|
|
using Gameplay.Common;
|
|
using Gameplay.Level;
|
|
|
|
namespace Code.Scripts.Gameplay.BT.Conditional
|
|
{
|
|
public class BTWithinSight : BehaviorDesigner.Runtime.Tasks.Conditional
|
|
{
|
|
public SharedBattleInfo SharedBattleInfo;
|
|
|
|
private GameUnit _owner;
|
|
private Level _level;
|
|
|
|
public override void OnStart()
|
|
{
|
|
_level = LevelManager.Instance.CurrentLevel;
|
|
_owner = GameUnitMapper.Inst.GetUnitById(SharedBattleInfo.Value.ownerId);
|
|
DebugUtil.LogG($"BTWithinSight OnAwake, aiOwner id: {_owner?.GetID()}");
|
|
}
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_owner != null && _level != null
|
|
&& _owner.controlData.followUnit == null
|
|
&& _owner.controlData.targetEnemy == null)
|
|
{
|
|
var enemy = AIUtils.FindNearestEnemyInSightDistance(_owner);
|
|
if (enemy != null)
|
|
{
|
|
SharedBattleInfo.Value.theChosenOneId = enemy.GetID();
|
|
return TaskStatus.Success;
|
|
}
|
|
else
|
|
{
|
|
SharedBattleInfo.Value.theChosenOneId = Constants.INVALID_UINT_ID;
|
|
return TaskStatus.Failure;
|
|
}
|
|
}
|
|
|
|
else if (_owner != null && _level != null
|
|
&& (_owner.controlData.followUnit != null || _owner.controlData.targetEnemy != null))
|
|
{
|
|
if (_owner.controlData.targetEnemy != null)
|
|
{
|
|
SharedBattleInfo.Value.theChosenOneId = _owner.controlData.targetEnemy.GetID();
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (_owner.controlData.followUnit != null)
|
|
{
|
|
SharedBattleInfo.Value.theChosenOneId = _owner.controlData.followUnit.GetID();
|
|
return TaskStatus.Success;
|
|
}
|
|
}
|
|
return TaskStatus.Running;
|
|
}
|
|
}
|
|
} |