2023-10-20 19:31:12 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Xml;
|
2023-10-24 23:37:59 +08:00
|
|
|
using BITFALL.Combat;
|
|
|
|
using BITKit.Animations;
|
2023-10-20 19:31:12 +08:00
|
|
|
using BITKit.Entities.Melee;
|
|
|
|
using Unity.Mathematics;
|
|
|
|
using UnityEngine;
|
|
|
|
namespace BITKit.Entities
|
|
|
|
{
|
2023-10-24 23:37:59 +08:00
|
|
|
[CustomType(typeof(IMeleeCombat))]
|
2023-10-30 01:25:53 +08:00
|
|
|
public class EntityMelee : EntityBehavior,IMeleeCombat
|
2023-10-20 19:31:12 +08:00
|
|
|
{
|
2023-10-24 23:37:59 +08:00
|
|
|
[SerializeField] private UnityAnimator unityAnimator;
|
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
[Header(Constant.Header.Settings)]
|
2023-10-24 23:37:59 +08:00
|
|
|
[SerializeField] private int damage=50;
|
2023-11-15 23:54:54 +08:00
|
|
|
[SerializeField] private string[] ignoreTags;
|
2023-10-24 23:37:59 +08:00
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
[SerializeReference, SubclassSelector, Inject(true)] private IMeleeService meleeService;
|
2023-10-24 23:37:59 +08:00
|
|
|
[Inject(true)] private IEntityOverride entityOverride;
|
2023-11-15 23:54:54 +08:00
|
|
|
private readonly IntervalUpdate disableMelee = new(0.64f);
|
2023-10-20 19:31:12 +08:00
|
|
|
public override void OnStart()
|
|
|
|
{
|
2023-10-24 23:37:59 +08:00
|
|
|
unityAnimator[0].onStateEnter += OnStateEnter;
|
2023-11-15 23:54:54 +08:00
|
|
|
|
|
|
|
if (entityOverride is not null)
|
|
|
|
{
|
|
|
|
entityOverride.OnOverride += OnOverride;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnOverride(bool obj)
|
|
|
|
{
|
|
|
|
disableMelee.Reset();
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
2023-10-24 23:37:59 +08:00
|
|
|
|
|
|
|
private void OnStateEnter(string obj)
|
|
|
|
{
|
|
|
|
if(entityOverride is null)return;
|
|
|
|
if (obj is "HitStun")
|
|
|
|
{
|
|
|
|
entityOverride.AddOverride(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entityOverride.RemoveOverride(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-12-26 20:07:19 +08:00
|
|
|
public void AIAnimationEvent(string actionName)
|
2023-10-20 19:31:12 +08:00
|
|
|
{
|
2023-12-26 20:07:19 +08:00
|
|
|
|
2023-10-20 19:31:12 +08:00
|
|
|
switch (actionName)
|
|
|
|
{
|
|
|
|
case "Melee":
|
2023-12-26 20:07:19 +08:00
|
|
|
Melee(damage);
|
2023-10-20 19:31:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void Melee(int _damage)
|
|
|
|
{
|
2023-12-26 20:07:19 +08:00
|
|
|
//if (entityOverride.IsOvering) return;
|
2023-11-15 23:54:54 +08:00
|
|
|
if (disableMelee.AllowUpdateWithoutReset is false) return;
|
2023-10-31 18:07:15 +08:00
|
|
|
var forward = Transform.forward;
|
2023-10-20 19:31:12 +08:00
|
|
|
meleeService.Melee(new MeleeCommand()
|
|
|
|
{
|
|
|
|
PlayerId = Entity.Id,
|
|
|
|
Position = Transform.position + Vector3.up,
|
2023-10-31 18:07:15 +08:00
|
|
|
Force = forward * 128,
|
2023-10-20 19:31:12 +08:00
|
|
|
Range = 1.6f,
|
|
|
|
Damage = _damage,
|
2023-11-15 23:54:54 +08:00
|
|
|
Forward = forward,
|
|
|
|
IgnoreTags = ignoreTags,
|
2023-10-20 19:31:12 +08:00
|
|
|
});
|
2023-10-24 23:37:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Execute() => Melee(damage);
|
|
|
|
public void HitStun()
|
|
|
|
{
|
2023-12-26 20:07:19 +08:00
|
|
|
UnityEntity.Invoke(Constant.Animation.Play,"HitStun");
|
|
|
|
//unityAnimator.Play("HitStun");
|
2023-10-20 19:31:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|