mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Fixed healing stations
This commit is contained in:
parent
d4b420052e
commit
f1ddee18c4
9 changed files with 84 additions and 30 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
|
@ -22,7 +23,7 @@ public partial class HealthStation : Activable
|
|||
|
||||
private bool _isHealing = false;
|
||||
|
||||
private PlayerMovement _cachedPlayer;
|
||||
private InteractionController _cachedPlayer;
|
||||
|
||||
private double _healingTimer = 0;
|
||||
|
||||
|
|
@ -49,18 +50,20 @@ public partial class HealthStation : Activable
|
|||
{
|
||||
base._Process(delta);
|
||||
|
||||
if (_isHealing && _cachedPlayer != null)
|
||||
if (!_isHealing || _cachedPlayer == null) return;
|
||||
_healingTimer += delta;
|
||||
|
||||
if (!(_healingTimer >= 1)) return;
|
||||
if (_cachedPlayer.Health is not null)
|
||||
{
|
||||
_healingTimer += delta;
|
||||
|
||||
if (_healingTimer >= 1)
|
||||
{
|
||||
_cachedPlayer.CurrentHealth += HealthPerSecond;
|
||||
_cachedPlayer.CurrentShield += ShieldPerSecond;
|
||||
|
||||
_healingTimer = 0;
|
||||
}
|
||||
_cachedPlayer.Health.CurrentResource += HealthPerSecond;
|
||||
}
|
||||
if (_cachedPlayer.Shield is not null)
|
||||
{
|
||||
_cachedPlayer.Shield.CurrentResource += ShieldPerSecond;
|
||||
}
|
||||
|
||||
_healingTimer = 0;
|
||||
}
|
||||
|
||||
public override void Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
|
|
@ -89,23 +92,22 @@ public partial class HealthStation : Activable
|
|||
}
|
||||
}
|
||||
|
||||
private void _on_body_entered(CharacterBody2D area)
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
// Heal player if active
|
||||
if (!IsEnabled) return;
|
||||
if (area is not PlayerMovement player) return;
|
||||
|
||||
_cachedPlayer = player;
|
||||
if (area is not InteractionController interactionController) return;
|
||||
|
||||
_cachedPlayer = interactionController;
|
||||
|
||||
_isHealing = true;
|
||||
_particles.Emitting = true;
|
||||
}
|
||||
|
||||
private void _on_body_exited(CharacterBody2D area)
|
||||
private void _on_area_Exited(Area2D area)
|
||||
{
|
||||
if (!_isHealing) return;
|
||||
if (!IsEnabled) return;
|
||||
if (area is not PlayerMovement player) return;
|
||||
if (area is not InteractionController player) return;
|
||||
|
||||
// Stop healing player if active
|
||||
|
||||
|
|
@ -113,5 +115,29 @@ public partial class HealthStation : Activable
|
|||
_particles.Emitting = false;
|
||||
}
|
||||
|
||||
// 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;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue