using System; using System.Collections; using System.Collections.Generic; using System.Linq; using BITFALL.Player.Movement; using BITFALL.Props; using BITKit; using BITKit.Entities; using BITKit.Sensors; using UnityEngine; namespace BITFALL.AI { public class AIBehavour : EntityBehavior,IStunObject { [SerializeReference,SubclassSelector] private ISensor sensor; [SerializeReference, SubclassSelector] private IReference stunAnimation; private readonly Optional grabTarget=new(); [Inject] private IHealth _health; public override void OnStart() { base.OnStart(); UnityEntity.AddListener(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(out var movement)) { movement.ExecuteCommand(new PlayerDisableMovementCommand() { LockFile = this, Disable = true, Duration = 2, Source = "被抓住了" }); UnityEntity.Invoke(Constant.Animation.Play,"Grapple"); grabTarget.SetValueThenAllow(movement); } break; } } public float Weight { get; set; } public event Action OnWeightChanged; public void Stun(float distance, float duration) { if (stunAnimation is null) return; UnityEntity.Invoke(Constant.Animation.Play,stunAnimation.Value); } } }