mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
72 lines
No EOL
1.7 KiB
C#
72 lines
No EOL
1.7 KiB
C#
using Cirno.Scripts.Components.FSM._3DPlayer;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
public partial class AreaTrigger3D : Area3D
|
|
{
|
|
[Export] public Node3D Target { get; set; }
|
|
|
|
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
|
|
|
|
[Export] public bool OneTime { get; set; }
|
|
[Export] public bool DoNotActivateOnFirst { get; set; }
|
|
|
|
private int _activations = 0;
|
|
|
|
[Signal]
|
|
public delegate void ActivatedEventHandler();
|
|
|
|
private IsoInteractionController _cachedPlayer;
|
|
|
|
private bool Activate()
|
|
{
|
|
if (_activations == 0 && DoNotActivateOnFirst)
|
|
{
|
|
_activations++;
|
|
return false;
|
|
}
|
|
|
|
if (OneTime && _activations > 0) return false;
|
|
|
|
if (Target != null)
|
|
{
|
|
if (Target is not IActivable target)
|
|
{
|
|
GD.PrintErr($"Target {Target.Name} is not activable");
|
|
return false;
|
|
}
|
|
target.Activate(ActivationType);
|
|
}
|
|
|
|
EmitSignal(nameof(Activated));
|
|
|
|
_activations++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private void _on_area_entered(Area3D area)
|
|
{
|
|
if (area is not IsoInteractionController player) return;
|
|
if (player.Enabled)
|
|
{
|
|
Activate();
|
|
}
|
|
else
|
|
{
|
|
_cachedPlayer = player;
|
|
_cachedPlayer.InteractionStarted += PlayerOnInteractionStarted;
|
|
}
|
|
}
|
|
|
|
private void PlayerOnInteractionStarted()
|
|
{
|
|
Activate();
|
|
if (_cachedPlayer != null)
|
|
{
|
|
_cachedPlayer.InteractionStarted -= PlayerOnInteractionStarted;
|
|
}
|
|
}
|
|
} |