using BehaviorDesigner.Runtime.Tasks; using Gameplay.AI; using Gameplay.BT.Variables; using Gameplay.Common; using Gameplay.Level; 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 = GameUnitMapper.Inst.GetUnitById(SharedBattleInfo.Value.ownerId); if (SharedBattleInfo.Value.PartolPointIndex == -1) { SharedBattleInfo.Value.PartolPointIndex = AIUtils.FindNeareatPointInPatrolInfo(_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); } else if(_owner.transData.cellIndex == _TargetCellIndex) { return TaskStatus.Success; } return TaskStatus.Running; } } }