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,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
/// <returns>True if the interaction was handled. False otherwise</returns>
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<IUse>(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;

View File

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