2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Buckle.Components;
|
|
|
|
|
using Content.Server.Interaction;
|
|
|
|
|
using Content.Shared.Buckle;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Content.Shared.Verbs;
|
2020-07-24 14:22:28 +02:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Server.GameObjects;
|
2020-11-06 15:15:02 +01:00
|
|
|
using Robust.Shared.Containers;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-10-05 14:29:03 +11:00
|
|
|
using Robust.Shared.Localization;
|
2020-07-08 15:30:48 +02:00
|
|
|
|
2021-10-05 14:29:03 +11:00
|
|
|
namespace Content.Server.Buckle.Systems
|
2020-07-08 15:30:48 +02:00
|
|
|
{
|
2020-07-24 14:22:28 +02:00
|
|
|
[UsedImplicitly]
|
2021-05-30 23:30:44 +10:00
|
|
|
internal sealed class BuckleSystem : SharedBuckleSystem
|
2020-07-08 15:30:48 +02:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
UpdatesAfter.Add(typeof(InteractionSystem));
|
|
|
|
|
UpdatesAfter.Add(typeof(InputSystem));
|
2020-11-06 15:15:02 +01:00
|
|
|
|
2021-05-27 11:51:14 +01:00
|
|
|
SubscribeLocalEvent<BuckleComponent, MoveEvent>(MoveEvent);
|
2021-03-09 11:22:48 -08:00
|
|
|
|
2021-05-27 11:51:14 +01:00
|
|
|
SubscribeLocalEvent<StrapComponent, RotateEvent>(RotateEvent);
|
2021-03-09 11:22:48 -08:00
|
|
|
|
2021-05-27 11:51:14 +01:00
|
|
|
SubscribeLocalEvent<BuckleComponent, EntInsertedIntoContainerMessage>(ContainerModifiedBuckle);
|
|
|
|
|
SubscribeLocalEvent<StrapComponent, EntInsertedIntoContainerMessage>(ContainerModifiedStrap);
|
2021-04-09 16:08:12 +02:00
|
|
|
|
2021-05-27 11:51:14 +01:00
|
|
|
SubscribeLocalEvent<BuckleComponent, EntRemovedFromContainerMessage>(ContainerModifiedBuckle);
|
|
|
|
|
SubscribeLocalEvent<StrapComponent, EntRemovedFromContainerMessage>(ContainerModifiedStrap);
|
2021-04-09 16:08:12 +02:00
|
|
|
|
2021-06-08 19:10:29 -07:00
|
|
|
SubscribeLocalEvent<BuckleComponent, InteractHandEvent>(HandleInteractHand);
|
2021-10-05 14:29:03 +11:00
|
|
|
|
|
|
|
|
SubscribeLocalEvent<BuckleComponent, GetInteractionVerbsEvent>(AddUnbuckleVerb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddUnbuckleVerb(EntityUid uid, BuckleComponent component, GetInteractionVerbsEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!args.CanAccess || !args.CanInteract || !component.Buckled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Verb verb = new();
|
|
|
|
|
verb.Act = () => component.TryUnbuckle(args.User);
|
|
|
|
|
verb.Category = VerbCategory.Unbuckle;
|
|
|
|
|
|
|
|
|
|
if (args.Target == args.User && args.Using == null)
|
|
|
|
|
{
|
|
|
|
|
// A user is left clicking themselves with an empty hand, while buckled.
|
|
|
|
|
// It is very likely they are trying to unbuckle themselves.
|
|
|
|
|
verb.Priority = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args.Verbs.Add(verb);
|
2021-04-09 16:08:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-08 19:10:29 -07:00
|
|
|
private void HandleInteractHand(EntityUid uid, BuckleComponent component, InteractHandEvent args)
|
2021-03-09 11:22:48 -08:00
|
|
|
{
|
|
|
|
|
args.Handled = component.TryUnbuckle(args.User);
|
2020-11-06 12:38:24 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-18 20:12:53 +01:00
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
foreach (var (buckle, physics) in EntityManager.EntityQuery<BuckleComponent, PhysicsComponent>())
|
2020-12-18 20:12:53 +01:00
|
|
|
{
|
2021-05-30 23:30:44 +10:00
|
|
|
buckle.Update(physics);
|
2020-12-18 20:12:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 11:49:31 +02:00
|
|
|
private void MoveEvent(EntityUid uid, BuckleComponent buckle, ref MoveEvent ev)
|
2020-11-06 12:38:24 +01:00
|
|
|
{
|
2020-11-06 15:15:02 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 11:49:31 +02:00
|
|
|
private void RotateEvent(EntityUid uid, StrapComponent strap, ref RotateEvent ev)
|
2020-11-06 15:15:02 +01:00
|
|
|
{
|
2021-05-27 11:51:14 +01:00
|
|
|
// On rotation of a strap, reattach all buckled entities.
|
|
|
|
|
// This fixes buckle offsets and draw depths.
|
|
|
|
|
foreach (var buckledEntity in strap.BuckledEntities)
|
2020-11-06 12:38:24 +01:00
|
|
|
{
|
2021-05-27 11:51:14 +01:00
|
|
|
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
buckled.ReAttach(strap);
|
|
|
|
|
buckled.Dirty();
|
2020-11-06 15:15:02 +01:00
|
|
|
}
|
2021-05-27 11:51:14 +01:00
|
|
|
}
|
2020-11-06 15:15:02 +01:00
|
|
|
|
2021-05-27 11:51:14 +01:00
|
|
|
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)
|
2020-11-06 15:15:02 +01:00
|
|
|
{
|
2021-05-27 11:51:14 +01:00
|
|
|
if (!buckledEntity.TryGetComponent(out BuckleComponent? buckled))
|
2020-11-06 15:15:02 +01:00
|
|
|
{
|
2021-05-27 11:51:14 +01:00
|
|
|
continue;
|
2020-11-06 15:15:02 +01:00
|
|
|
}
|
2021-05-27 11:51:14 +01:00
|
|
|
|
|
|
|
|
ContainerModifiedReAttach(buckled, strap);
|
2020-11-06 12:38:24 +01:00
|
|
|
}
|
2020-07-08 15:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-11-06 15:15:02 +01:00
|
|
|
private void ContainerModifiedReAttach(BuckleComponent buckle, StrapComponent? strap)
|
2020-07-08 15:30:48 +02:00
|
|
|
{
|
2020-11-06 15:15:02 +01:00
|
|
|
if (strap == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-13 20:25:04 +13:00
|
|
|
var contained = buckle.Owner.TryGetContainer(out var ownContainer);
|
|
|
|
|
var strapContained = strap.Owner.TryGetContainer(out var strapContainer);
|
2020-11-06 15:15:02 +01:00
|
|
|
|
|
|
|
|
if (contained != strapContained || ownContainer != strapContainer)
|
|
|
|
|
{
|
|
|
|
|
buckle.TryUnbuckle(buckle.Owner, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!contained)
|
2020-07-08 15:30:48 +02:00
|
|
|
{
|
2020-11-06 15:15:02 +01:00
|
|
|
buckle.ReAttach(strap);
|
2020-07-08 15:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|