More rotatability (#4067)

* 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
This commit is contained in:
20kdc
2021-05-27 11:51:14 +01:00
committed by GitHub
parent 79a13f32e7
commit c7f104cd93
6 changed files with 60 additions and 39 deletions

View File

@@ -20,24 +20,19 @@ namespace Content.Server.GameObjects.EntitySystems
UpdatesAfter.Add(typeof(InteractionSystem));
UpdatesAfter.Add(typeof(InputSystem));
SubscribeLocalEvent<MoveEvent>(MoveEvent);
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(ContainerModified);
SubscribeLocalEvent<EntRemovedFromContainerMessage>(ContainerModified);
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);
}
public override void Shutdown()
{
base.Shutdown();
UnsubscribeLocalEvent<MoveEvent>();
UnsubscribeLocalEvent<EntInsertedIntoContainerMessage>();
UnsubscribeLocalEvent<EntRemovedFromContainerMessage>();
UnsubscribeLocalEvent<BuckleComponent, AttackHandEvent>(HandleAttackHand);
}
private void HandleAttackHand(EntityUid uid, BuckleComponent component, AttackHandEvent args)
{
args.Handled = component.TryUnbuckle(args.User);
@@ -51,13 +46,8 @@ namespace Content.Server.GameObjects.EntitySystems
}
}
private void MoveEvent(MoveEvent ev)
private void MoveEvent(EntityUid uid, BuckleComponent buckle, MoveEvent ev)
{
if (!ev.Sender.TryGetComponent(out BuckleComponent? buckle))
{
return;
}
var strap = buckle.BuckledTo;
if (strap == null)
@@ -75,25 +65,35 @@ namespace Content.Server.GameObjects.EntitySystems
buckle.TryUnbuckle(buckle.Owner, true);
}
private void ContainerModified(ContainerModifiedMessage message)
private void RotateEvent(EntityUid uid, StrapComponent strap, RotateEvent ev)
{
// Not returning is necessary in case an entity has both a buckle and strap component
if (message.Entity.TryGetComponent(out BuckleComponent? buckle))
// On rotation of a strap, reattach all buckled entities.
// This fixes buckle offsets and draw depths.
foreach (var buckledEntity in strap.BuckledEntities)
{
ContainerModifiedReAttach(buckle, buckle.BuckledTo);
}
if (message.Entity.TryGetComponent(out StrapComponent? strap))
{
foreach (var buckledEntity in strap.BuckledEntities)
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
{
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
{
continue;
}
ContainerModifiedReAttach(buckled, strap);
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);
}
}