2020-11-14 01:08:00 +11:00
|
|
|
using System;
|
2021-06-27 05:40:03 +02:00
|
|
|
using System.Collections.Generic;
|
2020-02-09 06:42:12 -03:00
|
|
|
using System.Linq;
|
2020-08-18 14:39:08 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Content.Server.Tools;
|
2021-10-06 11:45:52 +02:00
|
|
|
using Content.Server.Ghost.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Tools.Components;
|
|
|
|
|
using Content.Shared.ActionBlocker;
|
|
|
|
|
using Content.Shared.Acts;
|
|
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
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-10-07 13:01:27 +02:00
|
|
|
using Content.Shared.Tools;
|
|
|
|
|
using Content.Shared.Tools.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Verbs;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Audio;
|
2021-03-01 15:24:46 -08:00
|
|
|
using Robust.Shared.Containers;
|
2019-04-17 23:26:00 +02:00
|
|
|
using Robust.Shared.GameObjects;
|
2020-05-25 13:58:56 +02:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Localization;
|
2019-04-17 23:26:00 +02:00
|
|
|
using Robust.Shared.Maths;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Physics;
|
2021-03-21 09:12:03 -07:00
|
|
|
using Robust.Shared.Player;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
2019-04-17 23:26:00 +02:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
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]
|
|
|
|
|
[ComponentReference(typeof(IActivate))]
|
|
|
|
|
[ComponentReference(typeof(IStorageComponent))]
|
2021-10-21 13:03:14 +11:00
|
|
|
public class EntityStorageComponent : Component, IActivate, IStorageComponent, IInteractUsing, IDestroyAct, IExAct
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
public override string Name => "EntityStorage";
|
|
|
|
|
|
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
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
private const int OpenMask = (int) (
|
|
|
|
|
CollisionGroup.MobImpassable |
|
|
|
|
|
CollisionGroup.VaultImpassable |
|
|
|
|
|
CollisionGroup.SmallImpassable);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
[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")]
|
2020-05-25 01:03:44 +02:00
|
|
|
private bool _open;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
[DataField("weldingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
|
|
|
|
private string _weldingQuality = "Welding";
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("CanWeldShut")]
|
|
|
|
|
private bool _canWeldShut = true;
|
|
|
|
|
|
|
|
|
|
[DataField("IsWeldedShut")]
|
2020-05-25 13:58:56 +02:00
|
|
|
private bool _isWeldedShut;
|
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)]
|
|
|
|
|
public bool Open
|
|
|
|
|
{
|
|
|
|
|
get => _open;
|
|
|
|
|
private set => _open = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool IsWeldedShut
|
|
|
|
|
{
|
|
|
|
|
get => _isWeldedShut;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-04-08 07:39:50 -05:00
|
|
|
if (_isWeldedShut == value) return;
|
2020-05-25 13:58:56 +02:00
|
|
|
|
2021-04-08 07:39:50 -05:00
|
|
|
_isWeldedShut = value;
|
|
|
|
|
UpdateAppearance();
|
2020-05-25 13:58:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 01:08:00 +11:00
|
|
|
private bool _beingWelded;
|
|
|
|
|
|
2020-05-25 13:58:56 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-07-30 19:22:06 +02:00
|
|
|
public bool CanWeldShut
|
|
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
get => _canWeldShut;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-04-08 07:39:50 -05:00
|
|
|
if (_canWeldShut == value) return;
|
2020-11-14 01:08:00 +11:00
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
_canWeldShut = value;
|
2021-04-08 07:39:50 -05:00
|
|
|
UpdateAppearance();
|
2020-10-28 22:51:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
|
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();
|
2021-04-08 07:39:50 -05:00
|
|
|
Contents = Owner.EnsureContainer<Container>(nameof(EntityStorageComponent));
|
2020-07-26 20:49:41 +02:00
|
|
|
Contents.ShowContents = _showContents;
|
|
|
|
|
Contents.OccludesLight = _occludesLight;
|
2020-01-03 17:49:17 -08:00
|
|
|
|
2021-08-20 10:21:39 +02:00
|
|
|
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var surface))
|
2020-02-09 06:42:12 -03:00
|
|
|
{
|
2021-10-06 11:40:05 +02:00
|
|
|
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(Owner.Uid, Open, surface);
|
2020-02-09 06:42:12 -03:00
|
|
|
}
|
2021-04-08 07:39:50 -05:00
|
|
|
|
|
|
|
|
UpdateAppearance();
|
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
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
public virtual bool CanOpen(IEntity user, bool silent = false)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2020-05-25 13:58:56 +02:00
|
|
|
if (IsWeldedShut)
|
|
|
|
|
{
|
2021-07-30 19:22:06 +02:00
|
|
|
if (!silent) 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
|
|
|
|
|
|
|
|
if (Owner.TryGetComponent<LockComponent>(out var @lock) && @lock.Locked)
|
|
|
|
|
{
|
|
|
|
|
if (!silent) Owner.PopupMessage(user, Loc.GetString("entity-storage-component-locked-message"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool CanClose(IEntity user, bool silent = false)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-05-25 13:58:56 +02:00
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
public void ToggleOpen(IEntity 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;
|
|
|
|
|
|
2021-11-11 12:56:38 +00:00
|
|
|
// conditions are complicated because of pizzabox-related issues, so follow this guide
|
|
|
|
|
// 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
|
2020-02-09 06:42:12 -03:00
|
|
|
|
2021-10-06 11:45:52 +02:00
|
|
|
// Let's not insert admin ghosts, yeah? This is really a a hack and should be replaced by attempt events
|
2021-11-11 12:56:38 +00:00
|
|
|
if (Owner.EntityManager.HasComponent<GhostComponent>(entity.Uid))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// checks
|
|
|
|
|
|
|
|
|
|
var targetIsItem = Owner.EntityManager.HasComponent<SharedItemComponent>(entity.Uid);
|
|
|
|
|
var targetIsMob = Owner.EntityManager.HasComponent<SharedBodyComponent>(entity.Uid);
|
|
|
|
|
var storageIsItem = Owner.EntityManager.HasComponent<SharedItemComponent>(OwnerUid);
|
|
|
|
|
|
|
|
|
|
var allowedToEat = false;
|
|
|
|
|
|
|
|
|
|
if (targetIsItem)
|
|
|
|
|
allowedToEat = true;
|
|
|
|
|
|
|
|
|
|
// 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 && !storageIsItem)
|
|
|
|
|
allowedToEat = true;
|
|
|
|
|
|
|
|
|
|
if (!allowedToEat)
|
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();
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _closeSound.GetSound(), Owner);
|
2021-09-20 19:06:48 +10:00
|
|
|
LastInternalOpenAttempt = default;
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
protected virtual void OpenStorage()
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
|
|
|
|
Open = true;
|
|
|
|
|
EmptyContents();
|
|
|
|
|
ModifyComponents();
|
2021-07-31 19:52:33 +02:00
|
|
|
SoundSystem.Play(Filter.Pvs(Owner), _openSound.GetSound(), Owner);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 07:39:50 -05:00
|
|
|
private void UpdateAppearance()
|
|
|
|
|
{
|
|
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
|
|
|
|
{
|
|
|
|
|
appearance.SetData(StorageVisuals.CanWeld, _canWeldShut);
|
|
|
|
|
appearance.SetData(StorageVisuals.Welded, _isWeldedShut);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
private void ModifyComponents()
|
2019-07-27 09:23:00 +02:00
|
|
|
{
|
2021-12-01 18:32:37 +11:00
|
|
|
if (!_isCollidableWhenOpen && Owner.TryGetComponent<FixturesComponent>(out var manager))
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2020-07-02 06:31:55 -07:00
|
|
|
if (Open)
|
|
|
|
|
{
|
2021-12-01 18:32:37 +11:00
|
|
|
foreach (var (_, fixture) in manager.Fixtures)
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
fixture.CollisionLayer &= ~OpenMask;
|
|
|
|
|
}
|
2020-07-02 06:31:55 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-01 18:32:37 +11:00
|
|
|
foreach (var (_, fixture) in manager.Fixtures)
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
fixture.CollisionLayer |= OpenMask;
|
|
|
|
|
}
|
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-08-20 10:21:39 +02:00
|
|
|
if (Owner.TryGetComponent<PlaceableSurfaceComponent>(out var surface))
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2021-10-06 11:40:05 +02:00
|
|
|
EntitySystem.Get<PlaceableSurfaceSystem>().SetPlaceable(Owner.Uid, Open, surface);
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
2019-05-05 18:52:06 +02:00
|
|
|
|
2020-11-14 01:08:00 +11:00
|
|
|
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
|
2019-05-05 18:52:06 +02:00
|
|
|
{
|
|
|
|
|
appearance.SetData(StorageVisuals.Open, Open);
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
protected virtual bool AddToContents(IEntity entity)
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
if (entity == Owner) return false;
|
2021-03-08 04:09:59 +11:00
|
|
|
if (entity.TryGetComponent(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()
|
|
|
|
|
{
|
|
|
|
|
return Owner.Transform.WorldPosition;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-17 23:26:00 +02:00
|
|
|
private void EmptyContents()
|
|
|
|
|
{
|
2020-07-26 20:49:41 +02:00
|
|
|
foreach (var contained in Contents.ContainedEntities.ToArray())
|
2019-04-17 23:26:00 +02:00
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
if (Contents.Remove(contained))
|
2020-04-17 15:40:17 +02:00
|
|
|
{
|
2020-10-28 22:51:43 +00:00
|
|
|
contained.Transform.WorldPosition = ContentsDumpPosition();
|
2021-03-08 04:09:59 +11:00
|
|
|
if (contained.TryGetComponent<IPhysBody>(out var physics))
|
2020-04-17 15:40:17 +02:00
|
|
|
{
|
2020-10-11 16:36:58 +02:00
|
|
|
physics.CanCollide = true;
|
2020-04-17 15:40:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-28 22:51:43 +00:00
|
|
|
public virtual bool TryOpenStorage(IEntity 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual bool TryCloseStorage(IEntity user)
|
|
|
|
|
{
|
|
|
|
|
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 />
|
2019-05-05 18:52:06 +02:00
|
|
|
public bool Remove(IEntity entity)
|
|
|
|
|
{
|
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 />
|
2019-05-05 18:52:06 +02:00
|
|
|
public bool Insert(IEntity entity)
|
|
|
|
|
{
|
|
|
|
|
// Trying to add while open just dumps it on the ground below us.
|
|
|
|
|
if (Open)
|
|
|
|
|
{
|
|
|
|
|
entity.Transform.WorldPosition = Owner.Transform.WorldPosition;
|
|
|
|
|
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 />
|
2019-05-05 18:52:06 +02:00
|
|
|
public bool CanInsert(IEntity entity)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
2020-08-18 14:39:08 +02:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2020-07-07 00:49:14 +02:00
|
|
|
{
|
2020-11-14 01:08:00 +11:00
|
|
|
if (_beingWelded)
|
|
|
|
|
return false;
|
2020-07-07 00:49:14 +02:00
|
|
|
|
|
|
|
|
if (Open)
|
2020-11-14 01:08:00 +11:00
|
|
|
{
|
|
|
|
|
_beingWelded = false;
|
2020-07-07 00:49:14 +02:00
|
|
|
return false;
|
2020-11-14 01:08:00 +11:00
|
|
|
}
|
2020-07-07 00:49:14 +02:00
|
|
|
|
|
|
|
|
if (!CanWeldShut)
|
2020-11-14 01:08:00 +11:00
|
|
|
{
|
|
|
|
|
_beingWelded = false;
|
2020-07-07 00:49:14 +02:00
|
|
|
return false;
|
2020-11-14 01:08:00 +11:00
|
|
|
}
|
2020-07-07 00:49:14 +02:00
|
|
|
|
2020-07-26 20:49:41 +02:00
|
|
|
if (Contents.Contains(eventArgs.User))
|
2020-07-19 16:32:04 -04:00
|
|
|
{
|
2020-11-14 01:08:00 +11:00
|
|
|
_beingWelded = false;
|
2021-06-21 02:13:54 +02:00
|
|
|
Owner.PopupMessage(eventArgs.User, Loc.GetString("entity-storage-component-already-contains-user-message"));
|
2020-07-19 16:32:04 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-14 01:08:00 +11:00
|
|
|
if (_beingWelded)
|
2020-07-07 00:49:14 +02:00
|
|
|
return false;
|
|
|
|
|
|
2020-11-14 01:08:00 +11:00
|
|
|
_beingWelded = true;
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
var toolSystem = EntitySystem.Get<ToolSystem>();
|
|
|
|
|
|
|
|
|
|
if (!await toolSystem.UseTool(eventArgs.Using.Uid, eventArgs.User.Uid, Owner.Uid, 1f, 1f, _weldingQuality))
|
2020-11-14 01:08:00 +11:00
|
|
|
{
|
|
|
|
|
_beingWelded = false;
|
2020-07-07 00:49:14 +02:00
|
|
|
return false;
|
2020-11-14 01:08:00 +11:00
|
|
|
}
|
2020-07-07 00:49:14 +02:00
|
|
|
|
2020-11-14 01:08:00 +11:00
|
|
|
_beingWelded = false;
|
2020-07-07 00:49:14 +02:00
|
|
|
IsWeldedShut ^= true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
Open = true;
|
|
|
|
|
EmptyContents();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 06:13:46 +02:00
|
|
|
protected virtual IEnumerable<IEntity> DetermineCollidingEntities()
|
2021-06-27 05:40:03 +02:00
|
|
|
{
|
|
|
|
|
var entityLookup = IoCManager.Resolve<IEntityLookup>();
|
2021-10-27 19:27:25 +11:00
|
|
|
return entityLookup.GetEntitiesIntersecting(Owner, -0.015f, LookupFlags.Approximate);
|
2021-06-27 05:40:03 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-27 08:27:49 -06:00
|
|
|
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
if (eventArgs.Severity < ExplosionSeverity.Heavy)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 12:03:10 -06:00
|
|
|
var containedEntities = Contents.ContainedEntities.ToList();
|
|
|
|
|
foreach (var entity in containedEntities)
|
2020-08-27 08:27:49 -06:00
|
|
|
{
|
|
|
|
|
var exActs = entity.GetAllComponents<IExAct>().ToArray();
|
|
|
|
|
foreach (var exAct in exActs)
|
|
|
|
|
{
|
|
|
|
|
exAct.OnExplosion(eventArgs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 23:26:00 +02:00
|
|
|
}
|
|
|
|
|
}
|