diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index 67212bcb5b..3296a2f0ef 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -601,13 +601,8 @@ namespace Content.Shared.Interaction protected void InteractionActivate(EntityUid user, EntityUid used) { - if (TryComp(used, out UseDelayComponent? delayComponent)) - { - if (delayComponent.ActiveDelay) - return; - - delayComponent.BeginDelay(); - } + if (TryComp(used, out UseDelayComponent? delayComponent) && delayComponent.ActiveDelay) + return; if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user)) return; @@ -625,6 +620,7 @@ namespace Content.Shared.Interaction RaiseLocalEvent(used, activateMsg); if (activateMsg.Handled) { + delayComponent?.BeginDelay(); _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); return; } @@ -634,6 +630,7 @@ namespace Content.Shared.Interaction var activateEventArgs = new ActivateEventArgs(user, used); activateComp.Activate(activateEventArgs); + delayComponent?.BeginDelay(); _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); // No way to check success. } #endregion @@ -660,18 +657,16 @@ namespace Content.Shared.Interaction /// True if the interaction was handled. False otherwise public bool UseInteraction(EntityUid user, EntityUid used) { - if (TryComp(used, out UseDelayComponent? delayComponent)) - { - if (delayComponent.ActiveDelay) - return true; // if the item is on cooldown, we consider this handled. - - delayComponent.BeginDelay(); - } + if (TryComp(used, out UseDelayComponent? delayComponent) && delayComponent.ActiveDelay) + return true; // if the item is on cooldown, we consider this handled. var useMsg = new UseInHandEvent(user, used); RaiseLocalEvent(used, useMsg); if (useMsg.Handled) + { + delayComponent?.BeginDelay(); return true; + } var uses = AllComps(used).ToList(); @@ -680,7 +675,10 @@ namespace Content.Shared.Interaction { // If a Use returns a status completion we finish our interaction if (use.UseEntity(new UseEntityEventArgs(user))) + { + delayComponent?.BeginDelay(); return true; + } } return false; diff --git a/Content.Shared/Timing/UseDelayComponent.cs b/Content.Shared/Timing/UseDelayComponent.cs index f0d7c03d5a..87ad332fb8 100644 --- a/Content.Shared/Timing/UseDelayComponent.cs +++ b/Content.Shared/Timing/UseDelayComponent.cs @@ -46,12 +46,9 @@ namespace Content.Shared.Timing _lastUseTime = IoCManager.Resolve().CurTime; - if (IoCManager.Resolve().TryGetComponent(Owner, out ItemCooldownComponent? cooldown)) - { - cooldown.CooldownStart = _lastUseTime; - cooldown.CooldownEnd = _lastUseTime + TimeSpan.FromSeconds(Delay); - } - + var cooldown = IoCManager.Resolve().EnsureComponent(Owner); + cooldown.CooldownStart = _lastUseTime; + cooldown.CooldownEnd = _lastUseTime + TimeSpan.FromSeconds(Delay); } public void Cancel()