using BehaviorDesigner.Runtime.Tasks; using Gameplay.BT.Variables; using Gameplay.Level; using Gameplay.Unit; using Gameplay.AI; using Gameplay; 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; private Map _map; private Level _level; public override void OnStart() { _owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerID); _level = LevelManager.Instance.CurrentLevel; if (_level != null) _map = _level.Map; // 回到离自己最近的巡逻点 if (SharedBattleInfo.Value.patrolPointIndex == -1) { SharedBattleInfo.Value.patrolPointIndex = AIUtils.FindNearestPointInPatrolInfo(_owner, SharedBattleInfo.Value.patrolInfos); _lastTargetPointIndex = -1; } } public override TaskStatus OnUpdate() { if (AIUtils.AINeedStopUpdate(_level)) return TaskStatus.Running; if (!_owner.statusData.isMoveing && SharedBattleInfo.Value.patrolPointIndex != _lastTargetPointIndex && !AIUtils.IsNeedStop(_owner)) { _lastTargetPointIndex = SharedBattleInfo.Value.patrolPointIndex; _targetCellIndex = AIUtils.GetPatrolPointIndexFromVector2Int(_map, SharedBattleInfo.Value.patrolPointIndex, SharedBattleInfo.Value.patrolInfos); AIMoveHelper.MoveToCell(_owner, _targetCellIndex, false); return TaskStatus.Running; } if (_owner.transData.cellIndex == _targetCellIndex) return TaskStatus.Success; /*if (!_owner.statusData.isMoveing) // 没有移动表示路径错误,被控制,被阻挡,需要重新设置移动 _lastTargetPointIndex = -1;*/ return TaskStatus.Running; } } }