2023-10-19 15:00:19 +08:00
|
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
|
|
|
using Gameplay.AI;
|
|
|
|
|
using Gameplay.BT.Variables;
|
|
|
|
|
using Gameplay.Common;
|
|
|
|
|
using Gameplay.Level;
|
2023-12-13 16:20:41 +08:00
|
|
|
using Gameplay.Unit;
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
namespace Code.Scripts.Gameplay.BT.Task
|
|
|
|
|
{
|
|
|
|
|
public class BTBeginPatrol : BehaviorDesigner.Runtime.Tasks.Conditional
|
|
|
|
|
{
|
|
|
|
|
public SharedBattleInfo SharedBattleInfo;
|
|
|
|
|
|
|
|
|
|
private int _TargetCellIndex;
|
|
|
|
|
private int _lastTargetPointIndex;
|
|
|
|
|
private GameUnit _owner;
|
|
|
|
|
public override void OnStart()
|
|
|
|
|
{
|
2023-12-14 18:25:52 +08:00
|
|
|
_owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerId);
|
2023-10-19 15:00:19 +08:00
|
|
|
|
|
|
|
|
if (SharedBattleInfo.Value.PartolPointIndex == -1)
|
|
|
|
|
{
|
2024-01-04 18:55:53 +08:00
|
|
|
SharedBattleInfo.Value.PartolPointIndex = AIUtils.FindNearestPointInPatrolInfo(_owner, SharedBattleInfo.Value.PatrolInfos);
|
2023-10-19 15:00:19 +08:00
|
|
|
_TargetCellIndex = LevelManager.Instance.CurrentLevel.Map.BlockPosition2TGSCellIndex(SharedBattleInfo.Value.PatrolInfos[SharedBattleInfo.Value.PartolPointIndex].patrolPoint);
|
|
|
|
|
_lastTargetPointIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
|
|
|
{
|
2024-06-14 15:23:55 +08:00
|
|
|
if (SharedBattleInfo.Value.PartolPointIndex != _lastTargetPointIndex && !AIUtils.IsNeedStop(_owner))
|
2023-10-19 15:00:19 +08:00
|
|
|
{
|
|
|
|
|
_lastTargetPointIndex = SharedBattleInfo.Value.PartolPointIndex;
|
|
|
|
|
_TargetCellIndex = LevelManager.Instance.CurrentLevel.Map.BlockPosition2TGSCellIndex(SharedBattleInfo.Value.PatrolInfos[SharedBattleInfo.Value.PartolPointIndex].patrolPoint);
|
|
|
|
|
_owner.MoveTo(_TargetCellIndex, false);
|
2024-06-14 15:23:55 +08:00
|
|
|
return TaskStatus.Running;
|
2023-10-19 15:00:19 +08:00
|
|
|
}
|
2024-06-14 15:23:55 +08:00
|
|
|
|
|
|
|
|
if (_owner.transData.cellIndex == _TargetCellIndex)
|
|
|
|
|
return TaskStatus.Success;
|
|
|
|
|
|
|
|
|
|
if (!_owner.statusData.isMoveing) // 没有移动表示路径错误,被控制,被阻挡,需要重新设置移动
|
|
|
|
|
_lastTargetPointIndex = -1;
|
|
|
|
|
|
2023-10-19 15:00:19 +08:00
|
|
|
return TaskStatus.Running;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|