78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using System.Linq;
|
|
using Code.Infrastructure.Utils;
|
|
using Code.OfficeGame.BattleMode.HitBoxes;
|
|
using Cysharp.Threading.Tasks;
|
|
using Reflex.Attributes;
|
|
using UnityEngine;
|
|
|
|
namespace Code.OfficeGame.BattleMode.Actions.Attacks
|
|
{
|
|
public class BattleActionPlayerAttackMMA : BattleAction
|
|
{
|
|
private Animator _animator;
|
|
private EntityHitBoxes _entityHitBoxes;
|
|
private AttackActionConfig _attackData;
|
|
public int EntryStateHash => Animator.StringToHash("WalkBlend");
|
|
|
|
private int _currentFrame;
|
|
|
|
[Inject]
|
|
public void Construct(MultipleConfig<BattleActionParameters> attackData)
|
|
{
|
|
_animator = GetComponentInChildren<Animator>();
|
|
_entityHitBoxes = GetComponent<EntityHitBoxes>();
|
|
_attackData = (AttackActionConfig) attackData.Configs.SingleOrDefault(x=>x.ActionType == ActionType);
|
|
}
|
|
|
|
public override async UniTask<BattleActionDecisionResult> DecideAction()
|
|
{
|
|
_currentFrame = 0;
|
|
Finished = false;
|
|
|
|
return new() { ResultCode = BattleActionDecisionResultCode.Decided, FrameDuration = _attackData.TotalFrames};
|
|
}
|
|
|
|
public override BattleActionType ActionType => BattleActionType.PlayerAttackMMA;
|
|
|
|
public override void Tick(float tickDelta)
|
|
{
|
|
if (Finished) return;
|
|
|
|
if (_currentFrame == 0)
|
|
{
|
|
_animator.Play(_attackData.StateHash, 0, 0f);
|
|
}
|
|
|
|
_currentFrame++;
|
|
|
|
if (_currentFrame >= _attackData.HitboxStartFrame && _currentFrame <= _attackData.HitboxEndFrame)
|
|
{
|
|
_entityHitBoxes.EnableHitbox(_attackData.AttackingBodyPart);
|
|
_entityHitBoxes.CheckHitsForCurrentFrame(OnEnemyHit);
|
|
}
|
|
else
|
|
{
|
|
_entityHitBoxes.DisableAllHitboxes();
|
|
}
|
|
|
|
if (_currentFrame >= _attackData.TotalFrames)
|
|
{
|
|
CompleteOrInterruptAction();
|
|
}
|
|
}
|
|
|
|
private void OnEnemyHit(Collider enemyCollider)
|
|
{
|
|
Debug.Log($"Попадание в {enemyCollider.name} на {_currentFrame}-м кадре! Урон: {_attackData.Damage}");
|
|
var entityActor = enemyCollider.GetComponentInParent<EntityTimelineActor>();
|
|
entityActor.ForceDecideAction(BattleActionType.Stugger);
|
|
}
|
|
|
|
public void CompleteOrInterruptAction()
|
|
{
|
|
_animator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда
|
|
_entityHitBoxes.DisableAllHitboxes();
|
|
Finished = true;
|
|
}
|
|
}
|
|
} |