Disposals chute make it go splat (#20848)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -6,38 +6,54 @@ using Content.Server.Disposal.Unit.Components;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Throwing;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
{
|
||||
public sealed class DisposableSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DisposalUnitSystem _disposalUnit = default!;
|
||||
[Dependency] private readonly DisposalTubeSystem _disposalTube = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly MapSystem _map = default!;
|
||||
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
[Dependency] private readonly DisposalUnitSystem _disposalUnitSystem = default!;
|
||||
[Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedMapSystem _maps = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physicsSystem = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
|
||||
|
||||
private EntityQuery<DisposalTubeComponent> _disposalTubeQuery;
|
||||
private EntityQuery<DisposalUnitComponent> _disposalUnitQuery;
|
||||
private EntityQuery<MetaDataComponent> _metaQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
private List<EntityUid> _entList = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_disposalTubeQuery = GetEntityQuery<DisposalTubeComponent>();
|
||||
_disposalUnitQuery = GetEntityQuery<DisposalUnitComponent>();
|
||||
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup);
|
||||
}
|
||||
|
||||
private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
|
||||
{
|
||||
holder.Container = _container.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent));
|
||||
holder.Container = _containerSystem.EnsureContainer<Container>(uid, nameof(DisposalHolderComponent));
|
||||
}
|
||||
|
||||
public bool TryInsert(EntityUid uid, EntityUid toInsert, DisposalHolderComponent? holder = null)
|
||||
@@ -50,8 +66,8 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
if (!holder.Container.Insert(toInsert, EntityManager))
|
||||
return false;
|
||||
|
||||
if (TryComp<PhysicsComponent>(toInsert, out var physBody))
|
||||
_physics.SetCanCollide(toInsert, false, body: physBody);
|
||||
if (_physicsQuery.TryGetComponent(toInsert, out var physBody))
|
||||
_physicsSystem.SetCanCollide(toInsert, false, body: physBody);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -61,7 +77,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
if (!Resolve(uid, ref holder))
|
||||
return false;
|
||||
|
||||
if (!_container.CanInsert(toInsert, holder.Container))
|
||||
if (!_containerSystem.CanInsert(toInsert, holder.Container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -93,10 +109,9 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
var gridUid = holderTransform.GridUid;
|
||||
if (TryComp<MapGridComponent>(gridUid, out var grid))
|
||||
{
|
||||
var ducQuery = GetEntityQuery<DisposalUnitComponent>();
|
||||
foreach (var contentUid in _map.GetLocal(gridUid.Value, grid, holderTransform.Coordinates))
|
||||
foreach (var contentUid in _maps.GetLocal(gridUid.Value, grid, holderTransform.Coordinates))
|
||||
{
|
||||
if (ducQuery.TryGetComponent(contentUid, out duc))
|
||||
if (_disposalUnitQuery.TryGetComponent(contentUid, out duc))
|
||||
{
|
||||
disposalId = contentUid;
|
||||
break;
|
||||
@@ -104,39 +119,43 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
}
|
||||
}
|
||||
|
||||
var physQuery = GetEntityQuery<PhysicsComponent>();
|
||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
var transformQuery = GetEntityQuery<TransformComponent>();
|
||||
foreach (var entity in holder.Container.ContainedEntities.ToArray())
|
||||
_entList.Clear();
|
||||
_entList.AddRange(holder.Container.ContainedEntities);
|
||||
|
||||
foreach (var entity in _entList)
|
||||
{
|
||||
RemComp<BeingDisposedComponent>(entity);
|
||||
|
||||
var meta = metaQuery.GetComponent(entity);
|
||||
var meta = _metaQuery.GetComponent(entity);
|
||||
holder.Container.Remove(entity, EntityManager, meta: meta, reparent: false, force: true);
|
||||
|
||||
var xform = transformQuery.GetComponent(entity);
|
||||
var xform = _xformQuery.GetComponent(entity);
|
||||
if (xform.ParentUid != uid)
|
||||
continue;
|
||||
|
||||
if (duc != null)
|
||||
duc.Container.Insert(entity, EntityManager, xform, meta: meta);
|
||||
else
|
||||
_transform.AttachToGridOrMap(entity, xform);
|
||||
|
||||
if (physQuery.TryGetComponent(entity, out var physics))
|
||||
{
|
||||
_physics.WakeBody(entity, body: physics);
|
||||
_xformSystem.AttachToGridOrMap(entity, xform);
|
||||
|
||||
if (holder.PreviousDirection != Direction.Invalid && _xformQuery.TryGetComponent(xform.ParentUid, out var parentXform))
|
||||
{
|
||||
var direction = holder.PreviousDirection.ToAngle();
|
||||
direction += _xformSystem.GetWorldRotation(parentXform);
|
||||
_throwing.TryThrow(entity, direction.ToWorldVec() * 3f, 10f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (disposalId != null && duc != null)
|
||||
{
|
||||
_disposalUnit.TryEjectContents(disposalId.Value, duc);
|
||||
_disposalUnitSystem.TryEjectContents(disposalId.Value, duc);
|
||||
}
|
||||
|
||||
if (_atmosphere.GetContainingMixture(uid, false, true) is { } environment)
|
||||
if (_atmosphereSystem.GetContainingMixture(uid, false, true) is { } environment)
|
||||
{
|
||||
_atmosphere.Merge(environment, holder.Air);
|
||||
_atmosphereSystem.Merge(environment, holder.Air);
|
||||
holder.Air.Clear();
|
||||
}
|
||||
|
||||
@@ -199,7 +218,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
{
|
||||
_damageable.TryChangeDamage(ent, to.DamageOnTurn);
|
||||
}
|
||||
_audio.PlayPvs(to.ClangSound, toUid, AudioParams.Default.WithVolume(-5f));
|
||||
_audio.PlayPvs(to.ClangSound, toUid);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -237,21 +256,21 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
||||
if (holder.TimeLeft > 0)
|
||||
{
|
||||
var progress = 1 - holder.TimeLeft / holder.StartingTime;
|
||||
var origin = Transform(currentTube).Coordinates;
|
||||
var origin = _xformQuery.GetComponent(currentTube).Coordinates;
|
||||
var destination = holder.CurrentDirection.ToVec();
|
||||
var newPosition = destination * progress;
|
||||
|
||||
// This is some supreme shit code.
|
||||
_transform.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
||||
_xformSystem.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Past this point, we are performing inter-tube transfer!
|
||||
// Remove current tube content
|
||||
Comp<DisposalTubeComponent>(currentTube).Contents.Remove(uid, reparent: false, force: true);
|
||||
_disposalTubeQuery.GetComponent(currentTube).Contents.Remove(uid, reparent: false, force: true);
|
||||
|
||||
// Find next tube
|
||||
var nextTube = _disposalTube.NextTubeFor(currentTube, holder.CurrentDirection);
|
||||
var nextTube = _disposalTubeSystem.NextTubeFor(currentTube, holder.CurrentDirection);
|
||||
if (!EntityManager.EntityExists(nextTube))
|
||||
{
|
||||
ExitDisposals(uid, holder);
|
||||
|
||||
Reference in New Issue
Block a user