Add cooldown to window knocking (#3224)
This commit is contained in:
@@ -11,8 +11,12 @@ using Content.Server.GameObjects.Components.Destructible.Thresholds.Triggers;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components
|
||||
{
|
||||
@@ -20,6 +24,22 @@ namespace Content.Server.GameObjects.Components
|
||||
[ComponentReference(typeof(SharedWindowComponent))]
|
||||
public class WindowComponent : SharedWindowComponent, IExamine, IInteractHand
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _lastKnockTime;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private TimeSpan _knockDelay;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _rateLimitedKnocking;
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(ref _knockDelay, "knockDelay", TimeSpan.FromSeconds(0.5));
|
||||
serializer.DataField(ref _rateLimitedKnocking, "rateLimitedKnocking", true);
|
||||
}
|
||||
|
||||
public override void HandleMessage(ComponentMessage message, IComponent? component)
|
||||
{
|
||||
base.HandleMessage(message, component);
|
||||
@@ -108,9 +128,17 @@ namespace Content.Server.GameObjects.Components
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
if (_rateLimitedKnocking && _gameTiming.CurTime < _lastKnockTime + _knockDelay)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.PlayAtCoords("/Audio/Effects/glass_knock.ogg", eventArgs.Target.Transform.Coordinates, AudioHelpers.WithVariation(0.05f));
|
||||
eventArgs.Target.PopupMessageEveryone(Loc.GetString("*knock knock*"));
|
||||
|
||||
_lastKnockTime = _gameTiming.CurTime;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user