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.PartolPointIndex == -1) { SharedBattleInfo.Value.PartolPointIndex = 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.PartolPointIndex != _lastTargetPointIndex && !AIUtils.IsNeedStop(_owner)) { _lastTargetPointIndex = SharedBattleInfo.Value.PartolPointIndex; _targetCellIndex = AIUtils.GetPatrolPointIndexFromVector2Int(_map, SharedBattleInfo.Value.PartolPointIndex, SharedBattleInfo.Value.PatrolInfos); AIUtils.MoveTo(_owner, _targetCellIndex, false); return TaskStatus.Running; } if (_owner.transData.cellIndex == _targetCellIndex) return TaskStatus.Success; /*if (!_owner.statusData.isMoveing) // 没有移动表示路径错误,被控制,被阻挡,需要重新设置移动 _lastTargetPointIndex = -1;*/ return TaskStatus.Running; } } }