caninsert entitystorage tweaks (#20589)

This commit is contained in:
Nemanja
2023-09-28 23:55:29 -04:00
committed by GitHub
parent d664c906ad
commit 90605212fc
5 changed files with 41 additions and 36 deletions

View File

@@ -156,7 +156,7 @@ public sealed class CrematoriumSystem : EntitySystem
("victim", Identity.Entity(victim, EntityManager))),
victim, Filter.PvsExcept(victim), true, PopupType.LargeCaution);
if (_entityStorage.CanInsert(uid))
if (_entityStorage.CanInsert(victim, uid))
{
_entityStorage.CloseStorage(uid);
_standing.Down(victim, false);

View File

@@ -2,6 +2,7 @@ using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Robust.Shared.Map;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
@@ -17,7 +18,8 @@ public sealed class RandomEntityStorageSpawnRule : StationEventSystem<RandomEnti
if (!TryGetRandomStation(out var station))
return;
var validLockers = new List<(EntityUid, EntityStorageComponent, TransformComponent)>();
var validLockers = new List<(EntityUid, EntityStorageComponent)>();
var spawn = Spawn(comp.Prototype, MapCoordinates.Nullspace);
var query = EntityQueryEnumerator<EntityStorageComponent, TransformComponent>();
while (query.MoveNext(out var ent, out var storage, out var xform))
@@ -25,17 +27,19 @@ public sealed class RandomEntityStorageSpawnRule : StationEventSystem<RandomEnti
if (StationSystem.GetOwningStation(ent, xform) != station)
continue;
if (!_entityStorage.CanInsert(ent, storage) || storage.Open)
if (!_entityStorage.CanInsert(spawn, ent, storage))
continue;
validLockers.Add((ent, storage, xform));
validLockers.Add((ent, storage));
}
if (validLockers.Count == 0)
{
Del(spawn);
return;
}
var (locker, storageComp, xformComp) = RobustRandom.Pick(validLockers);
var spawn = Spawn(comp.Prototype, xformComp.Coordinates);
var (locker, storageComp) = RobustRandom.Pick(validLockers);
if (!_entityStorage.Insert(spawn, locker, storageComp))
{
Del(spawn);

View File

@@ -128,7 +128,7 @@ public sealed class EntityStorageSystem : SharedEntityStorageSystem
private TileRef? GetOffsetTileRef(EntityUid uid, EntityStorageComponent component)
{
var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset).ToMap(EntityManager);
var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset).ToMap(EntityManager, TransformSystem);
if (_map.TryFindGridAt(targetCoordinates, out _, out var grid))
{

View File

@@ -27,19 +27,19 @@ public abstract partial class SharedEntityStorageComponent : Component
/// <summary>
/// Collision masks that were removed from ANY layer when the storage was opened;
/// </summary>
[DataField("removedMasks")]
[DataField]
public int RemovedMasks;
/// <summary>
/// The total amount of items that can fit in one entitystorage
/// </summary>
[DataField("capacity")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public int Capacity = 30;
/// <summary>
/// Whether or not the entity still has collision when open
/// </summary>
[DataField("isCollidableWhenOpen")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool IsCollidableWhenOpen;
/// <summary>
@@ -47,71 +47,70 @@ public abstract partial class SharedEntityStorageComponent : Component
/// If false, it prevents the storage from opening when the entity inside of it moves.
/// This is for objects that you want the player to move while inside, like large cardboard boxes, without opening the storage.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("openOnMove")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool OpenOnMove = true;
//The offset for where items are emptied/vacuumed for the EntityStorage.
[DataField("enteringOffset")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public Vector2 EnteringOffset = new(0, 0);
//The collision groups checked, so that items are depositied or grabbed from inside walls.
[DataField("enteringOffsetCollisionFlags")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public CollisionGroup EnteringOffsetCollisionFlags = CollisionGroup.Impassable | CollisionGroup.MidImpassable;
/// <summary>
/// How close you have to be to the "entering" spot to be able to enter
/// </summary>
[DataField("enteringRange")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float EnteringRange = 0.18f;
/// <summary>
/// Whether or not to show the contents when the storage is closed
/// </summary>
[DataField("showContents")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool ShowContents;
/// <summary>
/// Whether or not light is occluded by the storage
/// </summary>
[DataField("occludesLight")]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool OccludesLight = true;
/// <summary>
/// Whether or not all the contents stored should be deleted with the entitystorage
/// </summary>
[DataField("deleteContentsOnDestruction"), ViewVariables(VVAccess.ReadWrite)]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool DeleteContentsOnDestruction;
/// <summary>
/// Whether or not the container is sealed and traps air inside of it
/// </summary>
[DataField("airtight"), ViewVariables(VVAccess.ReadWrite)]
[DataField, ViewVariables(VVAccess.ReadWrite)]
public bool Airtight = true;
/// <summary>
/// Whether or not the entitystorage is open or closed
/// </summary>
[DataField("open")]
[DataField]
public bool Open;
/// <summary>
/// The sound made when closed
/// </summary>
[DataField("closeSound")]
[DataField]
public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
/// <summary>
/// The sound made when open
/// </summary>
[DataField("openSound")]
[DataField]
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")]
[DataField]
public EntityWhitelist? Whitelist;
/// <summary>

View File

@@ -15,7 +15,6 @@ using Content.Shared.Storage.Components;
using Content.Shared.Tools.Systems;
using Content.Shared.Verbs;
using Content.Shared.Wall;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Map;
@@ -41,7 +40,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
[Dependency] private readonly SharedJointSystem _joints = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] protected readonly SharedPopupSystem Popup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
[Dependency] private readonly WeldableSystem _weldable = default!;
public const string ContainerName = "entity_storage";
@@ -103,7 +102,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
protected void OnDestruction(EntityUid uid, SharedEntityStorageComponent component, DestructionEventArgs args)
{
component.Open = true;
Dirty(component);
Dirty(uid, component);
if (!component.DeleteContentsOnDestruction)
{
EmptyContents(uid, component);
@@ -199,7 +198,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
var beforeev = new StorageBeforeOpenEvent();
RaiseLocalEvent(uid, ref beforeev);
component.Open = true;
Dirty(component);
Dirty(uid, component);
EmptyContents(uid, component);
ModifyComponents(uid, component);
if (_net.IsClient && _timing.IsFirstTimePredicted)
@@ -215,7 +214,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
return;
component.Open = false;
Dirty(component);
Dirty(uid, component);
var targetCoordinates = new EntityCoordinates(uid, component.EnteringOffset);
@@ -228,7 +227,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
{
if (!ev.BypassChecks.Contains(entity))
{
if (!CanFit(entity, uid, component.Whitelist))
if (!CanInsert(entity, uid, component))
continue;
}
@@ -256,7 +255,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
if (component.Open)
{
_transform.SetWorldPosition(toInsert, _transform.GetWorldPosition(container));
TransformSystem.SetWorldPosition(toInsert, TransformSystem.GetWorldPosition(container));
return true;
}
@@ -276,12 +275,12 @@ public abstract class SharedEntityStorageSystem : EntitySystem
RemComp<InsideEntityStorageComponent>(toRemove);
component.Contents.Remove(toRemove, EntityManager);
var pos = _transform.GetWorldPosition(xform) + _transform.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
_transform.SetWorldPosition(toRemove, pos);
var pos = TransformSystem.GetWorldPosition(xform) + TransformSystem.GetWorldRotation(xform).RotateVec(component.EnteringOffset);
TransformSystem.SetWorldPosition(toRemove, pos);
return true;
}
public bool CanInsert(EntityUid container, SharedEntityStorageComponent? component = null)
public bool CanInsert(EntityUid toInsert, EntityUid container, SharedEntityStorageComponent? component = null)
{
if (!ResolveStorage(container, ref component))
return false;
@@ -292,7 +291,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
if (component.Contents.ContainedEntities.Count >= component.Capacity)
return false;
return true;
return CanFit(toInsert, container, component);
}
public bool TryOpenStorage(EntityUid user, EntityUid target, bool silent = false)
@@ -376,8 +375,11 @@ public abstract class SharedEntityStorageSystem : EntitySystem
return Insert(toAdd, container, component);
}
public bool CanFit(EntityUid toInsert, EntityUid container, EntityWhitelist? whitelist)
private bool CanFit(EntityUid toInsert, EntityUid container, SharedEntityStorageComponent? component = null)
{
if (!Resolve(container, ref component))
return false;
// conditions are complicated because of pizzabox-related issues, so follow this guide
// 0. Accomplish your goals at all costs.
// 1. AddToContents can block anything
@@ -395,7 +397,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
var targetIsMob = HasComp<BodyComponent>(toInsert);
var storageIsItem = HasComp<ItemComponent>(container);
var allowedToEat = whitelist?.IsValid(toInsert) ?? HasComp<ItemComponent>(toInsert);
var allowedToEat = component.Whitelist?.IsValid(toInsert) ?? HasComp<ItemComponent>(toInsert);
// BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
// Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.