94 lines
3.1 KiB
C#
94 lines
3.1 KiB
C#
using Intrepid.Structures;
|
|
using Intrepid.Utilities;
|
|
using UnityEngine;
|
|
|
|
namespace Intrepid.Gameplay.Entities.Sentinel.StateMachine.States
|
|
{
|
|
public class SentinelStateKnockdown : SentinelState
|
|
{
|
|
[GroupConfigurations, SerializeField] private AnimationClip knockdown;
|
|
[GroupConfigurations, SerializeField] private AnimationClip knockout;
|
|
[GroupConfigurations, SerializeField] private float KnockoutTimeMultiplier = 0.1f;
|
|
[GroupConfigurations, SerializeField, Range(0, 3)] private float knockdownTime = 2.0f;
|
|
[GroupConfigurations, SerializeField, Range(0, 3)] private float recoverTime = 1.5f;
|
|
|
|
private Vector2 KnockdownForce { get; set; }
|
|
private float KnockoutTime { get; set; }
|
|
private Timer KnockdownTimer { get; } = new();
|
|
private Timer KnockoutTimer { get; } = new();
|
|
private Timer RecoverTimer { get; } = new();
|
|
|
|
public override SentinelStateType GetStateKey()
|
|
{
|
|
return SentinelStateType.Knockdown;
|
|
}
|
|
|
|
protected override void Subscriptions()
|
|
{
|
|
}
|
|
|
|
protected override void RunOnEnter(ParameterStore ps)
|
|
{
|
|
Brain.Entity.ModelAnimation.CrossFade(knockdown, 0.1f);
|
|
KnockdownForce = ps.Get<Vector2>(SentinelConstants.Parameters.KnockdownForce);
|
|
Brain.Entity.ChangeOrientation(-KnockdownForce.normalized);
|
|
KnockoutTime = KnockdownForce.sqrMagnitude * KnockoutTimeMultiplier;
|
|
Brain.Entity.DesiredVelocity = KnockdownForce;
|
|
KnockdownTimer.Start();
|
|
KnockoutTimer.Stop();
|
|
RecoverTimer.Stop();
|
|
}
|
|
|
|
protected override void RunOnExit()
|
|
{
|
|
}
|
|
|
|
public override void RunOnUpdate()
|
|
{
|
|
if (RecoverTimer.IsRunning)
|
|
{
|
|
RecoverTimer.Update(Timer.ScaledTime);
|
|
if (RecoverTimer.Check(recoverTime))
|
|
{
|
|
RecoverTimer.Stop();
|
|
Brain.ChangeState(SentinelStateType.Idle);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (KnockoutTimer.IsRunning)
|
|
{
|
|
KnockoutTimer.Update(Timer.ScaledTime);
|
|
if (KnockoutTimer.Check(recoverTime))
|
|
{
|
|
KnockoutTimer.Stop();
|
|
RecoverTimer.Start();
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
if (KnockdownTimer.IsNotRunning)
|
|
{
|
|
if (Brain.Entity.ModelAnimation.IsPlaying(knockout))
|
|
{
|
|
if (Brain.Entity.ModelAnimation.IsFinished)
|
|
{
|
|
KnockoutTimer.Start();
|
|
Brain.Entity.DesiredVelocity = Vector2.zero;
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
KnockdownTimer.Update(Timer.ScaledTime);
|
|
if (KnockdownTimer.Check(knockdownTime))
|
|
{
|
|
KnockdownTimer.Stop();
|
|
Brain.Entity.ModelAnimation.CrossFade(knockout, 0.1f);
|
|
}
|
|
}
|
|
}
|
|
} |