upd
This commit is contained in:
31
Code/Inventory/Usable/UseableBase.cs
Normal file
31
Code/Inventory/Usable/UseableBase.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Sandbox;
|
||||
|
||||
namespace Sasalka;
|
||||
|
||||
public abstract class UseableBase : Component, IUseable
|
||||
{
|
||||
[Property] public float Cooldown { get; set; } = 0.5f;
|
||||
|
||||
private TimeSince _timeSinceUsed;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
_timeSinceUsed = Cooldown;
|
||||
}
|
||||
|
||||
public virtual bool CanUse()
|
||||
{
|
||||
return _timeSinceUsed >= Cooldown && !Inventar.IsInventoryOpen;
|
||||
}
|
||||
|
||||
public virtual void Use()
|
||||
{
|
||||
if ( !CanUse() )
|
||||
return;
|
||||
|
||||
OnUse();
|
||||
_timeSinceUsed = 0;
|
||||
}
|
||||
|
||||
protected abstract void OnUse();
|
||||
}
|
||||
Reference in New Issue
Block a user