109 lines
2.7 KiB
C#
109 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Combat;
|
|
using BITFALL.Entities.Equipment;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Entities.Melee;
|
|
using BITKit.Sensors;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using IEntity = BITKit.Entities.IEntity;
|
|
|
|
namespace BITFALL.Entities.Equipment
|
|
{
|
|
public class AIEquipController : MonoBehaviour,IEquipBase
|
|
{
|
|
[SerializeField] protected Optional<int> overrideDamage;
|
|
[SerializeField] protected AssetableItem assetableItem;
|
|
[SerializeField] protected Optional<Tag> ignoreTag;
|
|
[SerializeReference,SubclassSelector] protected ISensor targetSensor;
|
|
[SerializeReference, SubclassSelector] protected IMeleeService meleeService;
|
|
protected AssetableEquip equip => assetableItem as AssetableEquip;
|
|
protected Transform Transform { get; private set; }
|
|
public bool IsEntered { get; set; }
|
|
protected readonly IntervalUpdate meleeInterval = new(1);
|
|
[Inject] public IHealth _health;
|
|
|
|
public virtual void Entry()
|
|
{
|
|
|
|
}
|
|
public virtual UniTask EntryAsync()
|
|
{
|
|
return UniTask.CompletedTask;
|
|
}
|
|
public virtual void Entered()
|
|
{
|
|
UnityEntity.AddListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
|
|
}
|
|
public virtual void Exit()
|
|
{
|
|
}
|
|
|
|
public virtual UniTask ExitAsync()
|
|
{
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
public virtual void Exited()
|
|
{
|
|
UnityEntity.RemoveListener<string>(Constant.Animation.OnEvent, OnAnimationEvent);
|
|
}
|
|
protected virtual void OnAnimationEvent(string animationEventName)
|
|
{
|
|
switch (animationEventName)
|
|
{
|
|
case BITConstant.Player.Attack:
|
|
case BITConstant.Player.Melee:
|
|
meleeService.Melee(new MeleeCommand()
|
|
{
|
|
Damage = equip.MeleeDamage,
|
|
Force = equip.MeleeForce,
|
|
PlayerId = Entity.Id,
|
|
Position = transform.position,
|
|
Range = equip.MeleeRange,
|
|
Forward = UnityEntity.transform.forward,
|
|
IgnoreTags = ignoreTag.Allow ?ignoreTag.Value.GetTags():Array.Empty<string>(),
|
|
ForceHitStun = true,
|
|
Limit = 1,
|
|
});
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnAwake()
|
|
{
|
|
Transform = transform;
|
|
}
|
|
|
|
public virtual void OnStart()
|
|
{
|
|
}
|
|
|
|
public virtual void OnUpdate(float deltaTime)
|
|
{
|
|
}
|
|
|
|
public string AddressablePath => assetableItem.AddressablePath;
|
|
public IEntity Entity { get; set; }
|
|
public Entity UnityEntity=>Entity as Entity;
|
|
public IBasicItem Item { get; set; }
|
|
|
|
public bool IsSupportItem(IBasicItem item) => item?.AddressablePath == AddressablePath;
|
|
|
|
public void PlayAudio(string name)
|
|
{
|
|
}
|
|
protected void RequestMelee()
|
|
{
|
|
if (meleeInterval.AllowUpdate is false) return;
|
|
UnityEntity.Invoke(Constant.Animation.Play, BITConstant.Player.Melee);
|
|
}
|
|
}
|
|
|
|
}
|