2022-05-13 00:59:03 -07:00
|
|
|
|
using Content.Shared.Body.Components;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Content.Shared.Disposal.Components;
|
2023-04-03 13:13:48 +12:00
|
|
|
|
using Content.Shared.DoAfter;
|
2022-01-30 17:53:22 +01:00
|
|
|
|
using Content.Shared.DragDrop;
|
2023-03-23 14:55:49 +00:00
|
|
|
|
using Content.Shared.Emag.Systems;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Content.Shared.Item;
|
2023-01-13 16:57:10 -08:00
|
|
|
|
using Content.Shared.Mobs.Components;
|
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Content.Shared.Throwing;
|
2020-08-24 20:41:15 +02:00
|
|
|
|
using JetBrains.Annotations;
|
2022-10-04 14:24:19 +11:00
|
|
|
|
using Robust.Shared.Physics.Components;
|
2022-09-14 17:26:26 +10:00
|
|
|
|
using Robust.Shared.Physics.Events;
|
2023-04-03 13:13:48 +12:00
|
|
|
|
using Robust.Shared.Serialization;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Robust.Shared.Timing;
|
2020-08-24 20:41:15 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Shared.Disposal
|
2020-08-24 20:41:15 +02:00
|
|
|
|
{
|
2023-04-03 13:13:48 +12:00
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
|
public sealed class DisposalDoAfterEvent : SimpleDoAfterEvent
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-24 20:41:15 +02:00
|
|
|
|
[UsedImplicitly]
|
2021-08-12 13:40:38 +10:00
|
|
|
|
public abstract class SharedDisposalUnitSystem : EntitySystem
|
2020-08-24 20:41:15 +02:00
|
|
|
|
{
|
2021-08-12 13:40:38 +10:00
|
|
|
|
[Dependency] protected readonly IGameTiming GameTiming = default!;
|
2023-01-13 16:57:10 -08:00
|
|
|
|
[Dependency] private readonly MobStateSystem _mobState = default!;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
|
|
|
|
|
|
protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
|
|
|
|
|
|
|
|
|
|
|
|
// Percentage
|
|
|
|
|
|
public const float PressurePerSecond = 0.05f;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
2020-08-24 20:41:15 +02:00
|
|
|
|
{
|
2021-08-12 13:40:38 +10:00
|
|
|
|
base.Initialize();
|
2022-01-30 17:53:22 +01:00
|
|
|
|
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(OnPreventCollide);
|
2023-02-14 00:29:34 +11:00
|
|
|
|
SubscribeLocalEvent<SharedDisposalUnitComponent, CanDropTargetEvent>(OnCanDragDropOn);
|
2023-03-23 14:55:49 +00:00
|
|
|
|
SubscribeLocalEvent<SharedDisposalUnitComponent, GotEmaggedEvent>(OnEmagged);
|
2021-08-12 13:40:38 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-03 13:13:48 +12:00
|
|
|
|
private void OnPreventCollide(EntityUid uid, SharedDisposalUnitComponent component,
|
|
|
|
|
|
ref PreventCollideEvent args)
|
2021-08-12 13:40:38 +10:00
|
|
|
|
{
|
2023-06-03 00:20:09 +12:00
|
|
|
|
var otherBody = args.OtherEntity;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
|
|
|
|
|
|
// Items dropped shouldn't collide but items thrown should
|
2022-07-27 03:53:47 -07:00
|
|
|
|
if (EntityManager.HasComponent<ItemComponent>(otherBody) &&
|
2021-09-28 13:35:29 +02:00
|
|
|
|
!EntityManager.HasComponent<ThrownItemComponent>(otherBody))
|
2020-08-24 20:41:15 +02:00
|
|
|
|
{
|
2022-09-14 17:26:26 +10:00
|
|
|
|
args.Cancelled = true;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
return;
|
2020-08-24 20:41:15 +02:00
|
|
|
|
}
|
2020-10-30 01:16:26 +01:00
|
|
|
|
|
2021-08-12 13:40:38 +10:00
|
|
|
|
if (component.RecentlyEjected.Contains(otherBody))
|
|
|
|
|
|
{
|
2022-09-14 17:26:26 +10:00
|
|
|
|
args.Cancelled = true;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-14 00:29:34 +11:00
|
|
|
|
private void OnCanDragDropOn(EntityUid uid, SharedDisposalUnitComponent component, ref CanDropTargetEvent args)
|
2022-01-30 17:53:22 +01:00
|
|
|
|
{
|
2023-02-14 00:29:34 +11:00
|
|
|
|
if (args.Handled)
|
|
|
|
|
|
return;
|
2022-01-30 17:53:22 +01:00
|
|
|
|
|
2023-06-21 07:31:19 -07:00
|
|
|
|
args.CanDrop = CanInsert(uid, component, args.Dragged);
|
2022-01-30 17:53:22 +01:00
|
|
|
|
args.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-23 14:55:49 +00:00
|
|
|
|
private void OnEmagged(EntityUid uid, SharedDisposalUnitComponent component, ref GotEmaggedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
component.DisablePressure = true;
|
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-21 07:31:19 -07:00
|
|
|
|
public virtual bool CanInsert(EntityUid uid, SharedDisposalUnitComponent component, EntityUid entity)
|
2021-08-12 13:40:38 +10:00
|
|
|
|
{
|
2023-06-21 07:31:19 -07:00
|
|
|
|
if (!EntityManager.GetComponent<TransformComponent>(uid).Anchored)
|
2021-08-12 13:40:38 +10:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Probably just need a disposable tag.
|
2022-07-27 03:53:47 -07:00
|
|
|
|
if (!EntityManager.TryGetComponent(entity, out ItemComponent? storable) &&
|
2022-10-23 00:46:28 +02:00
|
|
|
|
!EntityManager.HasComponent<BodyComponent>(entity))
|
2021-08-12 13:40:38 +10:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-08-14 07:57:25 +02:00
|
|
|
|
//Check if the entity is a mob and if mobs can be inserted
|
2022-10-04 14:24:19 +11:00
|
|
|
|
if (TryComp<MobStateComponent>(entity, out var damageState) && !component.MobsCanEnter)
|
2022-08-14 07:57:25 +02:00
|
|
|
|
return false;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
|
2022-10-04 14:24:19 +11:00
|
|
|
|
if (EntityManager.TryGetComponent(entity, out PhysicsComponent? physics) &&
|
|
|
|
|
|
(physics.CanCollide || storable != null))
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
2022-10-04 14:24:19 +11:00
|
|
|
|
return true;
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
2021-10-20 21:12:23 +02:00
|
|
|
|
|
2022-10-04 14:24:19 +11:00
|
|
|
|
return damageState != null && (!component.MobsCanEnter || _mobState.IsDead(entity, damageState));
|
2020-08-24 20:41:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|