Drone Interaction Checks & Cleanup (#6731)

This commit is contained in:
Rane
2022-02-18 17:57:31 -05:00
committed by GitHub
parent 9f439f1d36
commit 67661ddbdb
7 changed files with 51 additions and 32 deletions

View File

@@ -1,4 +0,0 @@
using Content.Shared.Drone;
// yeah this is just required for prediction
public sealed class DroneSystem : SharedDroneSystem {}

View File

@@ -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<DroneComponent, InteractionAttemptEvent>(OnInteractionAttempt);
SubscribeLocalEvent<DroneComponent, UserOpenActivatableUIAttemptEvent>(OnActivateUIAttempt);
SubscribeLocalEvent<DroneComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DroneComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DroneComponent, MindAddedMessage>(OnMindAdded);
@@ -28,6 +33,19 @@ namespace Content.Server.Drone
SubscribeLocalEvent<DroneComponent, EmoteAttemptEvent>(OnEmoteAttempt);
}
private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args)
{
if (HasComp<MobStateComponent>(args.Target) && !HasComp<DroneComponent>(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<DroneToolComponent>(item);
AddComp<UnremoveableComponent>(item);
hands.PutInHand(item);
drone.ToolUids.Add(item);
}

View File

@@ -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
{
}

View File

@@ -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 {}
}

View File

@@ -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<DroneToolComponent, ContainerGettingRemovedAttemptEvent>(OnRemoveAttempt);
}
private void OnRemoveAttempt(EntityUid uid, DroneToolComponent tool, ContainerGettingRemovedAttemptEvent args)
{
args.Cancel();
}
[Serializable, NetSerializable]
public enum DroneVisuals : byte
{

View File

@@ -0,0 +1,8 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Interaction.Components
{
[RegisterComponent]
[NetworkedComponent]
public sealed class UnremoveableComponent : Component {}
}

View File

@@ -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<BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
SubscribeLocalEvent<UnremoveableComponent, ContainerGettingRemovedAttemptEvent>(OnRemoveAttempt);
CommandBinds.Builder
.Bind(ContentKeyFunctions.AltActivateItemInWorld,
@@ -91,6 +94,15 @@ namespace Content.Shared.Interaction
}
}
/// <summary>
/// Prevents an item with the Unremovable component from being removed from a container by almost any means
/// </summary>
private void OnRemoveAttempt(EntityUid uid, UnremoveableComponent item, ContainerGettingRemovedAttemptEvent args)
{
args.Cancel();
}
/// <summary>
/// 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.