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:
Tayrtahn
2024-04-25 22:25:52 -04:00
committed by GitHub
parent 0aee198adf
commit b292905216
7 changed files with 193 additions and 62 deletions

View File

@@ -72,6 +72,8 @@ public abstract class SharedStorageSystem : EntitySystem
private readonly List<ItemSizePrototype> _sortedSizes = new();
private FrozenDictionary<string, ItemSizePrototype> _nextSmallest = FrozenDictionary<string, ItemSizePrototype>.Empty;
private const string QuickInsertUseDelayID = "quickInsert";
protected readonly List<string> CantFillReasons = [];
/// <inheritdoc />
@@ -84,6 +86,7 @@ public abstract class SharedStorageSystem : EntitySystem
_xformQuery = GetEntityQuery<TransformComponent>();
_prototype.PrototypesReloaded += OnPrototypesReloaded;
SubscribeLocalEvent<StorageComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<StorageComponent, ComponentGetState>(OnStorageGetState);
SubscribeLocalEvent<StorageComponent, ComponentHandleState>(OnStorageHandleState);
SubscribeLocalEvent<StorageComponent, ComponentInit>(OnComponentInit, before: new[] { typeof(SharedContainerSystem) });
@@ -118,6 +121,12 @@ public abstract class SharedStorageSystem : EntitySystem
UpdatePrototypeCache();
}
protected virtual void OnMapInit(Entity<StorageComponent> entity, ref MapInitEvent args)
{
if (TryComp<UseDelayComponent>(entity, out var useDelayComp))
UseDelay.SetLength((entity, useDelayComp), entity.Comp.QuickInsertCooldown, QuickInsertUseDelayID);
}
private void OnStorageGetState(EntityUid uid, StorageComponent component, ref ComponentGetState args)
{
var storedItems = new Dictionary<NetEntity, ItemStorageLocation>();
@@ -275,7 +284,7 @@ public abstract class SharedStorageSystem : EntitySystem
/// <returns></returns>
private void AfterInteract(EntityUid uid, StorageComponent storageComp, AfterInteractEvent args)
{
if (args.Handled || !args.CanReach || !UseDelay.TryResetDelay(uid, checkDelayed: true))
if (args.Handled || !args.CanReach || !UseDelay.TryResetDelay(uid, checkDelayed: true, id: QuickInsertUseDelayID))
return;
// Pick up all entities in a radius around the clicked location.