mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
* the definition of insanity * the definition of insanity * the definition of insanity * we have hullrot at home * maybe the real hullrot was the friends we made along the way * john hullrot * i am going to hullroooooot * it's hullrotver * we're so hullback * we're rotting the hull with this one * hullmerge * the hullrot is leaking * never gonna rot you up * hullfresh * john starsector * god i wish we had grid collision damage * you can tell I am very tired because I stopped forcing a hullrot joke into every commit message * hr * this is a surprise sprite that will help us later * motherfucker * i have nothing good to say * still nothing * brb * random letter random letter random letter dash random number random number random number * ass * blast * ffs * fcuk * RE: ffs * RE: RE: ffs * гнида жестяная * continue * i hate tests * i love tests * slide to the right * i hate tests again * what the fuck * ты шиз? * ?? * bbgun
161 lines
6.0 KiB
C#
161 lines
6.0 KiB
C#
using Content.Server.Actions;
|
|
using Content.Server.Chat.Systems;
|
|
using Content.Server.DeviceLinking.Systems;
|
|
using Content.Server.Interaction;
|
|
using Content.Server.Mind;
|
|
using Content.Server.Popups;
|
|
using Content.Shared._White.Overlays;
|
|
using Content.Shared._White.RemoteControl.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DeviceLinking;
|
|
using Content.Shared.Lock;
|
|
using Content.Shared.Mind.Components;
|
|
using Content.Shared.Whitelist;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server._White.RemoteControl.Systems;
|
|
|
|
public sealed partial class RemoteControlSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly DeviceLinkSystem _link = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
|
[Dependency] private readonly ActionsSystem _action = default!;
|
|
[Dependency] private readonly EntityWhitelistSystem _whitelist = default!;
|
|
[Dependency] private readonly InteractionSystem _interactionSystem = default!;
|
|
[Dependency] private readonly LockSystem _lock = default!;
|
|
[Dependency] private readonly MindSystem _mind = default!;
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
[Dependency] private readonly TransformSystem _transform = default!;
|
|
|
|
public static ProtoId<SinkPortPrototype> SinkPortId = "RemoteControlSinkPort";
|
|
public static ProtoId<SourcePortPrototype> SourcePortId = "RemoteControlSourcePort";
|
|
|
|
public override void Initialize()
|
|
{
|
|
InitializeConsole();
|
|
InitializeTarget();
|
|
InitializeUser();
|
|
|
|
SubscribeLocalEvent<ExpandICChatRecipientsEvent>(OnExpandICChatRecipients);
|
|
}
|
|
|
|
// I hate it.
|
|
private void OnExpandICChatRecipients(ExpandICChatRecipientsEvent args)
|
|
{
|
|
var sourceXform = Transform(args.Source);
|
|
|
|
var query = EntityQueryEnumerator<RemoteControllableComponent, TransformComponent>();
|
|
while (query.MoveNext(out _, out var comp, out var xform))
|
|
{
|
|
var range = xform.MapID != sourceXform.MapID
|
|
? -1
|
|
: (_transform.GetWorldPosition(sourceXform) - _transform.GetWorldPosition(xform)).Length();
|
|
|
|
if (range < 0 || range > args.VoiceRange)
|
|
continue;
|
|
|
|
if (TryComp<ActorComponent>(comp.User, out var actor))
|
|
args.Recipients.TryAdd(actor.PlayerSession, new ChatSystem.ICChatRecipientData(range, false, false));
|
|
}
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
var query = EntityQueryEnumerator<RemoteControllingComponent>();
|
|
while (query.MoveNext(out var uid, out var comp))
|
|
{
|
|
if(!_actionBlocker.CanInteract(uid, comp.Console)
|
|
|| !_interactionSystem.InRangeAndAccessible(uid, comp.Console))
|
|
EndRemoteControl((uid, comp), comp.Target, comp.Console, true);
|
|
}
|
|
}
|
|
|
|
private bool RemoteControl(EntityUid user, Entity<RemoteControllableComponent?> target, Entity<RemoteControlConsoleComponent?> console, bool overlay = false)
|
|
{
|
|
if (!Resolve(target, ref target.Comp)
|
|
|| HasComp<RemoteControllingComponent>(user)
|
|
|| HasComp<VisitingMindComponent>(target)
|
|
|| _mind.GetMind(user) is not { } userMind)
|
|
return false;
|
|
|
|
var userComp = EnsureComp<RemoteControllingComponent>(user);
|
|
userComp.Target = target;
|
|
userComp.Console = console;
|
|
|
|
target.Comp.User = user;
|
|
|
|
if (Resolve(console, ref console.Comp, false))
|
|
{
|
|
console.Comp.User = user;
|
|
console.Comp.Target = target;
|
|
console.Comp.LastIndex = console.Comp.LinkedEntities.IndexOf(target);
|
|
DebugTools.Assert(console.Comp.SwitchToNextActionUid.HasValue);
|
|
_action.AddAction(target, console.Comp.SwitchToNextActionUid.Value, console);
|
|
}
|
|
|
|
_mind.Visit(userMind, target);
|
|
|
|
if (overlay)
|
|
EnsureComp<RemoteControlOverlayComponent>(target);
|
|
else if (TryComp<RemoteControlOverlayComponent>(target, out var overlayComp))
|
|
RemComp(target, overlayComp);
|
|
|
|
return true;
|
|
}
|
|
|
|
private bool EndRemoteControl(Entity<RemoteControllingComponent?> user, bool shouldAutoSwitch = false)
|
|
{
|
|
if (!Resolve(user, ref user.Comp))
|
|
return false;
|
|
|
|
return EndRemoteControl(user, user.Comp.Target, user.Comp.Console, shouldAutoSwitch);
|
|
}
|
|
|
|
private bool EndRemoteControl(Entity<RemoteControllingComponent?> user, Entity<RemoteControllableComponent?> target, bool shouldAutoSwitch = false)
|
|
{
|
|
if (!Resolve(user, ref user.Comp) || !Resolve(target, ref target.Comp))
|
|
return false;
|
|
|
|
return EndRemoteControl(user, target, user.Comp.Console, shouldAutoSwitch);
|
|
}
|
|
|
|
private bool EndRemoteControl(Entity<RemoteControllingComponent?> user, Entity<RemoteControlConsoleComponent?> console, bool shouldAutoSwitch = false )
|
|
{
|
|
if (!Resolve(user, ref user.Comp) || !Resolve(console, ref console.Comp))
|
|
return false;
|
|
|
|
return EndRemoteControl(user, user.Comp.Target, console, shouldAutoSwitch);
|
|
}
|
|
|
|
private bool EndRemoteControl(Entity<RemoteControllingComponent?> user, Entity<RemoteControllableComponent?> target, Entity<RemoteControlConsoleComponent?> console, bool shouldAutoSwitch = false )
|
|
{
|
|
if (!Resolve(user, ref user.Comp)
|
|
|| !Resolve(target, ref target.Comp)
|
|
|| _mind.GetMind(user) is not { } userMind)
|
|
return false;
|
|
|
|
target.Comp.User = null;
|
|
|
|
_mind.UnVisit(userMind);
|
|
|
|
RemComp(user.Owner, user.Comp);
|
|
|
|
if (!Resolve(console, ref console.Comp, false))
|
|
return true;
|
|
|
|
console.Comp.Target = null;
|
|
|
|
_action.RemoveAction(target, console.Comp.SwitchToNextActionUid);
|
|
|
|
if (shouldAutoSwitch && TrySwitchToNextAvailable(user.Comp.Console, console.Comp))
|
|
return true;
|
|
|
|
console.Comp.User = null;
|
|
|
|
return true;
|
|
}
|
|
}
|