45 lines
1.8 KiB
C#
45 lines
1.8 KiB
C#
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.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;
|
|
}
|
|
}
|
|
}
|