cirnogodot/Scripts/Components/FSM/3DPlayer/Active.cs
2025-06-10 16:33:43 +02:00

165 lines
No EOL
4.4 KiB
C#

using Godot;
namespace Cirno.Scripts.Components.FSM._3DPlayer;
public partial class Active : BaseState<PlayerState, CharacterBody3D>
{
public override PlayerState StateId => PlayerState.Active;
private CharacterBody3D _player;
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
{
base.Init(machine);
//_hud = Hud.Instance;
//_damageReceiver.Death += () => { ChangeState(PlayerState.Dead); };
// _damageReceiver.HealthDecreased += (value, newValue, maxValue) =>
// {
// _animationProvider.Blink();
// };
// _damageReceiver.ShieldDecreased += (value, newValue, maxValue) =>
// {
// _animationProvider.PlayShieldAnimation();
//
// };
//_damageReceiver.Init(StateMachine);
//_damageReceiver.RefillHealth();
//_damageReceiver.RefillShield();
//_activationProvider.Init(MainObject);
//_weaponProvider.Init(MainObject);
}
public override void EnterState()
{
base.EnterState();
// enable sprite
// enable crosshair
//_crosshairProvider.Show();
//_animationProvider.ShowSprite();
//_damageReceiver.Enabled = true;
//_activationProvider.Enabled = true;
//_interactionController.Enabled = true;
}
public override void ExitState()
{
base.ExitState();
// _animationProvider.SetAnimationSpeed(Vector2.Zero);
// //_animationProvider.SetAnimation(Vector2.Zero);
// _crosshairProvider.Hide();
// _hitboxSpriteProvider.Hide();
//
// _damageReceiver.Enabled = false;
// _activationProvider.Enabled = false;
// _interactionController.Enabled = false;
}
public override void PhysicsProcessState(double delta)
{
// Reset at start of frame
//MainObject.Velocity = Vector2.Zero;
// Process modules
base.PhysicsProcessState(delta);
}
public override void ProcessState(double delta)
{
base.ProcessState(delta);
_movementDirection = _inputProvider.GetMovementInput().Normalized();
_isStrafing = _inputProvider.GetStrafePressed();
// Toggle visibility of the hitbox sprite based on strafing
_hitboxSpriteProvider.SetVisibility(_isStrafing);
var rightStickInput = _inputProvider.GetAimInput().Normalized();
// Update Facing Direction
// if (!_isStrafing)
// {
if (rightStickInput.Length() > 0.1f) // If the right stick is moved
{
FacingDirection = rightStickInput;
}
else if (_movementDirection != Vector2.Zero) // Fall back to movement direction
{
FacingDirection = _movementDirection;
}
// }
_animationProvider.SetAnimationSpeed(MainObject.Velocity);
_animationProvider.SetAnimation(FacingDirection);
HandleWeaponSwitch();
_weaponProvider.Update(delta);
//_crosshairProvider.UpdatePosition(FacingDirection);
HandleShoot();
HandleInteraction();
// FindInteractable();
// _crosshair.Position = CalculateCrosshairPosition();
if (_inputProvider.GetInventoryJustPressed())
{
GameManager.Instance.ChangeState(GameState.Inventory);
}
if (_inputProvider.GetPauseJustPressed())
{
//CallDeferred(MethodName.PauseDeferred);
PauseDeferred();
}
}
private void PauseDeferred()
{
GameManager.Instance.Pause();
}
// private void HandleShoot()
// {
// if (_inputProvider.GetReloadJustPressed())
// {
// _weaponProvider.Reload();
// return;
// }
//
// if (!_inputProvider.GetShootPressed()) return;
// _weaponProvider.Shoot(this.FacingDirection);
// }
//
// private void HandleInteraction()
// {
// _activationProvider.HandleInteraction();
// }
//
// private void HandleWeaponSwitch()
// {
// if (_inputProvider.GetWeaponNextJustPressed())
// {
// _weaponProvider.NextWeapon();
// }
// else if (_inputProvider.GetWeaponPreviousJustPressed())
// {
// _weaponProvider.PreviousWeapon();
// }
// }
}