Expand UseDelay to support multiple delays per entity; fix bible healing and bag pickup (#27234)
* Upgraded UseDelay to support multiple delays per entity * Implement secondary delay for bibles. Also some improvements to make it work nicely. * Documentation is good * Reserve the previous change; now Storage uses the special ID and Bible uses the default. * .0 * Added VV support to UseDelayInfo * Serialize better * No register, just setlength
This commit is contained in:
@@ -24,7 +24,8 @@ public sealed partial class StorageSystem : SharedStorageSystem
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly UseDelaySystem _useDelay = default!;
|
||||
|
||||
private const string OpenUiUseDelayID = "storage";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -39,6 +40,14 @@ public sealed partial class StorageSystem : SharedStorageSystem
|
||||
SubscribeLocalEvent<StorageFillComponent, MapInitEvent>(OnStorageFillMapInit);
|
||||
}
|
||||
|
||||
protected override void OnMapInit(Entity<StorageComponent> entity, ref MapInitEvent args)
|
||||
{
|
||||
base.OnMapInit(entity, ref args);
|
||||
|
||||
if (TryComp<UseDelayComponent>(entity, out var useDelay))
|
||||
UseDelay.SetLength((entity, useDelay), entity.Comp.OpenUiCooldown, OpenUiUseDelayID);
|
||||
}
|
||||
|
||||
private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent<ActivationVerb> args)
|
||||
{
|
||||
var silent = false;
|
||||
@@ -120,13 +129,13 @@ public sealed partial class StorageSystem : SharedStorageSystem
|
||||
return;
|
||||
|
||||
// prevent spamming bag open / honkerton honk sound
|
||||
silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && _useDelay.IsDelayed((uid, useDelay));
|
||||
silent |= TryComp<UseDelayComponent>(uid, out var useDelay) && UseDelay.IsDelayed((uid, useDelay), OpenUiUseDelayID);
|
||||
if (!silent)
|
||||
{
|
||||
if (!storageComp.IsUiOpen)
|
||||
_audio.PlayPvs(storageComp.StorageOpenSound, uid);
|
||||
if (useDelay != null)
|
||||
_useDelay.TryResetDelay((uid, useDelay));
|
||||
UseDelay.TryResetDelay((uid, useDelay), id: OpenUiUseDelayID);
|
||||
}
|
||||
|
||||
Log.Debug($"Storage (UID {uid}) \"used\" by player session (UID {player.PlayerSession.AttachedEntity}).");
|
||||
|
||||
Reference in New Issue
Block a user