diff --git a/Content.Shared/Movement/Systems/SlowContactsSystem.cs b/Content.Shared/Movement/Systems/SlowContactsSystem.cs index 3118e80a20..1ee145075f 100644 --- a/Content.Shared/Movement/Systems/SlowContactsSystem.cs +++ b/Content.Shared/Movement/Systems/SlowContactsSystem.cs @@ -10,6 +10,8 @@ public sealed class SlowContactsSystem : EntitySystem [Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!; + // TODO full-game-save + // Either these need to be processed before a map is saved, or slowed/slowing entities need to update on init. private HashSet _toUpdate = new(); private HashSet _toRemove = new(); @@ -19,6 +21,7 @@ public sealed class SlowContactsSystem : EntitySystem SubscribeLocalEvent(OnEntityEnter); SubscribeLocalEvent(OnEntityExit); SubscribeLocalEvent(MovementSpeedCheck); + SubscribeLocalEvent(OnShutdown); UpdatesAfter.Add(typeof(SharedPhysicsSystem)); } @@ -56,6 +59,16 @@ public sealed class SlowContactsSystem : EntitySystem component.WalkSpeedModifier = walkSpeed; component.SprintSpeedModifier = sprintSpeed; Dirty(component); + _toUpdate.UnionWith(_physics.GetContactingEntities(uid)); + } + + private void OnShutdown(EntityUid uid, SlowContactsComponent component, ComponentShutdown args) + { + if (!TryComp(uid, out PhysicsComponent? phys)) + return; + + // Note that the entity may not be getting deleted here. E.g., glue puddles. + _toUpdate.UnionWith(_physics.GetContactingEntities(uid, phys)); } private void MovementSpeedCheck(EntityUid uid, SlowedByContactComponent component, RefreshMovementSpeedModifiersEvent args) @@ -90,8 +103,7 @@ public sealed class SlowContactsSystem : EntitySystem private void OnEntityExit(EntityUid uid, SlowContactsComponent component, ref EndCollideEvent args) { var otherUid = args.OtherEntity; - if (HasComp(otherUid)) - _toUpdate.Add(otherUid); + _toUpdate.Add(otherUid); } private void OnEntityEnter(EntityUid uid, SlowContactsComponent component, ref StartCollideEvent args)