54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using System.Linq;
|
|
using Code.Infrastructure.Utils;
|
|
using Code.OfficeGame.BattleMode.Actions.Deciders;
|
|
using Code.OfficeGame.BattleMode.Timeline;
|
|
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<BattleActionParameters> 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 void Tick(float tickDelta,
|
|
EntityProperties entity,
|
|
BattleActionDecisionResult battleActionDecisionResult,
|
|
BattleActionData battleActionData)
|
|
{
|
|
if (battleActionData is not StuggerActionData stuggerActionData)
|
|
{
|
|
battleActionData.Finished = true;
|
|
return;
|
|
}
|
|
|
|
if (stuggerActionData.CurrentFrame == 0)
|
|
{
|
|
var transitionTime = stuggerActionData.TransitionFrames * BattleTimeline.TickDelta;
|
|
entity.animator.ResetAnimatorPosition();
|
|
entity.animator.CrossFadeInFixedTime(StuggerStateHash, transitionTime);
|
|
}
|
|
|
|
stuggerActionData.CurrentFrame++;
|
|
|
|
if (stuggerActionData.CurrentFrame >= _actionParameters.TotalFrames)
|
|
{
|
|
battleActionData.Finished = true;
|
|
}
|
|
}
|
|
}
|
|
} |