2025-07-22 14:08:22 +00:00
|
|
|
|
|
|
|
|
using Godot;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
|
{
|
|
|
|
|
[Tool]
|
|
|
|
|
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/ConditionalAction.svg")]
|
|
|
|
|
public partial class CoolDown : Action
|
|
|
|
|
{
|
|
|
|
|
[Export]
|
|
|
|
|
public Action action;
|
|
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
|
public Duration coolDownDuration;
|
|
|
|
|
|
|
|
|
|
bool _isCoolingDown = false;
|
2025-10-24 11:38:51 +00:00
|
|
|
int _coolDownID = -1;
|
|
|
|
|
|
|
|
|
|
public void ResetCoolDown()
|
|
|
|
|
{
|
|
|
|
|
if ( _coolDownID == -1 )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isCoolingDown = false;
|
|
|
|
|
_coolDownID = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 14:08:22 +00:00
|
|
|
protected override void _OnTrigger()
|
|
|
|
|
{
|
|
|
|
|
if ( _isCoolingDown )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isCoolingDown = coolDownDuration != null;
|
|
|
|
|
Trigger( action );
|
|
|
|
|
|
|
|
|
|
if ( coolDownDuration != null )
|
|
|
|
|
{
|
2025-10-24 11:38:51 +00:00
|
|
|
var te = TimeLineManager.ScheduleEventIn(
|
2025-07-22 14:08:22 +00:00
|
|
|
coolDownDuration.timeLine, coolDownDuration.GetDurationInSeconds(),
|
2025-10-24 11:38:51 +00:00
|
|
|
ev =>
|
|
|
|
|
{
|
|
|
|
|
if ( _coolDownID != ev.id )
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isCoolingDown = false;
|
|
|
|
|
}
|
2025-07-22 14:08:22 +00:00
|
|
|
);
|
2025-10-24 11:38:51 +00:00
|
|
|
|
|
|
|
|
_coolDownID = te.id;
|
|
|
|
|
|
2025-07-22 14:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|