mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-16 13:23:48 +00:00
Min max triggers
This commit is contained in:
parent
9c3a7d6247
commit
0492a008d0
6 changed files with 130 additions and 45 deletions
|
|
@ -12,12 +12,16 @@ public partial class TriggerArea : Area3D
|
|||
[Export] public string TargetFunc { get; private set; }
|
||||
[Export] public string TargetName { get; private set; }
|
||||
|
||||
[Export] public int MinActivations { get; private set; } = 0;
|
||||
[Export] public int MaxActivations { get; private set; } = 1;
|
||||
|
||||
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
|
||||
|
||||
public enum TriggerStates
|
||||
{
|
||||
READY,
|
||||
USED
|
||||
USED,
|
||||
WAITING
|
||||
}
|
||||
|
||||
private TriggerStates _triggerState = TriggerStates.READY;
|
||||
|
|
@ -25,6 +29,8 @@ public partial class TriggerArea : Area3D
|
|||
private float _timeout = 0f;
|
||||
private Node _lastActivator;
|
||||
|
||||
private int _activations = 0;
|
||||
|
||||
public void _func_godot_apply_properties(Dictionary<string, string> props)
|
||||
{
|
||||
Target = props["target"];
|
||||
|
|
@ -38,45 +44,77 @@ public partial class TriggerArea : Area3D
|
|||
ActivationType = activationType;
|
||||
}
|
||||
}
|
||||
// TODO: Oneshot
|
||||
|
||||
if (int.TryParse(props["minactivations"], out var minActivations))
|
||||
{
|
||||
MinActivations = minActivations;
|
||||
}
|
||||
|
||||
if (int.TryParse(props["maxactivations"], out var maxActivations))
|
||||
{
|
||||
MaxActivations = maxActivations;
|
||||
}
|
||||
}
|
||||
|
||||
public void _on_ent_entered(Node ent)
|
||||
{
|
||||
GD.Print($"Trigger entered by {ent.Name}");
|
||||
if (_triggerState is TriggerStates.READY)
|
||||
//GD.Print($"Trigger entered by {ent.Name}");
|
||||
switch (_triggerState)
|
||||
{
|
||||
if (ent is IsoPlayerFSMProxy)
|
||||
{
|
||||
GD.Print($"Entity {ent} is player, trying to use");
|
||||
Use();
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"{ent.Name} was not interaction controller");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print("Trigger was not ready");
|
||||
case TriggerStates.READY:
|
||||
if (ent is IsoPlayerFSMProxy)
|
||||
{
|
||||
if (_activations >= MinActivations && _activations < MaxActivations )
|
||||
{
|
||||
Use();
|
||||
}
|
||||
else
|
||||
{
|
||||
_activations++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TriggerStates.USED:
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
// if (_triggerState is TriggerStates.READY)
|
||||
// {
|
||||
// if (ent is IsoPlayerFSMProxy)
|
||||
// {
|
||||
// //GD.Print($"Entity {ent} is player, trying to use");
|
||||
// Use();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //GD.Print($"{ent.Name} was not interaction controller");
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //GD.Print("Trigger was not ready");
|
||||
// }
|
||||
}
|
||||
|
||||
public void Use()
|
||||
{
|
||||
if (_triggerState is TriggerStates.READY)
|
||||
if (_triggerState is not TriggerStates.READY) return;
|
||||
|
||||
ActivationHelper.UseTargets(this, Target, ActivationType);
|
||||
|
||||
_activations++;
|
||||
|
||||
if (_activations >= MaxActivations)
|
||||
{
|
||||
_triggerState = TriggerStates.USED;
|
||||
ToggleCollision(false);
|
||||
|
||||
ActivationHelper.UseTargets(this, Target, ActivationType);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleCollision(bool toggle)
|
||||
{
|
||||
|
||||
Monitoring = toggle;
|
||||
}
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue