2022-10-23 00:46:28 +02:00
|
|
|
using Content.Server.Body.Systems;
|
2022-02-10 17:15:06 -05:00
|
|
|
using Content.Server.Drone.Components;
|
2022-03-07 06:46:36 -05:00
|
|
|
using Content.Server.Ghost.Components;
|
2022-02-10 17:15:06 -05:00
|
|
|
using Content.Server.Ghost.Roles.Components;
|
2022-10-23 00:46:28 +02:00
|
|
|
using Content.Server.Mind.Components;
|
|
|
|
|
using Content.Server.Popups;
|
2022-08-31 22:09:20 -04:00
|
|
|
using Content.Server.Tools.Innate;
|
2022-02-18 17:57:31 -05:00
|
|
|
using Content.Server.UserInterface;
|
2022-10-23 00:46:28 +02:00
|
|
|
using Content.Shared.Body.Components;
|
|
|
|
|
using Content.Shared.Drone;
|
|
|
|
|
using Content.Shared.Emoting;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.IdentityManagement;
|
|
|
|
|
using Content.Shared.Interaction.Components;
|
|
|
|
|
using Content.Shared.Interaction.Events;
|
|
|
|
|
using Content.Shared.Item;
|
2023-01-13 16:57:10 -08:00
|
|
|
using Content.Shared.Mobs;
|
|
|
|
|
using Content.Shared.Mobs.Components;
|
|
|
|
|
using Content.Shared.Mobs.Systems;
|
2022-10-23 00:46:28 +02:00
|
|
|
using Content.Shared.Popups;
|
|
|
|
|
using Content.Shared.Tag;
|
|
|
|
|
using Content.Shared.Throwing;
|
2023-02-02 17:34:53 +01:00
|
|
|
using Robust.Server.GameObjects;
|
2022-02-10 17:15:06 -05:00
|
|
|
using Robust.Shared.Player;
|
2022-03-13 05:53:01 -04:00
|
|
|
using Robust.Shared.Timing;
|
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
|
|
|
{
|
2022-10-23 00:46:28 +02:00
|
|
|
[Dependency] private readonly BodySystem _bodySystem = default!;
|
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-03-07 06:46:36 -05:00
|
|
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
2022-03-13 05:53:01 -04:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2022-08-31 22:09:20 -04:00
|
|
|
[Dependency] private readonly InnateToolSystem _innateToolSystem = default!;
|
2022-12-19 19:25:35 -08:00
|
|
|
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
2023-02-02 17:34:53 +01:00
|
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
2022-03-13 05:53:01 -04:00
|
|
|
|
2022-02-10 17:15:06 -05:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2022-02-18 17:57:31 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-02-18 17:57:31 -05:00
|
|
|
private void OnInteractionAttempt(EntityUid uid, DroneComponent component, InteractionAttemptEvent args)
|
|
|
|
|
{
|
2022-03-13 05:53:01 -04:00
|
|
|
if (args.Target != null && !HasComp<UnremoveableComponent>(args.Target) && NonDronesInRange(uid, component))
|
2022-02-18 17:57:31 -05:00
|
|
|
args.Cancel();
|
2022-03-07 06:46:36 -05:00
|
|
|
|
2022-07-27 03:53:47 -07:00
|
|
|
if (HasComp<ItemComponent>(args.Target) && !HasComp<UnremoveableComponent>(args.Target))
|
2022-03-07 06:46:36 -05:00
|
|
|
{
|
|
|
|
|
if (!_tagSystem.HasAnyTag(args.Target.Value, "DroneUsable", "Trash"))
|
|
|
|
|
args.Cancel();
|
2022-02-18 17:57:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivateUIAttempt(EntityUid uid, DroneComponent component, UserOpenActivatableUIAttemptEvent args)
|
|
|
|
|
{
|
2022-03-12 13:26:06 -05:00
|
|
|
if (!_tagSystem.HasTag(args.Target, "DroneUsable"))
|
|
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
2022-02-18 17:57:31 -05:00
|
|
|
}
|
|
|
|
|
|
2022-02-10 17:15:06 -05:00
|
|
|
private void OnExamined(EntityUid uid, DroneComponent component, ExaminedEvent args)
|
|
|
|
|
{
|
2023-06-18 11:33:19 -07:00
|
|
|
if (TryComp<MindContainerComponent>(uid, out var mind) && mind.HasMind)
|
2022-02-10 17:15:06 -05:00
|
|
|
{
|
2022-04-08 17:17:25 -04:00
|
|
|
args.PushMarkup(Loc.GetString("drone-active"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
args.PushMarkup(Loc.GetString("drone-dormant"));
|
2022-02-10 17:15:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMobStateChanged(EntityUid uid, DroneComponent drone, MobStateChangedEvent args)
|
|
|
|
|
{
|
2023-01-13 16:57:10 -08:00
|
|
|
if (args.NewMobState == MobState.Dead)
|
2022-02-10 17:15:06 -05:00
|
|
|
{
|
2022-08-31 22:09:20 -04:00
|
|
|
if (TryComp<InnateToolComponent>(uid, out var innate))
|
|
|
|
|
_innateToolSystem.Cleanup(uid, innate);
|
2022-04-27 13:56:11 +10:00
|
|
|
|
2022-10-23 00:46:28 +02:00
|
|
|
if (TryComp<BodyComponent>(uid, out var body))
|
|
|
|
|
_bodySystem.GibBody(uid, body: body);
|
2022-11-09 13:32:44 +13:00
|
|
|
QueueDel(uid);
|
2022-02-10 17:15:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMindAdded(EntityUid uid, DroneComponent drone, MindAddedMessage args)
|
|
|
|
|
{
|
|
|
|
|
UpdateDroneAppearance(uid, DroneStatus.On);
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("drone-activated"), uid, PopupType.Large);
|
2022-02-10 17:15:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMindRemoved(EntityUid uid, DroneComponent drone, MindRemovedMessage args)
|
|
|
|
|
{
|
|
|
|
|
UpdateDroneAppearance(uid, DroneStatus.Off);
|
|
|
|
|
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))
|
|
|
|
|
{
|
2023-02-02 17:34:53 +01:00
|
|
|
_appearance.SetData(uid, DroneVisuals.Status, status, appearance);
|
2022-02-10 17:15:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-03-07 06:46:36 -05:00
|
|
|
|
|
|
|
|
private bool NonDronesInRange(EntityUid uid, DroneComponent component)
|
|
|
|
|
{
|
|
|
|
|
var xform = Comp<TransformComponent>(uid);
|
2022-04-06 19:35:18 +10:00
|
|
|
foreach (var entity in _lookup.GetEntitiesInRange(xform.MapPosition, component.InteractionBlockRange))
|
2022-03-07 06:46:36 -05:00
|
|
|
{
|
2022-05-03 22:41:15 -04:00
|
|
|
// Return true if the entity is/was controlled by a player and is not a drone or ghost.
|
2023-06-18 11:33:19 -07:00
|
|
|
if (HasComp<MindContainerComponent>(entity) && !HasComp<DroneComponent>(entity) && !HasComp<GhostComponent>(entity))
|
2022-03-07 06:46:36 -05:00
|
|
|
{
|
2022-05-03 22:41:15 -04:00
|
|
|
// Filter out dead ghost roles. Dead normal players are intended to block.
|
2022-12-19 19:25:35 -08:00
|
|
|
if ((TryComp<MobStateComponent>(entity, out var entityMobState) && HasComp<GhostTakeoverAvailableComponent>(entity) && _mobStateSystem.IsDead(entity, entityMobState)))
|
2022-05-03 22:41:15 -04:00
|
|
|
continue;
|
2022-03-13 05:53:01 -04:00
|
|
|
if (_gameTiming.IsFirstTimePredicted)
|
2022-12-19 10:41:47 +13:00
|
|
|
_popupSystem.PopupEntity(Loc.GetString("drone-too-close", ("being", Identity.Entity(entity, EntityManager))), uid, uid);
|
2022-03-07 06:46:36 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-02-10 17:15:06 -05:00
|
|
|
}
|
|
|
|
|
}
|