CatStation/Content.Shared/Disposal/Unit/SharedBeingDisposedSystem.cs
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

85 lines
3.2 KiB
C#

using Content.Shared.Disposal.Components;
using Content.Shared.Disposal.Holder;
using Content.Shared.Follower;
using Content.Shared.Follower.Components;
using Content.Shared.Interaction.Events;
namespace Content.Shared.Disposal.Unit;
/// <summary>
/// This system handles entities that are currently being flushed through
/// the disposals system. These entities should all have a temporary
/// <see cref="BeingDisposedComponent"/>.
/// </summary>
public abstract partial class SharedBeingDisposedSystem : EntitySystem
{
[Dependency] private SharedDisposalHolderSystem _disposalHolder = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BeingDisposedComponent, DisposalSystemTransitionEvent>(OnTransition);
SubscribeLocalEvent<BeingDisposedComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<BeingDisposedComponent, EntityStartedFollowingEvent>(OnStartedFollowing);
SubscribeLocalEvent<BeingDisposedComponent, EntityStoppedFollowingEvent>(OnStoppedFollowing);
SubscribeLocalEvent<BeingDisposedComponent, InteractionAttemptEvent>(OnInteractionAttempt);
SubscribeLocalEvent<BeingDisposedComponent, AttackAttemptEvent>(OnAttackAttempt);
}
private void OnTransition(Entity<BeingDisposedComponent> ent, ref DisposalSystemTransitionEvent args)
{
if (!TryComp<DisposalHolderComponent>(ent.Comp.Holder, out var holder))
return;
if (!TryComp<FollowedComponent>(ent, out var followed))
return;
// Any followers of the entity will also be attached to its disposal holder.
// This is so that movement under subfloors can be predicted by follower clients.
foreach (var follower in followed.Following)
{
_disposalHolder.AttachEntity((ent.Comp.Holder, holder), follower);
}
}
private void OnShutdown(Entity<BeingDisposedComponent> ent, ref ComponentShutdown args)
{
// Remove followers from the disposal holder
if (!TryComp<FollowedComponent>(ent, out var followed))
return;
foreach (var follower in followed.Following)
{
_disposalHolder.DetachEntity(follower);
}
}
private void OnStartedFollowing(Entity<BeingDisposedComponent> ent, ref EntityStartedFollowingEvent args)
{
// Attach new followers to the disposal holder to prevent mispredicts
if (!TryComp<DisposalHolderComponent>(ent.Comp.Holder, out var holder))
return;
_disposalHolder.AttachEntity((ent.Comp.Holder, holder), args.Follower);
}
private void OnStoppedFollowing(Entity<BeingDisposedComponent> ent, ref EntityStoppedFollowingEvent args)
{
// Remove departing followers from the disposal holder
_disposalHolder.DetachEntity(args.Follower);
}
private void OnInteractionAttempt(Entity<BeingDisposedComponent> ent, ref InteractionAttemptEvent args)
{
// Prevent interactions while travelling through disposals
args.Cancelled = true;
}
private void OnAttackAttempt(Entity<BeingDisposedComponent> ent, ref AttackAttemptEvent args)
{
// Prevent attacking while travelling through disposals
args.Cancel();
}
}