Files
OldThink/Content.Server/Drone/DroneSystem.cs

135 lines
4.9 KiB
C#
Raw Normal View History

2022-02-10 17:15:06 -05:00
using Content.Shared.Drone;
using Content.Server.Drone.Components;
using Content.Shared.MobState;
using Content.Shared.MobState.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Interaction.Components;
2022-02-10 17:15:06 -05:00
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;
2022-02-15 21:00:36 -07:00
using Content.Shared.Emoting;
2022-02-10 17:15:06 -05:00
using Robust.Shared.Player;
using Content.Shared.Tag;
2022-02-20 01:02:05 -05:00
using Content.Shared.Throwing;
2022-02-10 17:15:06 -05:00
namespace Content.Server.Drone
{
2022-02-10 15:45:02 -07:00
public sealed class DroneSystem : SharedDroneSystem
2022-02-10 17:15:06 -05:00
{
[Dependency] private readonly PopupSystem _popupSystem = default!;
2022-02-10 15:45:02 -07:00
[Dependency] private readonly TagSystem _tagSystem = default!;
2022-02-10 17:15:06 -05:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DroneComponent, InteractionAttemptEvent>(OnInteractionAttempt);
SubscribeLocalEvent<DroneComponent, UserOpenActivatableUIAttemptEvent>(OnActivateUIAttempt);
2022-02-10 17:15:06 -05:00
SubscribeLocalEvent<DroneComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<DroneComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<DroneComponent, MindAddedMessage>(OnMindAdded);
SubscribeLocalEvent<DroneComponent, MindRemovedMessage>(OnMindRemoved);
2022-02-15 21:00:36 -07:00
SubscribeLocalEvent<DroneComponent, EmoteAttemptEvent>(OnEmoteAttempt);
2022-02-20 01:02:05 -05:00
SubscribeLocalEvent<DroneComponent, ThrowAttemptEvent>(OnThrowAttempt);
2022-02-10 17:15:06 -05:00
}
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();
}
2022-02-10 17:15:06 -05:00
private void OnExamined(EntityUid uid, DroneComponent component, ExaminedEvent args)
{
if (args.IsInDetailsRange)
{
if (TryComp<MindComponent>(uid, out var mind) && mind.HasMind)
{
args.PushMarkup(Loc.GetString("drone-active"));
}
else
{
args.PushMarkup(Loc.GetString("drone-dormant"));
}
}
}
private void OnMobStateChanged(EntityUid uid, DroneComponent drone, MobStateChangedEvent args)
{
if (args.Component.IsDead())
{
var body = Comp<SharedBodyComponent>(uid); //There's no way something can have a mobstate but not a body...
foreach (var item in drone.ToolUids)
{
EntityManager.DeleteEntity(item);
}
body.Gib();
EntityManager.DeleteEntity(uid);
}
}
private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args)
{
UpdateDroneAppearance(uid, DroneStatus.On);
2022-02-10 15:45:02 -07:00
_tagSystem.AddTag(uid, "DoorBumpOpener");
2022-02-10 17:15:06 -05:00
_popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, Filter.Pvs(uid));
if (drone.AlreadyAwoken == false)
{
var spawnCoord = Transform(uid).Coordinates;
if (drone.Tools.Count == 0) return;
if (TryComp<HandsComponent>(uid, out var hands) && hands.Count >= drone.Tools.Count)
{
foreach (var entry in drone.Tools)
{
var item = EntityManager.SpawnEntity(entry.PrototypeId, spawnCoord);
AddComp<UnremoveableComponent>(item);
2022-02-10 17:15:06 -05:00
hands.PutInHand(item);
drone.ToolUids.Add(item);
}
}
drone.AlreadyAwoken = true;
}
}
private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args)
{
UpdateDroneAppearance(uid, DroneStatus.Off);
2022-02-10 15:45:02 -07:00
_tagSystem.RemoveTag(uid, "DoorBumpOpener");
2022-02-10 17:15:06 -05:00
EnsureComp<GhostTakeoverAvailableComponent>(uid);
}
2022-02-15 21:00:36 -07:00
private void OnEmoteAttempt(EntityUid uid, DroneComponent component, EmoteAttemptEvent args)
{
// No.
args.Cancel();
}
2022-02-20 01:02:05 -05:00
private void OnThrowAttempt(EntityUid uid, DroneComponent drone, ThrowAttemptEvent args)
{
args.Cancel();
}
2022-02-10 17:15:06 -05:00
private void UpdateDroneAppearance(EntityUid uid, DroneStatus status)
{
if (TryComp<AppearanceComponent>(uid, out var appearance))
{
appearance.SetData(DroneVisuals.Status, status);
}
}
}
}