Files
OldThink/Content.Shared/Cuffs/SharedCuffableSystem.cs

134 lines
5.6 KiB
C#
Raw Normal View History

2022-04-10 16:48:11 +12:00
using Content.Shared.ActionBlocker;
2023-01-21 02:48:19 +13:00
using Content.Shared.Alert;
2021-06-17 00:37:05 +10:00
using Content.Shared.Cuffs.Components;
using Content.Shared.DragDrop;
using Content.Shared.Hands;
2023-01-21 02:48:19 +13:00
using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.Item;
using Content.Shared.Movement.Events;
2022-04-10 16:48:11 +12:00
using Content.Shared.Physics.Pull;
2021-06-17 00:37:05 +10:00
using Content.Shared.Pulling.Components;
using Content.Shared.Pulling.Events;
2023-01-21 02:48:19 +13:00
using Content.Shared.Rejuvenate;
using Robust.Shared.Containers;
2021-06-17 00:37:05 +10:00
namespace Content.Shared.Cuffs
{
public abstract class SharedCuffableSystem : EntitySystem
{
2022-04-10 16:48:11 +12:00
[Dependency] private readonly ActionBlockerSystem _blocker = default!;
2023-01-21 02:48:19 +13:00
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
2022-04-10 16:48:11 +12:00
2021-06-17 00:37:05 +10:00
public override void Initialize()
{
base.Initialize();
2023-01-21 02:48:19 +13:00
SubscribeLocalEvent<SharedCuffableComponent, EntRemovedFromContainerMessage>(OnCuffCountChanged);
SubscribeLocalEvent<SharedCuffableComponent, EntInsertedIntoContainerMessage>(OnCuffCountChanged);
SubscribeLocalEvent<SharedCuffableComponent, RejuvenateEvent>(OnRejuvenate);
2021-06-17 00:37:05 +10:00
SubscribeLocalEvent<SharedCuffableComponent, StopPullingEvent>(HandleStopPull);
2022-04-10 16:48:11 +12:00
SubscribeLocalEvent<SharedCuffableComponent, UpdateCanMoveEvent>(HandleMoveAttempt);
2022-09-29 23:38:24 +10:00
SubscribeLocalEvent<SharedCuffableComponent, AttackAttemptEvent>(CheckAct);
SubscribeLocalEvent<SharedCuffableComponent, UseAttemptEvent>(CheckAct);
SubscribeLocalEvent<SharedCuffableComponent, InteractionAttemptEvent>(CheckAct);
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
SubscribeLocalEvent<SharedCuffableComponent, IsEquippingAttemptEvent>(OnEquipAttempt);
SubscribeLocalEvent<SharedCuffableComponent, IsUnequippingAttemptEvent>(OnUnequipAttempt);
2022-09-29 23:38:24 +10:00
SubscribeLocalEvent<SharedCuffableComponent, DropAttemptEvent>(CheckAct);
SubscribeLocalEvent<SharedCuffableComponent, PickupAttemptEvent>(CheckAct);
SubscribeLocalEvent<SharedCuffableComponent, BeingPulledAttemptEvent>(OnBeingPulledAttempt);
SubscribeLocalEvent<SharedCuffableComponent, PullStartedMessage>(OnPull);
SubscribeLocalEvent<SharedCuffableComponent, PullStoppedMessage>(OnPull);
2022-04-10 16:48:11 +12:00
}
2023-01-21 02:48:19 +13:00
private void OnRejuvenate(EntityUid uid, SharedCuffableComponent component, RejuvenateEvent args)
{
_container.EmptyContainer(component.Container, true, attachToGridOrMap: true);
}
private void OnCuffCountChanged(EntityUid uid, SharedCuffableComponent component, ContainerModifiedMessage args)
{
if (args.Container == component.Container)
UpdateCuffState(uid, component);
}
public void UpdateCuffState(EntityUid uid, SharedCuffableComponent component)
{
var canInteract = TryComp(uid, out SharedHandsComponent? hands) && hands.Hands.Count > component.CuffedHandCount;
if (canInteract == component.CanStillInteract)
return;
component.CanStillInteract = canInteract;
Dirty(component);
_blocker.UpdateCanMove(uid);
if (component.CanStillInteract)
_alerts.ClearAlert(uid, AlertType.Handcuffed);
else
_alerts.ShowAlert(uid, AlertType.Handcuffed);
var ev = new CuffedStateChangeEvent();
RaiseLocalEvent(uid, ref ev);
}
private void OnBeingPulledAttempt(EntityUid uid, SharedCuffableComponent component, BeingPulledAttemptEvent args)
{
if (!TryComp<SharedPullableComponent>(uid, out var pullable))
return;
if (pullable.Puller != null && !component.CanStillInteract) // If we are being pulled already and cuffed, we can't get pulled again.
args.Cancel();
}
2022-04-10 16:48:11 +12:00
private void OnPull(EntityUid uid, SharedCuffableComponent component, PullMessage args)
{
if (!component.CanStillInteract)
_blocker.UpdateCanMove(uid);
}
2022-04-10 16:48:11 +12:00
private void HandleMoveAttempt(EntityUid uid, SharedCuffableComponent component, UpdateCanMoveEvent args)
{
if (component.CanStillInteract || !EntityManager.TryGetComponent(uid, out SharedPullableComponent? pullable) || !pullable.BeingPulled)
return;
args.Cancel();
2021-06-17 00:37:05 +10:00
}
private void HandleStopPull(EntityUid uid, SharedCuffableComponent component, StopPullingEvent args)
{
2021-12-06 15:39:46 +11:00
if (args.User == null || !EntityManager.EntityExists(args.User.Value)) return;
2021-06-17 00:37:05 +10:00
2021-12-06 15:39:46 +11:00
if (args.User.Value == component.Owner && !component.CanStillInteract)
2021-06-17 00:37:05 +10:00
{
args.Cancel();
}
}
#region ActionBlocker
private void CheckAct(EntityUid uid, SharedCuffableComponent component, CancellableEntityEventArgs args)
{
if (!component.CanStillInteract)
args.Cancel();
}
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
private void OnEquipAttempt(EntityUid uid, SharedCuffableComponent component, IsEquippingAttemptEvent args)
{
2022-01-02 06:03:29 +13:00
// is this a self-equip, or are they being stripped?
if (args.Equipee == uid)
CheckAct(uid, component, args);
}
get that crap outta here (completely rewrites inventorysystem) (#5807) * some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable:tm: * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge:tm: * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
2021-12-30 22:56:10 +01:00
private void OnUnequipAttempt(EntityUid uid, SharedCuffableComponent component, IsUnequippingAttemptEvent args)
{
2022-01-02 06:03:29 +13:00
// is this a self-equip, or are they being stripped?
if (args.Unequipee == uid)
CheckAct(uid, component, args);
}
#endregion
2021-06-17 00:37:05 +10:00
}
}