Partial buckling refactor (#29031)
* partial buckling refactor * git mv test * change test namespace * git mv test * Update test namespace * Add pulling test * Network BuckleTime * Add two more tests * smelly
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Alert;
|
||||
@@ -16,11 +15,9 @@ using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Pulling.Events;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
@@ -68,11 +65,26 @@ public sealed class PullingSystem : EntitySystem
|
||||
SubscribeLocalEvent<PullerComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
|
||||
SubscribeLocalEvent<PullerComponent, DropHandItemsEvent>(OnDropHandItems);
|
||||
|
||||
SubscribeLocalEvent<PullableComponent, StrappedEvent>(OnBuckled);
|
||||
SubscribeLocalEvent<PullableComponent, BuckledEvent>(OnGotBuckled);
|
||||
|
||||
CommandBinds.Builder
|
||||
.Bind(ContentKeyFunctions.ReleasePulledObject, InputCmdHandler.FromDelegate(OnReleasePulledObject, handle: false))
|
||||
.Register<PullingSystem>();
|
||||
}
|
||||
|
||||
private void OnBuckled(Entity<PullableComponent> ent, ref StrappedEvent args)
|
||||
{
|
||||
// Prevent people from pulling the entity they are buckled to
|
||||
if (ent.Comp.Puller == args.Buckle.Owner && !args.Buckle.Comp.PullStrap)
|
||||
StopPulling(ent, ent);
|
||||
}
|
||||
|
||||
private void OnGotBuckled(Entity<PullableComponent> ent, ref BuckledEvent args)
|
||||
{
|
||||
StopPulling(ent, ent);
|
||||
}
|
||||
|
||||
private void OnAfterState(Entity<PullerComponent> ent, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
if (ent.Comp.Pulling == null)
|
||||
@@ -94,7 +106,8 @@ public sealed class PullingSystem : EntitySystem
|
||||
|
||||
private void OnPullerContainerInsert(Entity<PullerComponent> ent, ref EntGotInsertedIntoContainerMessage args)
|
||||
{
|
||||
if (ent.Comp.Pulling == null) return;
|
||||
if (ent.Comp.Pulling == null)
|
||||
return;
|
||||
|
||||
if (!TryComp(ent.Comp.Pulling.Value, out PullableComponent? pulling))
|
||||
return;
|
||||
@@ -228,8 +241,18 @@ public sealed class PullingSystem : EntitySystem
|
||||
/// </summary>
|
||||
private void StopPulling(EntityUid pullableUid, PullableComponent pullableComp)
|
||||
{
|
||||
if (pullableComp.Puller == null)
|
||||
return;
|
||||
|
||||
if (!_timing.ApplyingState)
|
||||
{
|
||||
// Joint shutdown
|
||||
if (pullableComp.PullJointId != null)
|
||||
{
|
||||
_joints.RemoveJoint(pullableUid, pullableComp.PullJointId);
|
||||
pullableComp.PullJointId = null;
|
||||
}
|
||||
|
||||
if (TryComp<PhysicsComponent>(pullableUid, out var pullablePhysics))
|
||||
{
|
||||
_physics.SetFixedRotation(pullableUid, pullableComp.PrevFixedRotation, body: pullablePhysics);
|
||||
@@ -330,15 +353,6 @@ public sealed class PullingSystem : EntitySystem
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityManager.TryGetComponent(puller, out BuckleComponent? buckle))
|
||||
{
|
||||
// Prevent people pulling the chair they're on, etc.
|
||||
if (buckle is { PullStrap: false, Buckled: true } && (buckle.LastEntityBuckledTo == pullableUid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var getPulled = new BeingPulledAttemptEvent(puller, pullableUid);
|
||||
RaiseLocalEvent(pullableUid, getPulled, true);
|
||||
var startPull = new StartPullAttemptEvent(puller, pullableUid);
|
||||
@@ -382,11 +396,8 @@ public sealed class PullingSystem : EntitySystem
|
||||
if (!CanPull(pullerUid, pullableUid))
|
||||
return false;
|
||||
|
||||
if (!EntityManager.TryGetComponent<PhysicsComponent>(pullerUid, out var pullerPhysics) ||
|
||||
!EntityManager.TryGetComponent<PhysicsComponent>(pullableUid, out var pullablePhysics))
|
||||
{
|
||||
if (!HasComp<PhysicsComponent>(pullerUid) || !TryComp(pullableUid, out PhysicsComponent? pullablePhysics))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure that the puller is not currently pulling anything.
|
||||
if (TryComp<PullableComponent>(pullerComp.Pulling, out var oldPullable)
|
||||
@@ -431,7 +442,7 @@ public sealed class PullingSystem : EntitySystem
|
||||
{
|
||||
// Joint startup
|
||||
var union = _physics.GetHardAABB(pullerUid).Union(_physics.GetHardAABB(pullableUid, body: pullablePhysics));
|
||||
var length = Math.Max((float) union.Size.X, (float) union.Size.Y) * 0.75f;
|
||||
var length = Math.Max(union.Size.X, union.Size.Y) * 0.75f;
|
||||
|
||||
var joint = _joints.CreateDistanceJoint(pullableUid, pullerUid, id: pullableComp.PullJointId);
|
||||
joint.CollideConnected = false;
|
||||
@@ -475,17 +486,6 @@ public sealed class PullingSystem : EntitySystem
|
||||
if (msg.Cancelled)
|
||||
return false;
|
||||
|
||||
// Stop pulling confirmed!
|
||||
if (!_timing.ApplyingState)
|
||||
{
|
||||
// Joint shutdown
|
||||
if (pullable.PullJointId != null)
|
||||
{
|
||||
_joints.RemoveJoint(pullableUid, pullable.PullJointId);
|
||||
pullable.PullJointId = null;
|
||||
}
|
||||
}
|
||||
|
||||
StopPulling(pullableUid, pullable);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user