2021-08-12 13:40:38 +10:00
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
|
using Content.Shared.Disposal.Components;
|
|
|
|
|
|
using Content.Shared.Item;
|
2021-11-08 15:11:58 +01:00
|
|
|
|
using Content.Shared.MobState.Components;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Content.Shared.Throwing;
|
2020-08-24 20:41:15 +02:00
|
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Physics;
|
|
|
|
|
|
using Robust.Shared.Physics.Dynamics;
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
[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!;
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
SubscribeLocalEvent<SharedDisposalUnitComponent, PreventCollideEvent>(HandlePreventCollide);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void HandlePreventCollide(EntityUid uid, SharedDisposalUnitComponent component, PreventCollideEvent args)
|
|
|
|
|
|
{
|
2021-12-03 16:30:34 +01:00
|
|
|
|
var otherBody = args.BodyB.Owner;
|
2021-08-12 13:40:38 +10:00
|
|
|
|
|
|
|
|
|
|
// Items dropped shouldn't collide but items thrown should
|
2021-09-28 13:35:29 +02:00
|
|
|
|
if (EntityManager.HasComponent<SharedItemComponent>(otherBody) &&
|
|
|
|
|
|
!EntityManager.HasComponent<ThrownItemComponent>(otherBody))
|
2020-08-24 20:41:15 +02:00
|
|
|
|
{
|
2021-08-12 13:40:38 +10:00
|
|
|
|
args.Cancel();
|
|
|
|
|
|
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))
|
|
|
|
|
|
{
|
|
|
|
|
|
args.Cancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-04 12:59:44 +01:00
|
|
|
|
public virtual bool CanInsert(SharedDisposalUnitComponent component, EntityUid entity)
|
2021-08-12 13:40:38 +10:00
|
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (!EntityManager.GetComponent<TransformComponent>(component.Owner).Anchored)
|
2021-08-12 13:40:38 +10:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Probably just need a disposable tag.
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (!EntityManager.TryGetComponent(entity, out SharedItemComponent? storable) &&
|
|
|
|
|
|
!EntityManager.HasComponent<SharedBodyComponent>(entity))
|
2021-08-12 13:40:38 +10:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (!EntityManager.TryGetComponent(entity, out IPhysBody? physics) ||
|
2021-08-12 13:40:38 +10:00
|
|
|
|
!physics.CanCollide && storable == null)
|
2020-10-30 01:16:26 +01:00
|
|
|
|
{
|
2021-12-08 13:00:43 +01:00
|
|
|
|
if (!(EntityManager.TryGetComponent(entity, out MobStateComponent? damageState) && damageState.IsDead()))
|
2021-10-20 21:12:23 +02:00
|
|
|
|
{
|
2021-08-12 13:40:38 +10:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2020-10-30 01:16:26 +01:00
|
|
|
|
}
|
2021-10-20 21:12:23 +02:00
|
|
|
|
|
2021-08-12 13:40:38 +10:00
|
|
|
|
return true;
|
2020-08-24 20:41:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|