NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/AI/Conditional/BTBeginPatrol.cs

59 lines
2.1 KiB
C#
Raw Normal View History

2023-10-19 15:00:19 +08:00
using BehaviorDesigner.Runtime.Tasks;
using Gameplay.BT.Variables;
using Gameplay.Level;
2023-12-13 16:20:41 +08:00
using Gameplay.Unit;
2024-11-04 15:24:11 +08:00
using Gameplay.AI;
using Gameplay;
2023-10-19 15:00:19 +08:00
namespace Code.Scripts.Gameplay.BT.Task
{
public class BTBeginPatrol : BehaviorDesigner.Runtime.Tasks.Conditional
{
public SharedBattleInfo SharedBattleInfo;
2024-11-04 15:24:11 +08:00
private int _targetCellIndex;
2024-10-21 15:44:25 +08:00
private int _lastTargetPointIndex;
2023-10-19 15:00:19 +08:00
private GameUnit _owner;
2024-11-04 15:24:11 +08:00
private Map _map;
private Level _level;
2024-10-21 15:44:25 +08:00
2023-10-19 15:00:19 +08:00
public override void OnStart()
{
2023-12-14 18:25:52 +08:00
_owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerId);
2024-11-04 15:24:11 +08:00
_level = LevelManager.Instance.CurrentLevel;
if (_level != null)
_map = _level.Map;
2024-10-21 15:44:25 +08:00
2024-11-04 15:24:11 +08:00
// 回到离自己最近的巡逻点
2023-10-19 15:00:19 +08:00
if (SharedBattleInfo.Value.PartolPointIndex == -1)
{
2024-11-04 15:24:11 +08:00
SharedBattleInfo.Value.PartolPointIndex = AIUtils.FindNearestPointInPatrolInfo(_owner, SharedBattleInfo.Value.PatrolInfos);
2023-10-19 15:00:19 +08:00
_lastTargetPointIndex = -1;
}
}
public override TaskStatus OnUpdate()
{
2024-11-04 15:24:11 +08:00
if (AIUtils.AINeedStopUpdate(_level)) return TaskStatus.Running;
if (!_owner.statusData.isMoveing && SharedBattleInfo.Value.PartolPointIndex != _lastTargetPointIndex && !AIUtils.IsNeedStop(_owner))
2023-10-19 15:00:19 +08:00
{
_lastTargetPointIndex = SharedBattleInfo.Value.PartolPointIndex;
2024-11-04 15:24:11 +08:00
_targetCellIndex =
AIUtils.GetPatrolPointIndexFromVector2Int(_map, SharedBattleInfo.Value.PartolPointIndex, SharedBattleInfo.Value.PatrolInfos);
AIUtils.MoveTo(_owner, _targetCellIndex, false);
return TaskStatus.Running;
2023-10-19 15:00:19 +08:00
}
2024-11-04 15:24:11 +08:00
if (_owner.transData.cellIndex == _targetCellIndex)
return TaskStatus.Success;
2024-11-04 15:24:11 +08:00
/*if (!_owner.statusData.isMoveing) // 没有移动表示路径错误,被控制,被阻挡,需要重新设置移动
_lastTargetPointIndex = -1;*/
2023-10-19 15:00:19 +08:00
return TaskStatus.Running;
}
}
2024-10-21 15:44:25 +08:00
}