Fix some buckling bugs (#10759)

This commit is contained in:
Leon Friedrich
2022-08-22 12:44:37 +12:00
committed by GitHub
parent eb7804989d
commit ff37e69c0a
2 changed files with 26 additions and 0 deletions

View File

@@ -85,6 +85,9 @@ namespace Content.Server.Buckle.Systems
private void ContainerModifiedStrap(EntityUid uid, StrapComponent strap, ContainerModifiedMessage message)
{
if (GameTiming.ApplyingState)
return;
foreach (var buckledEntity in strap.BuckledEntities)
{
if (!EntityManager.TryGetComponent(buckledEntity, out BuckleComponent? buckled))

View File

@@ -5,11 +5,14 @@ using Content.Shared.Movement.Events;
using Content.Shared.Standing;
using Content.Shared.Throwing;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Timing;
namespace Content.Shared.Buckle
{
public abstract class SharedBuckleSystem : EntitySystem
{
[Dependency] protected readonly IGameTiming GameTiming = default!;
public override void Initialize()
{
base.Initialize();
@@ -28,6 +31,20 @@ namespace Content.Shared.Buckle
// TODO: This looks dirty af.
// On rotation of a strap, reattach all buckled entities.
// This fixes buckle offsets and draw depths.
// This is mega cursed. Please somebody save me from Mr Buckle's wild ride.
// Consider a chair that has a player strapped to it. Then the client receives a new server state, showing
// that the player entity has moved elsewhere, and the chair has rotated. If the client applies the player
// state, then the chairs transform comp state, and then the buckle state. The transform state will
// forcefully teleport the player back to the chair (client-side only). This causes even more issues if the
// chair was teleporting in from nullspace after having left PVS.
//
// One option is to just never trigger re-buckles during state application.
// another is to.. just not do this? Like wtf is this code. But I CBF with buckle atm.
if (GameTiming.ApplyingState)
return;
foreach (var buckledEntity in component.BuckledEntities)
{
if (!EntityManager.TryGetComponent(buckledEntity, out SharedBuckleComponent? buckled))
@@ -35,6 +52,12 @@ namespace Content.Shared.Buckle
continue;
}
if (!buckled.Buckled || buckled.LastEntityBuckledTo != uid)
{
Logger.Error($"A moving strap entity {ToPrettyString(uid)} attempted to re-parent an entity that does not 'belong' to it {ToPrettyString(buckledEntity)}");
continue;
}
buckled.ReAttach(component);
Dirty(buckled);
}