Candy Bucket for Halloween (#21257)

* Added candy bucket and component to update appearance of held containers akin to it

* cleanup newline

* newline was load-bearing

* moved component to Shared, cleanup

* newline is spooky

* You build and run without errors, stop pretending otherwise

* Updated for new storage system in master branch
This commit is contained in:
Bixkitts
2023-10-31 16:54:41 +01:00
committed by GitHub
parent 77db8b166a
commit 74f1098008
10 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
using Robust.Shared.Containers;
using Content.Shared.Item;
using Content.Shared.Storage;
using Content.Shared.Storage.EntitySystems;
using Content.Shared.Toggleable;
namespace Content.Shared.ContainerHeld;
public sealed class ContainerHeldSystem : EntitySystem
{
[Dependency] private readonly SharedItemSystem _item = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedStorageSystem _storage = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ContainerHeldComponent, EntInsertedIntoContainerMessage>(OnContainerModified);
SubscribeLocalEvent<ContainerHeldComponent, EntRemovedFromContainerMessage>(OnContainerModified);
}
private void OnContainerModified(EntityUid uid, ContainerHeldComponent comp, ContainerModifiedMessage args)
{
if (!(TryComp<StorageComponent>(uid, out var storage)
&& TryComp<AppearanceComponent>(uid, out var appearance)
&& TryComp<ItemComponent>(uid, out var item)))
{
return;
}
if (_storage.GetCumulativeItemSizes(uid, storage) >= comp.Threshold)
{
_item.SetHeldPrefix(uid, "full", item);
_appearance.SetData(uid, ToggleVisuals.Toggled, true, appearance);
}
else
{
_item.SetHeldPrefix(uid, "empty", item);
_appearance.SetData(uid, ToggleVisuals.Toggled, false, appearance);
}
}
}