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 { [Header(Constant.Header.Settings)] [SerializeField] private bool debug; [SerializeField] private int damage = 50; [SerializeField] private Tag ignoreTags; [SerializeField] private bool allowAnimationEvent; [SerializeField] private bool allowAIAnimationEvent; [SerializeReference, SubclassSelector, Inject(true)] private IMeleeService meleeService; [Inject(true)] private IEntityOverride entityOverride; private readonly IntervalUpdate disableMelee = new(0.64f); public override void OnStart() { if (entityOverride is not null) { entityOverride.OnOverride += OnOverride; } } private void OnOverride(bool obj) { // disableMelee.Reset(); } public void AnimationEvent(string actionName) { if (debug) { BIT4Log.Log($"{name} AnimationEvent {actionName}"); } if (allowAnimationEvent) AnimationEventInternal(actionName); } public void AIAnimationEvent(string actionName) { if (debug) { BIT4Log.Log($"{name} AIAnimationEvent {actionName}"); } if (allowAIAnimationEvent) AnimationEventInternal(actionName); } private void AnimationEventInternal(string actionName) { switch (actionName) { case "Melee": Melee(damage); break; } } private void Melee(int _damage) { if (disableMelee.AllowUpdateWithoutReset is false) { if (debug) BIT4Log.Log("Melee is disabled"); return; } 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, IgnoreTags = ignoreTags.GetTags(), }); if (debug) BIT4Log.Log("Melee Command Queued"); } public void Execute() => Melee(damage); public void HitStun() { UnityEntity.Invoke(Constant.Animation.Play, nameof(HitStun)); } } }