Entity storage whitelist (#9694)
This commit is contained in:
@@ -1,7 +0,0 @@
|
|||||||
namespace Content.Server.Storage.Components;
|
|
||||||
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class ArtifactStorageComponent : Component
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Content.Shared.Sound;
|
using Content.Shared.Sound;
|
||||||
|
using Content.Shared.Whitelist;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
|
|
||||||
namespace Content.Server.Storage.Components;
|
namespace Content.Server.Storage.Components;
|
||||||
@@ -64,6 +65,13 @@ public sealed class EntityStorageComponent : Component
|
|||||||
[DataField("openSound")]
|
[DataField("openSound")]
|
||||||
public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
|
public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whitelist for what entities are allowed to be inserted into this container. If this is not null, the
|
||||||
|
/// standard requirement that the entity must be an item or mob is waived.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("whitelist")]
|
||||||
|
public EntityWhitelist? Whitelist;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public Container Contents = default!;
|
public Container Contents = default!;
|
||||||
|
|
||||||
@@ -93,7 +101,10 @@ public sealed class StorageBeforeCloseEvent : EventArgs
|
|||||||
|
|
||||||
public HashSet<EntityUid> Contents;
|
public HashSet<EntityUid> Contents;
|
||||||
|
|
||||||
public HashSet<EntityUid> ContentsWhitelist = new();
|
/// <summary>
|
||||||
|
/// Entities that will get inserted, regardless of any insertion or whitelist checks.
|
||||||
|
/// </summary>
|
||||||
|
public HashSet<EntityUid> BypassChecks = new();
|
||||||
|
|
||||||
public StorageBeforeCloseEvent(EntityUid container, HashSet<EntityUid> contents)
|
public StorageBeforeCloseEvent(EntityUid container, HashSet<EntityUid> contents)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
using Content.Server.Storage.Components;
|
|
||||||
using Content.Server.Xenoarchaeology.XenoArtifacts;
|
|
||||||
|
|
||||||
namespace Content.Server.Storage.EntitySystems;
|
|
||||||
|
|
||||||
public sealed class ArtifactStorageSystem : EntitySystem
|
|
||||||
{
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<ArtifactStorageComponent, StorageBeforeCloseEvent>(OnBeforeClose);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnBeforeClose(EntityUid uid, ArtifactStorageComponent component, StorageBeforeCloseEvent args)
|
|
||||||
{
|
|
||||||
foreach (var ent in args.Contents)
|
|
||||||
{
|
|
||||||
if (HasComp<ArtifactComponent>(ent))
|
|
||||||
args.ContentsWhitelist.Add(ent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@ using Content.Shared.Interaction;
|
|||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Content.Shared.Placeable;
|
using Content.Shared.Placeable;
|
||||||
using Content.Shared.Storage;
|
using Content.Shared.Storage;
|
||||||
|
using Content.Shared.Whitelist;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
@@ -143,16 +144,20 @@ public sealed class EntityStorageSystem : EntitySystem
|
|||||||
|
|
||||||
var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset);
|
var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset);
|
||||||
|
|
||||||
var ev = new StorageBeforeCloseEvent(uid, _lookup.GetEntitiesInRange(targetCoordinates, component.EnteringRange, LookupFlags.Approximate));
|
var entities = _lookup.GetEntitiesInRange(targetCoordinates, component.EnteringRange, LookupFlags.Approximate);
|
||||||
|
|
||||||
|
var ev = new StorageBeforeCloseEvent(uid, entities);
|
||||||
RaiseLocalEvent(uid, ev, true);
|
RaiseLocalEvent(uid, ev, true);
|
||||||
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var entity in ev.Contents)
|
foreach (var entity in ev.Contents)
|
||||||
{
|
{
|
||||||
if (!ev.ContentsWhitelist.Contains(entity))
|
if (!ev.BypassChecks.Contains(entity))
|
||||||
if (!CanFit(entity, uid))
|
{
|
||||||
|
if (!CanFit(entity, uid, component.Whitelist))
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!AddToContents(entity, uid, component))
|
if (!AddToContents(entity, uid, component))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -279,7 +284,7 @@ public sealed class EntityStorageSystem : EntitySystem
|
|||||||
return Insert(toAdd, container, component);
|
return Insert(toAdd, container, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanFit(EntityUid toInsert, EntityUid container)
|
public bool CanFit(EntityUid toInsert, EntityUid container, EntityWhitelist? whitelist)
|
||||||
{
|
{
|
||||||
// conditions are complicated because of pizzabox-related issues, so follow this guide
|
// conditions are complicated because of pizzabox-related issues, so follow this guide
|
||||||
// 0. Accomplish your goals at all costs.
|
// 0. Accomplish your goals at all costs.
|
||||||
@@ -296,13 +301,12 @@ public sealed class EntityStorageSystem : EntitySystem
|
|||||||
if (attemptEvent.Cancelled)
|
if (attemptEvent.Cancelled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// checks
|
|
||||||
// TODO: Make the others sub to it.
|
|
||||||
var targetIsItem = HasComp<SharedItemComponent>(toInsert);
|
|
||||||
var targetIsMob = HasComp<SharedBodyComponent>(toInsert);
|
var targetIsMob = HasComp<SharedBodyComponent>(toInsert);
|
||||||
var storageIsItem = HasComp<SharedItemComponent>(container);
|
var storageIsItem = HasComp<SharedItemComponent>(container);
|
||||||
|
|
||||||
var allowedToEat = targetIsItem;
|
var allowedToEat = whitelist == null
|
||||||
|
? HasComp<SharedItemComponent>(toInsert)
|
||||||
|
: whitelist.IsValid(toInsert);
|
||||||
|
|
||||||
// BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
|
// BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
|
||||||
// Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.
|
// Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.
|
||||||
|
|||||||
@@ -40,7 +40,9 @@
|
|||||||
state: artifact_container_icon
|
state: artifact_container_icon
|
||||||
- type: EntityStorage
|
- type: EntityStorage
|
||||||
Capacity: 1
|
Capacity: 1
|
||||||
- type: ArtifactStorage
|
whitelist:
|
||||||
|
components:
|
||||||
|
- Artifact
|
||||||
- type: Weldable
|
- type: Weldable
|
||||||
- type: SuppressArtifactContainer
|
- type: SuppressArtifactContainer
|
||||||
- type: PlaceableSurface
|
- type: PlaceableSurface
|
||||||
|
|||||||
Reference in New Issue
Block a user