using BehaviorDesigner.Runtime.Tasks; using Gameplay.AI; using Gameplay.BT.Variables; using Gameplay.Common; using Gameplay.Level; using Gameplay.Unit; 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() { _owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerId); if (SharedBattleInfo.Value.PartolPointIndex == -1) { SharedBattleInfo.Value.PartolPointIndex = AIUtils.FindNearestPointInPatrolInfo(_owner, SharedBattleInfo.Value.PatrolInfos); _TargetCellIndex = LevelManager.Instance.CurrentLevel.Map.BlockPosition2TGSCellIndex(SharedBattleInfo.Value.PatrolInfos[SharedBattleInfo.Value.PartolPointIndex].patrolPoint); _lastTargetPointIndex = -1; } } public override TaskStatus OnUpdate() { if (SharedBattleInfo.Value.PartolPointIndex != _lastTargetPointIndex && !AIUtils.IsNeedStop(_owner)) { _lastTargetPointIndex = SharedBattleInfo.Value.PartolPointIndex; _TargetCellIndex = LevelManager.Instance.CurrentLevel.Map.BlockPosition2TGSCellIndex(SharedBattleInfo.Value.PatrolInfos[SharedBattleInfo.Value.PartolPointIndex].patrolPoint); _owner.MoveTo(_TargetCellIndex, false); return TaskStatus.Running; } if (_owner.transData.cellIndex == _TargetCellIndex) return TaskStatus.Success; if (!_owner.statusData.isMoveing) // 没有移动表示路径错误,被控制,被阻挡,需要重新设置移动 _lastTargetPointIndex = -1; return TaskStatus.Running; } } }