Refactor drone tool checks (#6643)

This commit is contained in:
Rane
2022-02-12 19:14:24 -05:00
committed by GitHub
parent d8127d4a94
commit be853b2529
4 changed files with 20 additions and 32 deletions

View File

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

View File

@@ -1,21 +1,13 @@
using Content.Shared.Drone;
using Content.Server.Drone.Components;
using Content.Shared.Drone.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory.Events;
using Content.Shared.MobState.Components;
using Content.Shared.MobState;
using Content.Shared.DragDrop;
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.Actions.Events;
using Robust.Shared.IoC;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Player;
using Content.Shared.Tag;
@@ -29,8 +21,6 @@ namespace Content.Server.Drone
{
base.Initialize();
SubscribeLocalEvent<DroneComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DroneComponent, DisarmAttemptEvent>(OnDisarmAttempt);
SubscribeLocalEvent<DroneComponent, DropAttemptEvent>(OnDropAttempt);
SubscribeLocalEvent<DroneComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DroneComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<DroneComponent, MindRemovedMessage>(OnMindRemoved);
@@ -66,16 +56,6 @@ namespace Content.Server.Drone
}
}
private void OnDisarmAttempt(EntityUid uid, DroneComponent drone, DisarmAttemptEvent args)
{
TryComp<HandsComponent>(args.TargetUid, out var hands);
var item = hands?.GetActiveHandItem;
if (TryComp<DroneToolComponent>(item?.Owner, out var itemInHand))
{
args.Cancel();
}
}
private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args)
{
UpdateDroneAppearance(uid, DroneStatus.On);
@@ -110,16 +90,6 @@ namespace Content.Server.Drone
EnsureComp<GhostTakeoverAvailableComponent>(uid);
}
private void OnDropAttempt(EntityUid uid, DroneComponent drone, DropAttemptEvent args)
{
TryComp<HandsComponent>(uid, out var hands);
var item = hands?.GetActiveHandItem;
if (TryComp<DroneToolComponent>(item?.Owner, out var itemInHand))
{
args.Cancel();
}
}
private void UpdateDroneAppearance(EntityUid uid, DroneStatus status)
{
if (TryComp<AppearanceComponent>(uid, out var appearance))

View File

@@ -1,8 +1,10 @@
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,11 +1,23 @@
using System;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.Containers;
using Content.Shared.Drone.Components;
namespace Content.Shared.Drone
{
public abstract class SharedDroneSystem : EntitySystem
{
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
{