2023-04-12 06:32:14 -07:00
|
|
|
using Content.Server.Instruments;
|
2022-03-13 01:33:23 +13:00
|
|
|
using Content.Shared.Interaction.Events;
|
2023-08-30 21:46:11 -07:00
|
|
|
using Content.Shared.Mind.Components;
|
2023-04-12 06:32:14 -07:00
|
|
|
using Content.Shared.PAI;
|
|
|
|
|
using Robust.Server.GameObjects;
|
2021-11-02 00:42:04 +00:00
|
|
|
|
|
|
|
|
namespace Content.Server.PAI
|
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class PAISystem : SharedPAISystem
|
2021-11-02 00:42:04 +00:00
|
|
|
{
|
2021-12-02 12:49:18 -06:00
|
|
|
[Dependency] private readonly InstrumentSystem _instrumentSystem = default!;
|
2023-08-12 17:39:58 -04:00
|
|
|
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
2021-11-02 00:42:04 +00:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<PAIComponent, UseInHandEvent>(OnUseInHand);
|
|
|
|
|
SubscribeLocalEvent<PAIComponent, MindAddedMessage>(OnMindAdded);
|
|
|
|
|
SubscribeLocalEvent<PAIComponent, MindRemovedMessage>(OnMindRemoved);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
private void OnUseInHand(EntityUid uid, PAIComponent component, UseInHandEvent args)
|
2021-11-02 00:42:04 +00:00
|
|
|
{
|
2023-08-12 17:39:58 -04:00
|
|
|
if (!TryComp<MindContainerComponent>(uid, out var mind) || !mind.HasMind)
|
|
|
|
|
component.LastUser = args.User;
|
2021-11-02 00:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
private void OnMindAdded(EntityUid uid, PAIComponent component, MindAddedMessage args)
|
2021-11-02 00:42:04 +00:00
|
|
|
{
|
2023-08-12 17:39:58 -04:00
|
|
|
if (component.LastUser == null)
|
2021-11-02 00:42:04 +00:00
|
|
|
return;
|
|
|
|
|
|
2021-11-04 22:29:16 +00:00
|
|
|
// Ownership tag
|
2023-08-12 17:39:58 -04:00
|
|
|
var val = Loc.GetString("pai-system-pai-name", ("owner", component.LastUser));
|
2022-07-15 20:10:52 +12:00
|
|
|
|
|
|
|
|
// TODO Identity? People shouldn't dox-themselves by carrying around a PAI.
|
|
|
|
|
// But having the pda's name permanently be "old lady's PAI" is weird.
|
|
|
|
|
// Changing the PAI's identity in a way that ties it to the owner's identity also seems weird.
|
|
|
|
|
// Cause then you could remotely figure out information about the owner's equipped items.
|
2023-02-02 17:34:53 +01:00
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
_metaData.SetEntityName(uid, val);
|
2021-11-02 00:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMindRemoved(EntityUid uid, PAIComponent component, MindRemovedMessage args)
|
|
|
|
|
{
|
|
|
|
|
// Mind was removed, shutdown the PAI.
|
2021-11-04 22:29:16 +00:00
|
|
|
PAITurningOff(uid);
|
2021-11-02 00:42:04 +00:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
public void PAITurningOff(EntityUid uid)
|
2021-11-04 22:29:16 +00:00
|
|
|
{
|
2021-12-02 12:49:18 -06:00
|
|
|
// Close the instrument interface if it was open
|
|
|
|
|
// before closing
|
2022-04-04 23:08:36 -07:00
|
|
|
if (HasComp<ActiveInstrumentComponent>(uid) && TryComp<ActorComponent>(uid, out var actor))
|
|
|
|
|
{
|
|
|
|
|
_instrumentSystem.ToggleInstrumentUi(uid, actor.PlayerSession);
|
|
|
|
|
}
|
2021-12-02 12:49:18 -06:00
|
|
|
|
|
|
|
|
// Stop instrument
|
2023-08-12 17:39:58 -04:00
|
|
|
if (TryComp<InstrumentComponent>(uid, out var instrument)) _instrumentSystem.Clean(uid, instrument);
|
|
|
|
|
if (TryComp<MetaDataComponent>(uid, out var metadata))
|
2021-11-04 22:29:16 +00:00
|
|
|
{
|
|
|
|
|
var proto = metadata.EntityPrototype;
|
|
|
|
|
if (proto != null)
|
2023-08-12 17:39:58 -04:00
|
|
|
_metaData.SetEntityName(uid, proto.Name);
|
2021-11-02 00:42:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|