2020-02-09 06:42:12 -03:00
|
|
|
using System.Linq;
|
2022-06-24 16:26:56 -03:00
|
|
|
using Content.Server.Buckle.Components;
|
2021-12-17 01:24:54 +01:00
|
|
|
using Content.Server.Construction;
|
2022-06-24 16:26:56 -03:00
|
|
|
using Content.Server.Construction.Completions;
|
2021-12-17 01:24:54 +01:00
|
|
|
using Content.Server.Construction.Components;
|
2021-10-06 11:45:52 +02:00
|
|
|
using Content.Server.Ghost.Components;
|
2022-05-03 01:43:25 +03:00
|
|
|
using Content.Server.Storage.EntitySystems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Body.Components;
|
2022-01-11 17:55:27 +13:00
|
|
|
using Content.Shared.Foldable;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Item;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Content.Shared.Physics;
|
2021-08-20 10:21:39 +02:00
|
|
|
using Content.Shared.Placeable;
|
2021-09-26 15:18:45 +02:00
|
|
|
using Content.Shared.Popups;
|
2021-07-10 17:35:33 +02:00
|
|
|
using Content.Shared.Sound;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Storage;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2019-04-17 23:26:00 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Storage.Components
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
[Virtual]
|
2019-07-31 15:02:36 +02:00
|
|
|
[ComponentReference(typeof(IActivate))]
|
|
|
|
|
[ComponentReference(typeof(IStorageComponent))]
|
2022-05-09 08:51:52 +03:00
|
|
|
public class EntityStorageComponent : Component, IActivate, IStorageComponent
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2019-09-01 17:08:15 -07:00
|
|
|
private const float MaxSize = 1.0f; // maximum width or height of an entity allowed inside the storage.
|
|
|
|
|
|
2021-09-20 19:06:48 +10:00
|
|
|
public static readonly TimeSpan InternalOpenAttemptDelay = TimeSpan.FromSeconds(0.5);
|
|
|
|
|
public TimeSpan LastInternalOpenAttempt;
|
2020-05-25 13:58:56 +02:00
|
|
|
|
2022-05-01 09:27:07 +12:00
|
|
|
/// <summary>
|
|
|
|
|
/// Collision masks that get removed when the storage gets opened.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const int MasksToRemove = (int) (
|
2022-05-10 17:57:20 -07:00
|
|
|
CollisionGroup.MidImpassable |
|
|
|
|
|
CollisionGroup.HighImpassable |
|
|
|
|
|
CollisionGroup.LowImpassable);
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2022-05-01 09:27:07 +12:00
|
|
|
/// <summary>
|
|
|
|
|
/// Collision masks that were removed from ANY layer when the storage was opened;
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataField("removedMasks")] public int RemovedMasks;
|
|
|
|
|
|
2020-05-25 13:58:56 +02:00
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("Capacity")]
|
|
|
|
|
private int _storageCapacityMax = 30;
|
|
|
|
|
|
2020-05-25 13:58:56 +02:00
|
|
|
[ViewVariables]
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("IsCollidableWhenOpen")]
|
2020-07-03 14:54:45 +02:00
|
|
|
private bool _isCollidableWhenOpen;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-12-27 08:04:18 -04:00
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("EnteringRange")]
|
2022-05-11 13:46:58 -07:00
|
|
|
private float _enteringRange = -0.18f;
|
2021-12-27 08:04:18 -04:00
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("showContents")]
|
2020-01-03 16:00:30 -08:00
|
|
|
private bool _showContents;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
[DataField("occludesLight")]
|
|
|
|
|
private bool _occludesLight = true;
|
|
|
|
|
|
|
|
|
|
[DataField("open")]
|
2022-05-03 01:43:25 +03:00
|
|
|
public bool Open;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
[DataField("closeSound")]
|
2021-09-09 18:31:54 -07:00
|
|
|
private SoundSpecifier _closeSound = new SoundPathSpecifier("/Audio/Effects/closetclose.ogg");
|
2021-03-05 01:08:38 +01:00
|
|
|
|
|
|
|
|
[DataField("openSound")]
|
2021-09-09 18:31:54 -07:00
|
|
|
private SoundSpecifier _openSound = new SoundPathSpecifier("/Audio/Effects/closetopen.ogg");
|
2020-01-03 13:38:58 -08:00
|
|
|
|
2020-07-26 20:49:41 +02:00
|
|
|
[ViewVariables]
|
2021-10-05 14:29:03 +11:00
|
|
|
public Container Contents = default!;
|
2020-07-26 20:49:41 +02:00
|
|
|
|
2020-01-03 16:00:30 -08:00
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if the container contents should be drawn when the container is closed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool ShowContents
|
|
|
|
|
{
|
|
|
|
|
get => _showContents;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_showContents = value;
|
2020-07-26 20:49:41 +02:00
|
|
|
Contents.ShowContents = _showContents;
|
2020-01-03 16:00:30 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 08:25:53 -04:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool OccludesLight
|
|
|
|
|
{
|
|
|
|
|
get => _occludesLight;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_occludesLight = value;
|
2020-07-26 20:49:41 +02:00
|
|
|
Contents.OccludesLight = _occludesLight;
|
2020-07-26 08:25:53 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-25 13:58:56 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2022-05-09 08:51:52 +03:00
|
|
|
public bool IsWeldedShut;
|
2020-05-25 13:58:56 +02:00
|
|
|
|
2021-12-27 08:04:18 -04:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public float EnteringRange
|
|
|
|
|
{
|
|
|
|
|
get => _enteringRange;
|
|
|
|
|
set => _enteringRange = value;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:38:58 -08:00
|
|
|
/// <inheritdoc />
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2022-06-12 13:29:03 +10:00
|
|
|
Contents = Owner.EnsureContainer<Container>(EntityStorageSystem.ContainerName);
|
2020-07-26 20:49:41 +02:00
|
|
|
Contents.ShowContents = _showContents;
|
|
|
|
|
Contents.OccludesLight = _occludesLight;
|
2020-01-03 17:49:17 -08:00
|
|
|
|
2021-12-17 01:24:54 +01:00
|
|
|
if(_entMan.TryGetComponent(Owner, out ConstructionComponent? construction))
|
2022-03-25 23:56:05 +13:00
|
|
|
EntitySystem.Get<ConstructionSystem>().AddContainer(Owner, nameof(EntityStorageComponent), construction);
|
2021-12-17 01:24:54 +01:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent<PlaceableSurfaceComponent?>(Owner, out var surface))
|
2020-02-09 06:42:12 -03:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(Owner, Open, surface);
|
2020-02-09 06:42:12 -03:00
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-25 01:03:44 +02:00
|
|
|
public virtual void Activate(ActivateEventArgs eventArgs)
|
2020-01-03 13:38:58 -08:00
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
ToggleOpen(eventArgs.User);
|
2020-01-03 13:38:58 -08:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public virtual bool CanOpen(EntityUid user, bool silent = false)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
if (IsWeldedShut)
|
|
|
|
|
{
|
2022-01-05 23:18:48 -07:00
|
|
|
if (!silent && !Contents.Contains(user))
|
|
|
|
|
Owner.PopupMessage(user, Loc.GetString("entity-storage-component-welded-shut-message"));
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
return false;
|
2020-05-25 13:58:56 +02:00
|
|
|
}
|
2021-10-05 14:29:03 +11:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent<LockComponent?>(Owner, out var @lock) && @lock.Locked)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
|
|
|
|
if (!silent) Owner.PopupMessage(user, Loc.GetString("entity-storage-component-locked-message"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 15:57:20 +11:00
|
|
|
var @event = new StorageOpenAttemptEvent();
|
2022-06-22 09:53:41 +10:00
|
|
|
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(Owner, @event, true);
|
2021-12-29 15:57:20 +11:00
|
|
|
|
|
|
|
|
return !@event.Cancelled;
|
2020-10-28 22:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public virtual bool CanClose(EntityUid user, bool silent = false)
|
2020-10-28 22:51:43 +00:00
|
|
|
{
|
2021-12-29 15:57:20 +11:00
|
|
|
var @event = new StorageCloseAttemptEvent();
|
2022-06-22 09:53:41 +10:00
|
|
|
IoCManager.Resolve<IEntityManager>().EventBus.RaiseLocalEvent(Owner, @event, true);
|
2021-12-29 15:57:20 +11:00
|
|
|
|
|
|
|
|
return !@event.Cancelled;
|
2020-10-28 22:51:43 +00:00
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public void ToggleOpen(EntityUid user)
|
2020-10-28 22:51:43 +00:00
|
|
|
{
|
2019-04-17 23:26:00 +02:00
|
|
|
if (Open)
|
|
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
TryCloseStorage(user);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
TryOpenStorage(user);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
protected virtual void CloseStorage()
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
Open = false;
|
2021-06-27 05:40:03 +02:00
|
|
|
|
2019-05-05 18:52:06 +02:00
|
|
|
var count = 0;
|
2021-06-27 05:40:03 +02:00
|
|
|
foreach (var entity in DetermineCollidingEntities())
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2019-09-09 14:50:12 -07:00
|
|
|
// prevents taking items out of inventories, out of containers, and orphaning child entities
|
2021-06-27 05:40:03 +02:00
|
|
|
if (entity.IsInContainer())
|
2019-09-09 14:50:12 -07:00
|
|
|
continue;
|
|
|
|
|
|
2022-04-29 01:03:39 +03:00
|
|
|
if (!CanFit(entity))
|
2021-10-06 11:45:52 +02:00
|
|
|
continue;
|
|
|
|
|
|
2021-11-11 12:56:38 +00:00
|
|
|
// finally, AddToContents
|
2019-04-17 23:26:00 +02:00
|
|
|
if (!AddToContents(entity))
|
|
|
|
|
continue;
|
2021-11-11 12:56:38 +00:00
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
count++;
|
2020-07-03 14:54:45 +02:00
|
|
|
if (count >= _storageCapacityMax)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-27 09:23:00 +02:00
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
ModifyComponents();
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(_closeSound.GetSound(), Filter.Pvs(Owner), Owner);
|
2021-09-20 19:06:48 +10:00
|
|
|
LastInternalOpenAttempt = default;
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-29 01:03:39 +03:00
|
|
|
public virtual bool CanFit(EntityUid entity)
|
|
|
|
|
{
|
|
|
|
|
// conditions are complicated because of pizzabox-related issues, so follow this guide
|
|
|
|
|
// 0. Accomplish your goals at all costs.
|
|
|
|
|
// 1. AddToContents can block anything
|
|
|
|
|
// 2. maximum item count can block anything
|
|
|
|
|
// 3. ghosts can NEVER be eaten
|
|
|
|
|
// 4. items can always be eaten unless a previous law prevents it
|
|
|
|
|
// 5. if this is NOT AN ITEM, then mobs can always be eaten unless unless a previous law prevents it
|
|
|
|
|
// 6. if this is an item, then mobs must only be eaten if some other component prevents pick-up interactions while a mob is inside (e.g. foldable)
|
|
|
|
|
|
2022-06-24 16:26:56 -03:00
|
|
|
var attemptEvent = new InsertIntoEntityStorageAttemptEvent();
|
|
|
|
|
_entMan.EventBus.RaiseLocalEvent(entity, attemptEvent);
|
|
|
|
|
if (attemptEvent.Cancelled)
|
2022-04-29 01:03:39 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// checks
|
|
|
|
|
|
|
|
|
|
var targetIsItem = _entMan.HasComponent<SharedItemComponent>(entity);
|
|
|
|
|
var targetIsMob = _entMan.HasComponent<SharedBodyComponent>(entity);
|
|
|
|
|
var storageIsItem = _entMan.HasComponent<SharedItemComponent>(Owner);
|
|
|
|
|
|
|
|
|
|
var allowedToEat = targetIsItem;
|
|
|
|
|
|
|
|
|
|
// BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
|
|
|
|
|
// Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.
|
|
|
|
|
// Seriously, it is insanely hacky and weird to get someone out of a backpack once they end up in there.
|
|
|
|
|
// And to be clear, they should NOT be in there.
|
|
|
|
|
// For the record, what you need to do is empty the backpack onto a PlacableSurface (table, rack)
|
|
|
|
|
if (targetIsMob)
|
|
|
|
|
{
|
|
|
|
|
if (!storageIsItem)
|
|
|
|
|
allowedToEat = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 16:26:56 -03:00
|
|
|
_entMan.EventBus.RaiseLocalEvent(entity, allowedToEat);
|
2022-04-29 01:03:39 +03:00
|
|
|
return allowedToEat;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
protected virtual void OpenStorage()
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
Open = true;
|
2022-05-03 01:43:25 +03:00
|
|
|
EntitySystem.Get<EntityStorageSystem>().EmptyContents(Owner, this);
|
2019-04-17 23:26:00 +02:00
|
|
|
ModifyComponents();
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(_openSound.GetSound(), Filter.Pvs(Owner), Owner);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ModifyComponents()
|
2019-07-27 09:23:00 +02:00
|
|
|
{
|
2022-05-01 09:27:07 +12:00
|
|
|
if (!_isCollidableWhenOpen && _entMan.TryGetComponent<FixturesComponent?>(Owner, out var manager)
|
|
|
|
|
&& manager.Fixtures.Count > 0)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2022-05-01 09:27:07 +12:00
|
|
|
// currently only works for single-fixture entities. If they have more than one fixture, then
|
|
|
|
|
// RemovedMasks needs to be tracked separately for each fixture, using a fixture Id Dictionary. Also the
|
|
|
|
|
// fixture IDs probably cant be automatically generated without causing issues, unless there is some
|
|
|
|
|
// guarantee that they will get deserialized with the same auto-generated ID when saving+loading the map.
|
|
|
|
|
var fixture = manager.Fixtures.Values.First();
|
|
|
|
|
|
2020-07-02 06:31:55 -07:00
|
|
|
if (Open)
|
|
|
|
|
{
|
2022-05-01 09:27:07 +12:00
|
|
|
RemovedMasks = fixture.CollisionLayer & MasksToRemove;
|
|
|
|
|
fixture.CollisionLayer &= ~MasksToRemove;
|
2020-07-02 06:31:55 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-05-01 09:27:07 +12:00
|
|
|
fixture.CollisionLayer |= RemovedMasks;
|
|
|
|
|
RemovedMasks = 0;
|
2020-07-02 06:31:55 -07:00
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent<PlaceableSurfaceComponent?>(Owner, out var surface))
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(Owner, Open, surface);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
appearance.SetData(StorageVisuals.Open, Open);
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
protected virtual bool AddToContents(EntityUid entity)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
if (entity == Owner) return false;
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent(entity, out IPhysBody? entityPhysicsComponent))
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2021-04-01 18:46:23 +11:00
|
|
|
if (MaxSize < entityPhysicsComponent.GetWorldAABB().Size.X
|
2021-03-08 04:09:59 +11:00
|
|
|
|| MaxSize < entityPhysicsComponent.GetWorldAABB().Size.Y)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-01 18:46:23 +11:00
|
|
|
|
|
|
|
|
return Contents.CanInsert(entity) && Insert(entity);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
public virtual Vector2 ContentsDumpPosition()
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
return _entMan.GetComponent<TransformComponent>(Owner).WorldPosition;
|
2020-10-28 22:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public virtual bool TryOpenStorage(EntityUid user)
|
2020-05-25 13:58:56 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
if (!CanOpen(user)) return false;
|
2020-05-25 13:58:56 +02:00
|
|
|
OpenStorage();
|
2020-10-28 22:51:43 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
public virtual bool TryCloseStorage(EntityUid user)
|
2020-10-28 22:51:43 +00:00
|
|
|
{
|
|
|
|
|
if (!CanClose(user)) return false;
|
|
|
|
|
CloseStorage();
|
|
|
|
|
return true;
|
2020-05-25 13:58:56 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:38:58 -08:00
|
|
|
/// <inheritdoc />
|
2021-12-05 18:09:01 +01:00
|
|
|
public bool Remove(EntityUid entity)
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
2020-07-26 20:49:41 +02:00
|
|
|
return Contents.CanRemove(entity);
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:38:58 -08:00
|
|
|
/// <inheritdoc />
|
2021-12-05 18:09:01 +01:00
|
|
|
public bool Insert(EntityUid entity)
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
// Trying to add while open just dumps it on the ground below us.
|
|
|
|
|
if (Open)
|
|
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
var entMan = _entMan;
|
2021-12-07 17:48:49 +01:00
|
|
|
entMan.GetComponent<TransformComponent>(entity).WorldPosition = entMan.GetComponent<TransformComponent>(Owner).WorldPosition;
|
2019-05-05 18:52:06 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 21:19:53 +11:00
|
|
|
return Contents.Insert(entity);
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-03 13:38:58 -08:00
|
|
|
/// <inheritdoc />
|
2021-12-05 18:09:01 +01:00
|
|
|
public bool CanInsert(EntityUid entity)
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
if (Open)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 20:49:41 +02:00
|
|
|
if (Contents.ContainedEntities.Count >= _storageCapacityMax)
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-26 20:49:41 +02:00
|
|
|
return Contents.CanInsert(entity);
|
2019-05-05 18:52:06 +02:00
|
|
|
}
|
2020-01-03 13:38:58 -08:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
protected virtual IEnumerable<EntityUid> DetermineCollidingEntities()
|
2021-06-27 05:40:03 +02:00
|
|
|
{
|
2022-03-03 21:18:35 +11:00
|
|
|
var entityLookup = EntitySystem.Get<EntityLookupSystem>();
|
2022-04-06 19:35:18 +10:00
|
|
|
return entityLookup.GetEntitiesInRange(Owner, _enteringRange, LookupFlags.Approximate);
|
2021-06-27 05:40:03 +02:00
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
2021-12-29 15:57:20 +11:00
|
|
|
|
2022-06-24 16:26:56 -03:00
|
|
|
public sealed class InsertIntoEntityStorageAttemptEvent : CancellableEntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2021-12-29 15:57:20 +11:00
|
|
|
public sealed class StorageOpenAttemptEvent : CancellableEntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed class StorageCloseAttemptEvent : CancellableEntityEventArgs
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|