From 67661ddbdb9ab26e7d01add8a0dc93220fd14037 Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Fri, 18 Feb 2022 17:57:31 -0500 Subject: [PATCH] Drone Interaction Checks & Cleanup (#6731) --- Content.Client/Drone/DroneSystem.cs | 4 ---- Content.Server/Drone/DroneSystem.cs | 22 +++++++++++++++++-- .../UserInterface/ActivatableUISystem.cs | 18 +++++++++------ .../Drone/Components/DroneToolComponent.cs | 10 --------- Content.Shared/Drone/SharedDroneSystem.cs | 9 -------- .../Components/UnremoveableComponent.cs | 8 +++++++ .../Interaction/SharedInteractionSystem.cs | 12 ++++++++++ 7 files changed, 51 insertions(+), 32 deletions(-) delete mode 100644 Content.Client/Drone/DroneSystem.cs delete mode 100644 Content.Shared/Drone/Components/DroneToolComponent.cs create mode 100644 Content.Shared/Interaction/Components/UnremoveableComponent.cs diff --git a/Content.Client/Drone/DroneSystem.cs b/Content.Client/Drone/DroneSystem.cs deleted file mode 100644 index ab00c0f7b1..0000000000 --- a/Content.Client/Drone/DroneSystem.cs +++ /dev/null @@ -1,4 +0,0 @@ -using Content.Shared.Drone; -// yeah this is just required for prediction - -public sealed class DroneSystem : SharedDroneSystem {} diff --git a/Content.Server/Drone/DroneSystem.cs b/Content.Server/Drone/DroneSystem.cs index f6404804bb..174c8a1c14 100644 --- a/Content.Server/Drone/DroneSystem.cs +++ b/Content.Server/Drone/DroneSystem.cs @@ -1,13 +1,16 @@ using Content.Shared.Drone; using Content.Server.Drone.Components; -using Content.Shared.Drone.Components; using Content.Shared.MobState; +using Content.Shared.MobState.Components; +using Content.Shared.Interaction.Events; +using Content.Shared.Interaction.Components; using Content.Shared.Examine; using Content.Server.Popups; using Content.Server.Mind.Components; using Content.Server.Ghost.Roles.Components; using Content.Server.Hands.Components; using Content.Shared.Body.Components; +using Content.Server.UserInterface; using Content.Shared.Emoting; using Robust.Shared.Player; using Content.Shared.Tag; @@ -21,6 +24,8 @@ namespace Content.Server.Drone public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnInteractionAttempt); + SubscribeLocalEvent(OnActivateUIAttempt); SubscribeLocalEvent(OnMobStateChanged); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnMindAdded); @@ -28,6 +33,19 @@ namespace Content.Server.Drone SubscribeLocalEvent(OnEmoteAttempt); } + private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args) + { + if (HasComp(args.Target) && !HasComp(args.Target)) + { + args.Cancel(); + } + } + + private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args) + { + args.Cancel(); + } + private void OnExamined(EntityUid uid, DroneComponent component, ExaminedEvent args) { if (args.IsInDetailsRange) @@ -75,7 +93,7 @@ namespace Content.Server.Drone foreach (var entry in drone.Tools) { var item = EntityManager.SpawnEntity(entry.PrototypeId, spawnCoord); - AddComp(item); + AddComp(item); hands.PutInHand(item); drone.ToolUids.Add(item); } diff --git a/Content.Server/UserInterface/ActivatableUISystem.cs b/Content.Server/UserInterface/ActivatableUISystem.cs index 56b9982b03..c8bfc5e31c 100644 --- a/Content.Server/UserInterface/ActivatableUISystem.cs +++ b/Content.Server/UserInterface/ActivatableUISystem.cs @@ -1,17 +1,11 @@ -using System.Linq; using Content.Server.Administration.Managers; using Content.Server.Ghost.Components; -using Content.Shared.ActionBlocker; using Content.Shared.Hands; using Content.Shared.Interaction; -using Content.Shared.Popups; using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Server.GameObjects; using Robust.Server.Player; -using Robust.Shared.GameObjects; -using Robust.Shared.IoC; -using Robust.Shared.Localization; namespace Content.Server.UserInterface { @@ -95,8 +89,10 @@ namespace Content.Server.UserInterface // If we've gotten this far, fire a cancellable event that indicates someone is about to activate this. // This is so that stuff can require further conditions (like power). var oae = new ActivatableUIOpenAttemptEvent(user); + var uae = new UserOpenActivatableUIAttemptEvent(user); + RaiseLocalEvent(user, uae, false); RaiseLocalEvent((aui).Owner, oae, false); - if (oae.Cancelled) return false; + if (oae.Cancelled || uae.Cancelled) return false; SetCurrentSingleUser((aui).Owner, actor.PlayerSession, aui); ui.Toggle(actor.PlayerSession); @@ -131,6 +127,14 @@ namespace Content.Server.UserInterface } } + public class UserOpenActivatableUIAttemptEvent : CancellableEntityEventArgs //have to one-up the already stroke-inducing name + { + public EntityUid User { get; } + public UserOpenActivatableUIAttemptEvent(EntityUid who) + { + User = who; + } + } public sealed class ActivatableUIPlayerChangedEvent : EntityEventArgs { } diff --git a/Content.Shared/Drone/Components/DroneToolComponent.cs b/Content.Shared/Drone/Components/DroneToolComponent.cs deleted file mode 100644 index c43e3c5c45..0000000000 --- a/Content.Shared/Drone/Components/DroneToolComponent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Robust.Shared.GameObjects; -using Robust.Shared.Analyzers; -using Robust.Shared.GameStates; - -namespace Content.Shared.Drone.Components -{ - [RegisterComponent] - [NetworkedComponent] - public sealed class DroneToolComponent : Component {} -} diff --git a/Content.Shared/Drone/SharedDroneSystem.cs b/Content.Shared/Drone/SharedDroneSystem.cs index 1b29087a7a..985a18e4e4 100644 --- a/Content.Shared/Drone/SharedDroneSystem.cs +++ b/Content.Shared/Drone/SharedDroneSystem.cs @@ -1,6 +1,4 @@ using Robust.Shared.Serialization; -using Robust.Shared.Containers; -using Content.Shared.Drone.Components; namespace Content.Shared.Drone { @@ -9,15 +7,8 @@ namespace Content.Shared.Drone public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnRemoveAttempt); } - private void OnRemoveAttempt(EntityUid uid, DroneToolComponent tool, ContainerGettingRemovedAttemptEvent args) - { - args.Cancel(); - } - - [Serializable, NetSerializable] public enum DroneVisuals : byte { diff --git a/Content.Shared/Interaction/Components/UnremoveableComponent.cs b/Content.Shared/Interaction/Components/UnremoveableComponent.cs new file mode 100644 index 0000000000..b2fe954b3f --- /dev/null +++ b/Content.Shared/Interaction/Components/UnremoveableComponent.cs @@ -0,0 +1,8 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Interaction.Components +{ + [RegisterComponent] + [NetworkedComponent] + public sealed class UnremoveableComponent : Component {} +} diff --git a/Content.Shared/Interaction/SharedInteractionSystem.cs b/Content.Shared/Interaction/SharedInteractionSystem.cs index b4354af026..8874b7cc0c 100644 --- a/Content.Shared/Interaction/SharedInteractionSystem.cs +++ b/Content.Shared/Interaction/SharedInteractionSystem.cs @@ -8,6 +8,8 @@ using Content.Shared.CombatMode; using Content.Shared.Database; using Content.Shared.Hands.Components; using Content.Shared.Input; +using Content.Shared.Interaction.Helpers; +using Content.Shared.Interaction.Components; using Content.Shared.Physics; using Content.Shared.Popups; using Content.Shared.Throwing; @@ -54,6 +56,7 @@ namespace Content.Shared.Interaction { SubscribeLocalEvent(OnBoundInterfaceInteractAttempt); SubscribeAllEvent(HandleInteractInventorySlotEvent); + SubscribeLocalEvent(OnRemoveAttempt); CommandBinds.Builder .Bind(ContentKeyFunctions.AltActivateItemInWorld, @@ -91,6 +94,15 @@ namespace Content.Shared.Interaction } } + /// + /// Prevents an item with the Unremovable component from being removed from a container by almost any means + /// + private void OnRemoveAttempt(EntityUid uid, UnremoveableComponent item, ContainerGettingRemovedAttemptEvent args) + { + args.Cancel(); + } + + /// /// Handles the event were a client uses an item in their inventory or in their hands, either by /// alt-clicking it or pressing 'E' while hovering over it.