* Make barstools, PA components, and radiation collectors rotatable. Making barstools rotatable is so that people can spin on the barstool. (RP moment.) The other two are more "functional" changes for assembling a PA. * Allow rotating a rotate-while-anchored object if you're buckled to it. Barstool spinny * Fix bug with rotation of an object that someone is buckled to * BuckleSystem: Efficiency improvements with directed events * Don't need to unsubscribe anymore from events, so in BuckleSystem, just don't
123 lines
4.0 KiB
C#
123 lines
4.0 KiB
C#
#nullable enable
|
|
using Content.Server.GameObjects.Components.Buckle;
|
|
using Content.Server.GameObjects.Components.Strap;
|
|
using Content.Server.GameObjects.EntitySystems.Click;
|
|
using Content.Shared.Interfaces.GameObjects.Components;
|
|
using JetBrains.Annotations;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.GameObjects;
|
|
|
|
namespace Content.Server.GameObjects.EntitySystems
|
|
{
|
|
[UsedImplicitly]
|
|
internal sealed class BuckleSystem : EntitySystem
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
UpdatesAfter.Add(typeof(InteractionSystem));
|
|
UpdatesAfter.Add(typeof(InputSystem));
|
|
|
|
SubscribeLocalEvent<BuckleComponent, MoveEvent>(MoveEvent);
|
|
|
|
SubscribeLocalEvent<StrapComponent, RotateEvent>(RotateEvent);
|
|
|
|
SubscribeLocalEvent<BuckleComponent, EntInsertedIntoContainerMessage>(ContainerModifiedBuckle);
|
|
SubscribeLocalEvent<StrapComponent, EntInsertedIntoContainerMessage>(ContainerModifiedStrap);
|
|
|
|
SubscribeLocalEvent<BuckleComponent, EntRemovedFromContainerMessage>(ContainerModifiedBuckle);
|
|
SubscribeLocalEvent<StrapComponent, EntRemovedFromContainerMessage>(ContainerModifiedStrap);
|
|
|
|
SubscribeLocalEvent<BuckleComponent, AttackHandEvent>(HandleAttackHand);
|
|
}
|
|
|
|
private void HandleAttackHand(EntityUid uid, BuckleComponent component, AttackHandEvent args)
|
|
{
|
|
args.Handled = component.TryUnbuckle(args.User);
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
foreach (var comp in ComponentManager.EntityQuery<BuckleComponent>())
|
|
{
|
|
comp.Update();
|
|
}
|
|
}
|
|
|
|
private void MoveEvent(EntityUid uid, BuckleComponent buckle, MoveEvent ev)
|
|
{
|
|
var strap = buckle.BuckledTo;
|
|
|
|
if (strap == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var strapPosition = strap.Owner.Transform.Coordinates.Offset(buckle.BuckleOffset);
|
|
|
|
if (ev.NewPosition.InRange(EntityManager, strapPosition, 0.2f))
|
|
{
|
|
return;
|
|
}
|
|
|
|
buckle.TryUnbuckle(buckle.Owner, true);
|
|
}
|
|
|
|
private void RotateEvent(EntityUid uid, StrapComponent strap, RotateEvent ev)
|
|
{
|
|
// On rotation of a strap, reattach all buckled entities.
|
|
// This fixes buckle offsets and draw depths.
|
|
foreach (var buckledEntity in strap.BuckledEntities)
|
|
{
|
|
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
|
|
{
|
|
continue;
|
|
}
|
|
buckled.ReAttach(strap);
|
|
buckled.Dirty();
|
|
}
|
|
}
|
|
|
|
private void ContainerModifiedBuckle(EntityUid uid, BuckleComponent buckle, ContainerModifiedMessage message)
|
|
{
|
|
ContainerModifiedReAttach(buckle, buckle.BuckledTo);
|
|
}
|
|
private void ContainerModifiedStrap(EntityUid uid, StrapComponent strap, ContainerModifiedMessage message)
|
|
{
|
|
foreach (var buckledEntity in strap.BuckledEntities)
|
|
{
|
|
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
ContainerModifiedReAttach(buckled, strap);
|
|
}
|
|
}
|
|
|
|
private void ContainerModifiedReAttach(BuckleComponent buckle, StrapComponent? strap)
|
|
{
|
|
if (strap == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var contained = buckle.Owner.TryGetContainer(out var ownContainer);
|
|
var strapContained = strap.Owner.TryGetContainer(out var strapContainer);
|
|
|
|
if (contained != strapContained || ownContainer != strapContainer)
|
|
{
|
|
buckle.TryUnbuckle(buckle.Owner, true);
|
|
return;
|
|
}
|
|
|
|
if (!contained)
|
|
{
|
|
buckle.ReAttach(strap);
|
|
}
|
|
}
|
|
}
|
|
}
|