using Cirno.Scripts.Components.Actors; using Cirno.Scripts.Components.Actors._3D; using Cirno.Scripts.Controllers; using Godot; namespace Cirno.Scripts.Components.FSM._3DPlayer; public partial class Dead : BaseState { public override PlayerState StateId => PlayerState.Dead; private ActorResourceProvider _motivationProvider; private InputProvider _inputProvider; private ActorResourceProvider _healthProvider; private PlayerAnimationProvider3D _animationProvider; private bool _isGameOver; public override void Init(IStateMachine machine) { base.Init(machine); // try to obtain common providers via modules/storage if (machine is IsoPlayerStateMachine sm) { var storage = sm.Storage; // store references if present on storage _motivationProvider = storage.Root.GetNodeOrNull("MotivationProvider"); _healthProvider = storage.Root.GetNodeOrNull("HealthProvider"); } // fallback to searching on the actor _motivationProvider ??= StateMachine.GetModule(); _healthProvider ??= StateMachine.GetModule(); _animationProvider ??= StateMachine.GetModule(); } public override void EnterState() { base.EnterState(); //MainObject.Hide(); _animationProvider.PlayDeathAnimation(); if (_motivationProvider.CurrentResource < 100f) { // If motivation is not enough show game over scene Hud.Instance.ShowGameOver(); _isGameOver = true; } else { // Else show respawn notification Hud.Instance.ShowTerminated(); _isGameOver = false; } } public override void ExitState() { base.ExitState(); Hud.Instance.HideTerminated(); } public override void ProcessState(double delta) { base.ProcessState(delta); if (_inputProvider.GetShootJustPressed()) { if (_isGameOver) { // Restart Level GlobalState.Instance.RestartLevel(); } else { Respawn(); } } } public void Respawn() { MainObject.GlobalPosition = GameController.Instance.LastCheckPointPosition; _healthProvider.FillResource(); PoolingManager.Instance.ClearBullets(); _motivationProvider.CurrentResource -= 100f; if (_motivationProvider.CurrentResource <= 1f) { _motivationProvider.CurrentResource = 1f; } ChangeState(PlayerState.Active); } }