74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Xml;
|
|
using BITFALL.Combat;
|
|
using BITKit.Animations;
|
|
using BITKit.Entities.Melee;
|
|
using Unity.Mathematics;
|
|
using UnityEngine;
|
|
namespace BITKit.Entities
|
|
{
|
|
[CustomType(typeof(IMeleeCombat))]
|
|
public class EntityMelee : EntityBehavior,IMeleeCombat
|
|
{
|
|
[SerializeField] private UnityAnimator unityAnimator;
|
|
|
|
[Header(Constant.Header.Settings)]
|
|
[SerializeField] private int damage=50;
|
|
|
|
|
|
[SerializeReference, SubclassSelector, Inject(true)] private IMeleeService meleeService;
|
|
[Inject(true)] private IEntityOverride entityOverride;
|
|
public override void OnStart()
|
|
{
|
|
UnityEntity.AddListener<int>("Melee", Melee);
|
|
UnityEntity.AddListener<string>(AIAction);
|
|
|
|
unityAnimator[0].onStateEnter += OnStateEnter;
|
|
}
|
|
|
|
private void OnStateEnter(string obj)
|
|
{
|
|
if(entityOverride is null)return;
|
|
if (obj is "HitStun")
|
|
{
|
|
entityOverride.AddOverride(this);
|
|
}
|
|
else
|
|
{
|
|
entityOverride.RemoveOverride(this);
|
|
}
|
|
|
|
}
|
|
|
|
private void AIAction(string actionName)
|
|
{
|
|
switch (actionName)
|
|
{
|
|
case "Melee":
|
|
break;
|
|
}
|
|
}
|
|
private void Melee(int _damage)
|
|
{
|
|
var forward = Transform.forward;
|
|
meleeService.Melee(new MeleeCommand()
|
|
{
|
|
PlayerId = Entity.Id,
|
|
Position = Transform.position + Vector3.up,
|
|
Force = forward * 128,
|
|
Range = 1.6f,
|
|
Damage = _damage,
|
|
Forward = forward
|
|
});
|
|
unityAnimator.Play("Attack");
|
|
//entity.Invoke(Constant.Animation.Play, "Melee");
|
|
}
|
|
|
|
public void Execute() => Melee(damage);
|
|
public void HitStun()
|
|
{
|
|
unityAnimator.Play("HitStun");
|
|
}
|
|
}
|
|
} |