cirnogodot/Scripts/Activables/HealthStation.cs

145 lines
3.6 KiB
C#
Raw Permalink Normal View History

2025-02-19 23:40:31 +01:00
using System;
using System.Collections;
using System.Threading.Tasks;
2025-03-05 09:44:03 +01:00
using Cirno.Scripts.Components.FSM;
2025-02-19 23:40:31 +01:00
using Godot;
namespace Cirno.Scripts.Activables;
public partial class HealthStation : Activable
{
[Export]
public bool IsEnabled { get; set; }
[Export]
public float HealthPerSecond { get; private set; } = 10f;
[Export]
public float ShieldPerSecond { get; private set; } = 10f;
private AnimatedSprite2D _animatedSprite;
private GpuParticles2D _particles;
private bool _isHealing = false;
2025-03-05 09:44:03 +01:00
private InteractionController _cachedPlayer;
2025-02-19 23:40:31 +01:00
private double _healingTimer = 0;
public override void _Ready()
{
_particles = GetNode<GpuParticles2D>("./Particles");
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
_particles.Emitting = false;
if (IsEnabled)
{
_animatedSprite.Play("Active");
}
else
{
_animatedSprite.Play("Default");
}
_healingTimer = 0;
}
public override void _Process(double delta)
{
base._Process(delta);
2025-03-05 09:44:03 +01:00
if (!_isHealing || _cachedPlayer == null) return;
_healingTimer += delta;
2025-02-19 23:40:31 +01:00
2025-03-05 09:44:03 +01:00
if (!(_healingTimer >= 1)) return;
if (_cachedPlayer.Health is not null)
{
_cachedPlayer.Health.CurrentResource += HealthPerSecond;
}
if (_cachedPlayer.Shield is not null)
{
_cachedPlayer.Shield.CurrentResource += ShieldPerSecond;
2025-02-19 23:40:31 +01:00
}
2025-03-05 09:44:03 +01:00
_healingTimer = 0;
2025-02-19 23:40:31 +01:00
}
2025-03-09 21:58:25 +01:00
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
2025-02-19 23:40:31 +01:00
{
switch (activationType)
{
case ActivationType.Toggle:
// Enables/Disables teleporter
break;
case ActivationType.Enable:
// Enables Teleporter
IsEnabled = true;
_animatedSprite.Play("Active");
break;
case ActivationType.Disable:
IsEnabled = false;
_animatedSprite.Play("Default");
// Disables Teleporter
break;
case ActivationType.Use:
// Teleports
break;
case ActivationType.Destroy:
// Destroys
break;
}
2025-03-09 21:58:25 +01:00
return true;
2025-02-19 23:40:31 +01:00
}
2025-03-05 09:44:03 +01:00
private void _on_area_entered(Area2D area)
2025-02-19 23:40:31 +01:00
{
if (!IsEnabled) return;
2025-03-05 09:44:03 +01:00
if (area is not InteractionController interactionController) return;
2025-02-19 23:40:31 +01:00
2025-03-05 09:44:03 +01:00
_cachedPlayer = interactionController;
2025-02-19 23:40:31 +01:00
_isHealing = true;
_particles.Emitting = true;
}
2025-03-05 09:44:03 +01:00
private void _on_area_Exited(Area2D area)
2025-02-19 23:40:31 +01:00
{
if (!_isHealing) return;
if (!IsEnabled) return;
2025-03-05 09:44:03 +01:00
if (area is not InteractionController player) return;
2025-02-19 23:40:31 +01:00
// Stop healing player if active
_isHealing = false;
_particles.Emitting = false;
}
2025-03-05 09:44:03 +01:00
// private void _on_body_entered(CharacterBody2D area)
// {
// // Heal player if active
// if (!IsEnabled) return;
// if (area is not PlayerStateMachine player) return;
//
// _cachedPlayer = player;
//
// _isHealing = true;
// _particles.Emitting = true;
// }
//
// private void _on_body_exited(CharacterBody2D area)
// {
// if (!_isHealing) return;
// if (!IsEnabled) return;
// if (area is not PlayerStateMachine player) return;
//
// // Stop healing player if active
//
// _isHealing = false;
// _particles.Emitting = false;
// }
2025-02-19 23:40:31 +01:00
}