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 { public class BattleActionStugger : BattleAction { private Animator _animator; private EntityHitBoxes _entityHitBoxes; private int EntryStateHash => Animator.StringToHash("WalkBlend"); private int StuggerStateHash => Animator.StringToHash("Stugger"); private BattleActionParameters _actionParameters; private int _currentFrame; [Inject] public void Construct(MultipleConfig actionData) { _animator = GetComponentInChildren(); _entityHitBoxes = GetComponent(); _actionParameters = actionData.Configs.SingleOrDefault(x => x.ActionType == ActionType); } public override async UniTask DecideAction() { _currentFrame = 0; Finished = false; return new() { ResultCode = BattleActionDecisionResultCode.Decided, FrameDuration = _actionParameters.TotalFrames}; } public override BattleActionType ActionType => BattleActionType.Stugger; public override void Tick(float tickDelta) { if (Finished) return; if (_currentFrame == 0) { _animator.Play(StuggerStateHash, 0, 0f); } _currentFrame++; if (_currentFrame >= _actionParameters.TotalFrames) { CompleteOrInterruptAction(); } } public void CompleteOrInterruptAction() { _animator.Play(EntryStateHash, 0, 0f); // Создать None State и кинуть эту штуку туда Finished = true; } } }