74 lines
1.5 KiB
C#
74 lines
1.5 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
public partial class Contact : Sprite2D
|
|
{
|
|
public bool _clickable, _interval;
|
|
public int _number, _calls = 0, _maxCalls = 0;
|
|
public Timer _timer, _cooldown;
|
|
public Action _action;
|
|
public Actor _owner;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_timer = GetNode<Timer>("Timer");
|
|
_cooldown = GetNode<Timer>("Cooldown");
|
|
_action = GetNode<Action>("Action");
|
|
}
|
|
|
|
public virtual void CallAction()
|
|
{
|
|
if (_cooldown.TimeLeft > 0 || _action._cooldownSeconds == 0)
|
|
{
|
|
GD.Print("Action fired!!");
|
|
_action.Fire();
|
|
}
|
|
}
|
|
|
|
public void PassNumber(int NUMBER)
|
|
{
|
|
_number = NUMBER;
|
|
}
|
|
public void PassOwner(Actor OWNER)
|
|
{
|
|
_owner = OWNER;
|
|
_action._owner = OWNER;
|
|
}
|
|
|
|
public void SetTimer(float SECONDS)
|
|
{
|
|
_action._timerSeconds = SECONDS;
|
|
}
|
|
|
|
public void SetCooldown(int SECONDS)
|
|
{
|
|
_action._cooldownSeconds = SECONDS;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
// GD.Print(_action._timerSeconds);
|
|
if (_action._timerSeconds > 0)
|
|
{
|
|
_timer.Start(_action._timerSeconds);
|
|
_calls = 0;
|
|
}
|
|
}
|
|
|
|
private void OnTimerTimeout()
|
|
{
|
|
if (_calls <= _maxCalls || _maxCalls == 0)
|
|
{
|
|
CallAction();
|
|
_timer.Start(_action._timerSeconds);
|
|
_calls++;
|
|
}
|
|
}
|
|
|
|
private void OnCooldownTimeout()
|
|
{
|
|
|
|
}
|
|
}
|