Disposals chute make it go splat (#20848)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -16,7 +16,7 @@ public sealed partial class DisposalTubeComponent : Component
|
|||||||
public bool Connected;
|
public bool Connected;
|
||||||
|
|
||||||
[DataField]
|
[DataField]
|
||||||
public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg");
|
public SoundSpecifier ClangSound = new SoundPathSpecifier("/Audio/Effects/clang.ogg", AudioParams.Default.WithVolume(-5f));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Container of entities that are currently inside this tube
|
/// Container of entities that are currently inside this tube
|
||||||
|
|||||||
@@ -6,38 +6,54 @@ using Content.Server.Disposal.Unit.Components;
|
|||||||
using Content.Shared.Body.Components;
|
using Content.Shared.Body.Components;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Item;
|
using Content.Shared.Item;
|
||||||
using Robust.Server.GameObjects;
|
using Content.Shared.Throwing;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Map.Components;
|
using Robust.Shared.Map.Components;
|
||||||
using Robust.Shared.Physics.Components;
|
using Robust.Shared.Physics.Components;
|
||||||
using Robust.Shared.Physics.Systems;
|
using Robust.Shared.Physics.Systems;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
namespace Content.Server.Disposal.Unit.EntitySystems
|
namespace Content.Server.Disposal.Unit.EntitySystems
|
||||||
{
|
{
|
||||||
public sealed class DisposableSystem : EntitySystem
|
public sealed class DisposableSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly DisposalUnitSystem _disposalUnit = default!;
|
[Dependency] private readonly ThrowingSystem _throwing = default!;
|
||||||
[Dependency] private readonly DisposalTubeSystem _disposalTube = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
|
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = 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 DamageableSystem _damageable = 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 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()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
|
_disposalTubeQuery = GetEntityQuery<DisposalTubeComponent>();
|
||||||
|
_disposalUnitQuery = GetEntityQuery<DisposalUnitComponent>();
|
||||||
|
_metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||||
|
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||||
|
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
|
|
||||||
SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup);
|
SubscribeLocalEvent<DisposalHolderComponent, ComponentStartup>(OnComponentStartup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnComponentStartup(EntityUid uid, DisposalHolderComponent holder, ComponentStartup args)
|
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)
|
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))
|
if (!holder.Container.Insert(toInsert, EntityManager))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (TryComp<PhysicsComponent>(toInsert, out var physBody))
|
if (_physicsQuery.TryGetComponent(toInsert, out var physBody))
|
||||||
_physics.SetCanCollide(toInsert, false, body: physBody);
|
_physicsSystem.SetCanCollide(toInsert, false, body: physBody);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -61,7 +77,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
if (!Resolve(uid, ref holder))
|
if (!Resolve(uid, ref holder))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_container.CanInsert(toInsert, holder.Container))
|
if (!_containerSystem.CanInsert(toInsert, holder.Container))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -93,10 +109,9 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
var gridUid = holderTransform.GridUid;
|
var gridUid = holderTransform.GridUid;
|
||||||
if (TryComp<MapGridComponent>(gridUid, out var grid))
|
if (TryComp<MapGridComponent>(gridUid, out var grid))
|
||||||
{
|
{
|
||||||
var ducQuery = GetEntityQuery<DisposalUnitComponent>();
|
foreach (var contentUid in _maps.GetLocal(gridUid.Value, grid, holderTransform.Coordinates))
|
||||||
foreach (var contentUid in _map.GetLocal(gridUid.Value, grid, holderTransform.Coordinates))
|
|
||||||
{
|
{
|
||||||
if (ducQuery.TryGetComponent(contentUid, out duc))
|
if (_disposalUnitQuery.TryGetComponent(contentUid, out duc))
|
||||||
{
|
{
|
||||||
disposalId = contentUid;
|
disposalId = contentUid;
|
||||||
break;
|
break;
|
||||||
@@ -104,39 +119,43 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var physQuery = GetEntityQuery<PhysicsComponent>();
|
_entList.Clear();
|
||||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
_entList.AddRange(holder.Container.ContainedEntities);
|
||||||
var transformQuery = GetEntityQuery<TransformComponent>();
|
|
||||||
foreach (var entity in holder.Container.ContainedEntities.ToArray())
|
foreach (var entity in _entList)
|
||||||
{
|
{
|
||||||
RemComp<BeingDisposedComponent>(entity);
|
RemComp<BeingDisposedComponent>(entity);
|
||||||
|
|
||||||
var meta = metaQuery.GetComponent(entity);
|
var meta = _metaQuery.GetComponent(entity);
|
||||||
holder.Container.Remove(entity, EntityManager, meta: meta, reparent: false, force: true);
|
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)
|
if (xform.ParentUid != uid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (duc != null)
|
if (duc != null)
|
||||||
duc.Container.Insert(entity, EntityManager, xform, meta: meta);
|
duc.Container.Insert(entity, EntityManager, xform, meta: meta);
|
||||||
else
|
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)
|
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();
|
holder.Air.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +218,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
{
|
{
|
||||||
_damageable.TryChangeDamage(ent, to.DamageOnTurn);
|
_damageable.TryChangeDamage(ent, to.DamageOnTurn);
|
||||||
}
|
}
|
||||||
_audio.PlayPvs(to.ClangSound, toUid, AudioParams.Default.WithVolume(-5f));
|
_audio.PlayPvs(to.ClangSound, toUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -237,21 +256,21 @@ namespace Content.Server.Disposal.Unit.EntitySystems
|
|||||||
if (holder.TimeLeft > 0)
|
if (holder.TimeLeft > 0)
|
||||||
{
|
{
|
||||||
var progress = 1 - holder.TimeLeft / holder.StartingTime;
|
var progress = 1 - holder.TimeLeft / holder.StartingTime;
|
||||||
var origin = Transform(currentTube).Coordinates;
|
var origin = _xformQuery.GetComponent(currentTube).Coordinates;
|
||||||
var destination = holder.CurrentDirection.ToVec();
|
var destination = holder.CurrentDirection.ToVec();
|
||||||
var newPosition = destination * progress;
|
var newPosition = destination * progress;
|
||||||
|
|
||||||
// This is some supreme shit code.
|
// This is some supreme shit code.
|
||||||
_transform.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
_xformSystem.SetCoordinates(uid, origin.Offset(newPosition).WithEntityId(currentTube));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Past this point, we are performing inter-tube transfer!
|
// Past this point, we are performing inter-tube transfer!
|
||||||
// Remove current tube content
|
// 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
|
// Find next tube
|
||||||
var nextTube = _disposalTube.NextTubeFor(currentTube, holder.CurrentDirection);
|
var nextTube = _disposalTubeSystem.NextTubeFor(currentTube, holder.CurrentDirection);
|
||||||
if (!EntityManager.EntityExists(nextTube))
|
if (!EntityManager.EntityExists(nextTube))
|
||||||
{
|
{
|
||||||
ExitDisposals(uid, holder);
|
ExitDisposals(uid, holder);
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ namespace Content.Shared.Throwing
|
|||||||
|
|
||||||
private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
|
private void OnSleep(EntityUid uid, ThrownItemComponent thrownItem, ref PhysicsSleepEvent @event)
|
||||||
{
|
{
|
||||||
|
@event.Cancelled = true;
|
||||||
StopThrow(uid, thrownItem);
|
StopThrow(uid, thrownItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user