From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Fri, 29 Sep 2023 03:55:29 +0000 (-0400) Subject: caninsert entitystorage tweaks (#20589) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=90605212fcac479c551c610d2fa71951190684dd;p=space-station-14.git caninsert entitystorage tweaks (#20589) --- diff --git a/Content.Server/Morgue/CrematoriumSystem.cs b/Content.Server/Morgue/CrematoriumSystem.cs index 5ef42ea00e..d713b43f27 100644 --- a/Content.Server/Morgue/CrematoriumSystem.cs +++ b/Content.Server/Morgue/CrematoriumSystem.cs @@ -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); diff --git a/Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs b/Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs index a9e8c437ec..c3cd719cc4 100644 --- a/Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs +++ b/Content.Server/StationEvents/Events/RandomEntityStorageSpawnRule.cs @@ -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(); + var validLockers = new List<(EntityUid, EntityStorageComponent)>(); + var spawn = Spawn(comp.Prototype, MapCoordinates.Nullspace); var query = EntityQueryEnumerator(); while (query.MoveNext(out var ent, out var storage, out var xform)) @@ -25,17 +27,19 @@ public sealed class RandomEntityStorageSpawnRule : StationEventSystem /// Collision masks that were removed from ANY layer when the storage was opened; /// - [DataField("removedMasks")] + [DataField] public int RemovedMasks; /// /// The total amount of items that can fit in one entitystorage /// - [DataField("capacity")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public int Capacity = 30; /// /// Whether or not the entity still has collision when open /// - [DataField("isCollidableWhenOpen")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public bool IsCollidableWhenOpen; /// @@ -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. /// - [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; /// /// How close you have to be to the "entering" spot to be able to enter /// - [DataField("enteringRange")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public float EnteringRange = 0.18f; /// /// Whether or not to show the contents when the storage is closed /// - [DataField("showContents")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public bool ShowContents; /// /// Whether or not light is occluded by the storage /// - [DataField("occludesLight")] + [DataField, ViewVariables(VVAccess.ReadWrite)] public bool OccludesLight = true; /// /// Whether or not all the contents stored should be deleted with the entitystorage /// - [DataField("deleteContentsOnDestruction"), ViewVariables(VVAccess.ReadWrite)] + [DataField, ViewVariables(VVAccess.ReadWrite)] public bool DeleteContentsOnDestruction; /// /// Whether or not the container is sealed and traps air inside of it /// - [DataField("airtight"), ViewVariables(VVAccess.ReadWrite)] + [DataField, ViewVariables(VVAccess.ReadWrite)] public bool Airtight = true; /// /// Whether or not the entitystorage is open or closed /// - [DataField("open")] + [DataField] public bool Open; /// /// The sound made when closed /// - [DataField("closeSound")] + [DataField] public SoundSpecifier CloseSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg"); /// /// The sound made when open /// - [DataField("openSound")] + [DataField] public SoundSpecifier OpenSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg"); /// /// 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. /// - [DataField("whitelist")] + [DataField] public EntityWhitelist? Whitelist; /// diff --git a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs index b4c0a63979..7553fb6c9c 100644 --- a/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs @@ -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(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(toInsert); var storageIsItem = HasComp(container); - var allowedToEat = whitelist?.IsValid(toInsert) ?? HasComp(toInsert); + var allowedToEat = component.Whitelist?.IsValid(toInsert) ?? HasComp(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.