Fix use delay (#6031)

This commit is contained in:
Leon Friedrich
2022-01-06 14:51:34 +13:00
committed by GitHub
parent 5b1cd2dd96
commit d6f0e71cba
2 changed files with 15 additions and 20 deletions

View File

@@ -601,14 +601,9 @@ namespace Content.Shared.Interaction
protected void InteractionActivate(EntityUid user, EntityUid used) protected void InteractionActivate(EntityUid user, EntityUid used)
{ {
if (TryComp(used, out UseDelayComponent? delayComponent)) if (TryComp(used, out UseDelayComponent? delayComponent) && delayComponent.ActiveDelay)
{
if (delayComponent.ActiveDelay)
return; return;
delayComponent.BeginDelay();
}
if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user)) if (!_actionBlockerSystem.CanInteract(user) || !_actionBlockerSystem.CanUse(user))
return; return;
@@ -625,6 +620,7 @@ namespace Content.Shared.Interaction
RaiseLocalEvent(used, activateMsg); RaiseLocalEvent(used, activateMsg);
if (activateMsg.Handled) if (activateMsg.Handled)
{ {
delayComponent?.BeginDelay();
_adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}");
return; return;
} }
@@ -634,6 +630,7 @@ namespace Content.Shared.Interaction
var activateEventArgs = new ActivateEventArgs(user, used); var activateEventArgs = new ActivateEventArgs(user, used);
activateComp.Activate(activateEventArgs); activateComp.Activate(activateEventArgs);
delayComponent?.BeginDelay();
_adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); // No way to check success. _adminLogSystem.Add(LogType.InteractActivate, LogImpact.Low, $"{ToPrettyString(user):user} activated {ToPrettyString(used):used}"); // No way to check success.
} }
#endregion #endregion
@@ -660,18 +657,16 @@ namespace Content.Shared.Interaction
/// <returns>True if the interaction was handled. False otherwise</returns> /// <returns>True if the interaction was handled. False otherwise</returns>
public bool UseInteraction(EntityUid user, EntityUid used) public bool UseInteraction(EntityUid user, EntityUid used)
{ {
if (TryComp(used, out UseDelayComponent? delayComponent)) if (TryComp(used, out UseDelayComponent? delayComponent) && delayComponent.ActiveDelay)
{
if (delayComponent.ActiveDelay)
return true; // if the item is on cooldown, we consider this handled. return true; // if the item is on cooldown, we consider this handled.
delayComponent.BeginDelay();
}
var useMsg = new UseInHandEvent(user, used); var useMsg = new UseInHandEvent(user, used);
RaiseLocalEvent(used, useMsg); RaiseLocalEvent(used, useMsg);
if (useMsg.Handled) if (useMsg.Handled)
{
delayComponent?.BeginDelay();
return true; return true;
}
var uses = AllComps<IUse>(used).ToList(); var uses = AllComps<IUse>(used).ToList();
@@ -680,8 +675,11 @@ namespace Content.Shared.Interaction
{ {
// If a Use returns a status completion we finish our interaction // If a Use returns a status completion we finish our interaction
if (use.UseEntity(new UseEntityEventArgs(user))) if (use.UseEntity(new UseEntityEventArgs(user)))
{
delayComponent?.BeginDelay();
return true; return true;
} }
}
return false; return false;
} }

View File

@@ -46,14 +46,11 @@ namespace Content.Shared.Timing
_lastUseTime = IoCManager.Resolve<IGameTiming>().CurTime; _lastUseTime = IoCManager.Resolve<IGameTiming>().CurTime;
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out ItemCooldownComponent? cooldown)) var cooldown = IoCManager.Resolve<IEntityManager>().EnsureComponent<ItemCooldownComponent>(Owner);
{
cooldown.CooldownStart = _lastUseTime; cooldown.CooldownStart = _lastUseTime;
cooldown.CooldownEnd = _lastUseTime + TimeSpan.FromSeconds(Delay); cooldown.CooldownEnd = _lastUseTime + TimeSpan.FromSeconds(Delay);
} }
}
public void Cancel() public void Cancel()
{ {
cancellationTokenSource?.Cancel(); cancellationTokenSource?.Cancel();