using System.Linq; using Code.Infrastructure.Utils; using Code.OfficeGame.BattleMode.Actions.Deciders; using Reflex.Attributes; using UnityEngine; namespace Code.OfficeGame.BattleMode.Actions { public class BattleActionStugger : BattleAction { private int EntryStateHash => Animator.StringToHash("WalkBlend"); private int StuggerStateHash => Animator.StringToHash("Stugger"); private BattleActionParameters _actionParameters; public BattleActionStugger(MultipleConfig actionData) { _actionParameters = actionData.Configs.SingleOrDefault(x => x.ActionType == ActionType); } public override BattleActionType ActionType => BattleActionType.Stugger; public override DeciderType DeciderType => DeciderType.AsIs; public override BattleActionData MountAndGetFrames(EntityProperties entity, BattleActionDecisionResult result) { return new StuggerActionData { TotalFrames = _actionParameters.TotalFrames}; } public override bool Tick(float tickDelta, EntityProperties entity, BattleActionDecisionResult battleActionDecisionResult, BattleActionData battleActionData) { if (battleActionData is not StuggerActionData stuggerActionData) return true; if (stuggerActionData.CurrentFrame == 0) { entity.animator.Play(StuggerStateHash, 0, 0f); } stuggerActionData.CurrentFrame++; if (stuggerActionData.CurrentFrame >= _actionParameters.TotalFrames) { entity.animator.Play(EntryStateHash, 0, 0f); return true; } return false; } } }