50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using BehaviorDesigner.Runtime.Tasks;
|
|
using Gameplay.BT.Variables;
|
|
using Gameplay.Unit;
|
|
using Gameplay.AI;
|
|
using Framework;
|
|
|
|
namespace Code.Scripts.Gameplay.BT.Task
|
|
{
|
|
public class BTMoveAway : Action
|
|
{
|
|
public SharedBattleInfo SharedBattleInfo;
|
|
private GameUnit _owner;
|
|
private bool lastMoveState;
|
|
|
|
private AIUtils.AvoidanceContext avoidContext;
|
|
|
|
public override void OnStart()
|
|
{
|
|
_owner = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.ownerID);
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_owner == null) return TaskStatus.Failure;
|
|
|
|
// 避开其他AI
|
|
AIUtils.TryAvoidOtherUnit(_owner, ref avoidContext, SharedBattleInfo.Value.targetID);
|
|
|
|
if (_owner != null && SharedBattleInfo.Value.targetID != Constants.INVALID_UINT_ID &&
|
|
!AIUtils.IsNeedStop(_owner))
|
|
{
|
|
if (GameUnitManager.instance.infightUnits.Contains(SharedBattleInfo.Value.targetID))
|
|
{
|
|
var enemy = GameUnitManager.instance.infightUnits.Search(SharedBattleInfo.Value.targetID);
|
|
if (enemy != null && !enemy.statusData.isDead)
|
|
{
|
|
if (AIUtils.MoveAway(_owner, enemy))
|
|
SharedBattleInfo.Value.targetID = Constants.INVALID_UINT_ID;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SharedBattleInfo.Value.targetID = Constants.INVALID_UINT_ID;
|
|
}
|
|
}
|
|
|
|
return TaskStatus.Success;
|
|
}
|
|
}
|
|
} |