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-12-03 14:05:23 +01:00
|
|
|
using Robust.Shared.IoC;
|
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
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
SubscribeLocalEvent<BuckleComponent, GetVerbsEvent<InteractionVerb>>(AddUnbuckleVerb);
|
2021-10-05 14:29:03 +11:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
private void AddUnbuckleVerb(EntityUid uid, BuckleComponent component, GetVerbsEvent<InteractionVerb> args)
|
2021-10-05 14:29:03 +11:00
|
|
|
{
|
|
|
|
|
if (!args.CanAccess || !args.CanInteract || !component.Buckled)
|
|
|
|
|
return;
|
2021-12-03 14:05:23 +01:00
|
|
|
|
2022-02-10 15:30:59 +13:00
|
|
|
InteractionVerb verb = new()
|
2021-12-29 15:57:20 +11:00
|
|
|
{
|
|
|
|
|
Act = () => component.TryUnbuckle(args.User),
|
|
|
|
|
Text = Loc.GetString("verb-categories-unbuckle"),
|
|
|
|
|
IconTexture = "/Textures/Interface/VerbIcons/unbuckle.svg.192dpi.png"
|
|
|
|
|
};
|
2021-10-05 14:29:03 +11:00
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-08 13:00:43 +01:00
|
|
|
var strapPosition = EntityManager.GetComponent<TransformComponent>(strap.Owner).Coordinates.Offset(buckle.BuckleOffset);
|
2020-11-06 15:15:02 +01:00
|
|
|
|
2021-12-29 15:57:20 +11:00
|
|
|
if (ev.NewPosition.InRange(EntityManager, strapPosition, strap.MaxBuckleDistance))
|
2020-11-06 15:15:02 +01:00
|
|
|
{
|
|
|
|
|
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-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(buckledEntity, out BuckleComponent? buckled))
|
2021-05-27 11:51:14 +01:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
buckled.ReAttach(strap);
|
2022-02-02 17:34:25 +11:00
|
|
|
Dirty(buckled);
|
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-12-08 13:00:43 +01:00
|
|
|
if (!EntityManager.TryGetComponent(buckledEntity, 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|