Files
space-station-14/Content.Server/Disposal/Holder/DisposalHolderSystem.cs
T
chromiumboy 2ca5d9d81a Disposals refactor (#40540)
* Initial commit

* Added pods

* Transit tubes should no longer connect with disposal pipes

* Updated the transit tube sprites

* Revisited how the transit tubes work

* Fixing merge conflict

* Updated sprites

* Simplified disposal component collections and updated yaml

* Moved the majority of the disposals code to Shared

* Move disposed ents via physics

* Disposal unit now use generic visualizers

* Followers of disposed entities have predicted movement

* Made BeingDisposedSystem shared

* Added documentation for some components

* Code clean up

* Removed unneeded container entries, tubes use directions instead of angles

* Many EntityUid/Comp -> Entity<Comp> changes

* Updated DisposableSystem

* Review of DisposalTubeSystem

* Review of DisposalUnitSystem

* Review of DisposalSignalRouterSystem

* Unit updates

* Fixing merge conflict

* Merge conflict resolved

* Re-organization of systems and components

* Allow trapped entities to escape endless loops

* Fix for item ejection

* UI updates

* Minor tweak

* Fixes for transit tubes

* Removed placeholder sprite

* Removed transit tubes (for now)

* Moved exit stun time to DisposalHolderComponent

* Added a limit on the amount of damage that can sustained from disposals travel

* Fix for PVS-related sound issues

* Added a limit on the number of entities that can be inserted into units

* Clean up

* Undid file scoping

* Fixed test fail

* Fixed test fail

* Increased min default capacity of disposal units

* Fixed audio spam occurring when dumping multiple items into a disposal unit

* Tile prying now occurs whenever exiting an open pipe

* Prevent attacking and interactions while traveling through disposals

* Added generic verbs for entering/exiting disposal units

* Fixed UI prediction bug

* Bug fixes

* Small improvements

* Moved the disposal holder prototype from the disposal entry to the unit

* Minor clean up

* Added support for a disposal holder despawn effect

* Added prediction guard

* Test fail fix

* Re-added new escape behavior

* Removed outdated PVS code

* Clean up

* More escape behavior changes

* More clean up

* Updated exit selection logic

* Bug fix

* More clean up

* Split up disposal unit code

* Cleaned up disposal units some more

* Adjusted exit throw distance

* Capitalized disposal and mailing unit window titles

* Bug fixes

* Taggers and routers show existing tags when the UI opens

* Fixed test fail

* test fail fix

* Minor performance improvement

* Minor improvement in pathing

* merge conflicts

* Fix heisentest

* Fixed mispredict

* Updated system referencing conventions

* Updated to account for changes made to the code

* Attempting to fix submodule issue

* Addressing test fails

* Additional fixes for tests

* Addressing reviewer comments

* Cleaned up exit randomization

* T-ray can see disposal pipes when in 'pipe' mode

* Fix for flush animation flickering

* mild thing

* fix both

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2026-05-27 04:38:03 +00:00

180 lines
6.5 KiB
C#

using Content.Server.Atmos.EntitySystems;
using Content.Shared.Disposal.Components;
using Content.Shared.Disposal.Holder;
using Content.Shared.Disposal.Tube;
using Content.Shared.Disposal.Unit;
using Content.Shared.Maps;
using Content.Shared.Stunnable;
using Content.Shared.Throwing;
using Robust.Shared.Containers;
using Robust.Shared.Map.Components;
using Robust.Shared.Network;
using Robust.Shared.Random;
namespace Content.Server.Disposal.Holder;
/// <inheritdoc/>
public sealed partial class DisposalHolderSystem : SharedDisposalHolderSystem
{
[Dependency] private AtmosphereSystem _atmos = default!;
[Dependency] private SharedTransformSystem _xform = default!;
[Dependency] private IRobustRandom _random = default!;
[Dependency] private ThrowingSystem _throwing = default!;
[Dependency] private SharedDisposalUnitSystem _disposalUnit = default!;
[Dependency] private SharedContainerSystem _container = default!;
[Dependency] private SharedMapSystem _maps = default!;
[Dependency] private INetManager _net = default!;
[Dependency] private SharedStunSystem _stun = default!;
[Dependency] private TileSystem _tile = default!;
private EntityQuery<DisposalUnitComponent> _disposalUnitQuery;
private EntityQuery<MetaDataComponent> _metaQuery;
private EntityQuery<TransformComponent> _xformQuery;
public override void Initialize()
{
base.Initialize();
_disposalUnitQuery = GetEntityQuery<DisposalUnitComponent>();
_metaQuery = GetEntityQuery<MetaDataComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
}
/// <inheritdoc/>
public override void TransferAtmos(Entity<DisposalHolderComponent> ent, Entity<DisposalUnitComponent> unit)
{
_atmos.Merge(ent.Comp.Air, unit.Comp.Air);
unit.Comp.Air.Clear();
}
/// <inheritdoc/>
protected override void ExpelAtmos(Entity<DisposalHolderComponent> ent)
{
if (_atmos.GetContainingMixture(ent.Owner, false, true) is { } environment)
{
_atmos.Merge(environment, ent.Comp.Air);
ent.Comp.Air.Clear();
}
}
/// <inheritdoc/>
public override void Exit(Entity<DisposalHolderComponent> ent)
{
if (Terminating(ent))
return;
if (ent.Comp.IsExiting)
return;
ent.Comp.IsExiting = true;
Dirty(ent);
// Get the holder and grid transforms
var xform = _xformQuery.GetComponent(ent);
var gridUid = xform.GridUid;
_xformQuery.TryGetComponent(gridUid, out var gridXform);
// Determine the exit angle of the ejected entities
var exitDirection = ent.Comp.CurrentDirection;
Angle? exitAngle = exitDirection != Direction.Invalid ? exitDirection.ToAngle() : null;
// Check for a disposal unit to throw them into and then eject them from it.
// *This ejection also makes the target not collide with the unit.*
// *This is on purpose.*
Entity<DisposalUnitComponent>? unit = null;
if (TryComp<MapGridComponent>(gridUid, out var grid))
{
foreach (var contentUid in _maps.GetLocal(gridUid.Value, grid, xform.Coordinates))
{
if (_disposalUnitQuery.TryGetComponent(contentUid, out var disposalUnit))
{
unit = new(contentUid, disposalUnit);
break;
}
}
// If no disposal unit was found, this exit will be a little messy
if (unit == null && _net.IsServer)
{
// Pry up the tile that the pipe was under
var tileRef = _maps.GetTileRef((gridUid.Value, grid), xform.Coordinates);
_tile.PryTile(tileRef);
// Also pry up the tile infront of the pipe
if (exitAngle != null)
{
tileRef = _maps.GetTileRef((gridUid.Value, grid), xform.Coordinates.Offset(exitAngle.Value.ToWorldVec()));
_tile.PryTile(tileRef);
}
}
}
// Update the exit angle here to account for the grid's rotation
if (exitAngle != null && gridXform != null)
{
exitAngle += _xform.GetWorldRotation(gridXform);
}
// We're purposely iterating over all the holder's children
// because the holder might have something teleported into it,
// outside the usual container insertion logic.
var children = xform.ChildEnumerator;
while (children.MoveNext(out var held))
{
DetachEntity(held);
var heldMeta = _metaQuery.GetComponent(held);
var heldXform = _xformQuery.GetComponent(held);
// Insert the child into the found disposal unit, then pop them out
if (unit != null && unit.Value.Comp.Container != null && _container.Insert((held, heldXform, heldMeta), unit.Value.Comp.Container))
{
_disposalUnit.Remove(unit.Value, held);
}
else
{
// Otherwise remove the child from the holder and prepare to throw it
if (ent.Comp.Container != null && ent.Comp.Container.Contains(held))
{
_container.Remove((held, null, heldMeta), ent.Comp.Container, force: true);
}
_xform.AttachToGridOrMap(held, heldXform);
// Knockdown the entity
_stun.TryKnockdown(held, ent.Comp.ExitStunDuration, force: true);
// Throw the entity
if (exitAngle != null && heldXform.ParentUid.IsValid())
{
_throwing.TryThrow(held, exitAngle.Value.ToWorldVec() * ent.Comp.ExitDistanceMultiplier, ent.Comp.TraversalSpeed * ent.Comp.ExitSpeedMultiplier);
}
}
}
ExpelAtmos(ent);
Del(ent.Owner);
}
/// <inheritdoc/>
protected override bool TryEscaping(Entity<DisposalHolderComponent> ent, Entity<DisposalTubeComponent> tube)
{
// Check if the entity should have a chance to escape yet
if (ent.Comp.DirectionChangeCount < ent.Comp.DirectionChangeThreshold)
return false;
// Check if the holder escaped
if (_random.NextFloat() > ent.Comp.EscapeChance)
return false;
// Unanchor the tube and exit
var xform = Transform(tube);
_xform.Unanchor(tube, xform);
Exit(ent);
return true;
}
}