68 lines
1.5 KiB
C#
68 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BITFALL.Player.Movement;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Sensors;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.AI
|
|
{
|
|
public class AIBehavour : EntityBehavior
|
|
{
|
|
[SerializeReference,SubclassSelector] private ISensor sensor;
|
|
|
|
private readonly Optional<IEntityMovement> grabTarget=new();
|
|
|
|
[Inject]
|
|
private IHealth _health;
|
|
public override void OnStart()
|
|
{
|
|
base.OnStart();
|
|
UnityEntity.AddListener<string>(OnCommand);
|
|
|
|
_health.OnSetAlive += OnSetAlive;
|
|
}
|
|
|
|
private void OnSetAlive(bool obj)
|
|
{
|
|
if (obj) return;
|
|
if(grabTarget.Allow)
|
|
{
|
|
grabTarget.Value.ExecuteCommand(new PlayerDisableMovementCommand()
|
|
{
|
|
LockFile = this,
|
|
Disable = false
|
|
});
|
|
grabTarget.Clear();
|
|
}
|
|
}
|
|
|
|
private async void OnCommand(string obj)
|
|
{
|
|
switch (obj)
|
|
{
|
|
case "Grapple":
|
|
await sensor.Execute();
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
var target = sensor.Get().FirstOrDefault();
|
|
if (target && target.TryGetComponent<IEntityMovement>(out var movement))
|
|
{
|
|
movement.ExecuteCommand(new PlayerDisableMovementCommand()
|
|
{
|
|
LockFile = this,
|
|
Disable = true,
|
|
Duration = 2,
|
|
Source = "<color=yellow>被抓住了</color>"
|
|
});
|
|
UnityEntity.Invoke(Constant.Animation.Play,"Grapple");
|
|
grabTarget.SetValueThenAllow(movement);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|