Telecom server panel check (#14523)

This commit is contained in:
Slava0135
2023-03-24 03:09:45 +03:00
committed by GitHub
parent 8c7e917038
commit d03ca61da1
17 changed files with 226 additions and 138 deletions

View File

@@ -7,7 +7,9 @@ using Content.Shared.Popups;
using Content.Shared.Radio.Components;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using Content.Shared.Wires;
using Robust.Shared.Containers;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
@@ -20,8 +22,9 @@ public sealed class EncryptionKeySystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly INetManager _net = default!;
[Dependency] private readonly SharedToolSystem _tool = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!;
@@ -55,7 +58,7 @@ public sealed class EncryptionKeySystem : EntitySystem
}
// if tool use ever gets predicted this needs changing.
_popupSystem.PopupEntity(Loc.GetString("encryption-keys-all-extracted"), uid, args.User);
_popup.PopupEntity(Loc.GetString("encryption-keys-all-extracted"), uid, args.User);
_audio.PlayPvs(component.KeyExtractionSound, uid);
component.Removing = false;
}
@@ -92,8 +95,8 @@ public sealed class EncryptionKeySystem : EntitySystem
return;
if (!component.KeysUnlocked)
{
if (_timing.IsFirstTimePredicted)
_popupSystem.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
if (_net.IsClient && _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User);
return;
}
if (TryComp<EncryptionKeyComponent>(args.Used, out var key))
@@ -108,20 +111,26 @@ public sealed class EncryptionKeySystem : EntitySystem
private void TryInsertKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args)
{
args.Handled = true;
if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
{
if (_net.IsClient && _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-keys-panel-locked"), uid, args.User);
return;
}
if (component.KeySlots <= component.KeyContainer.ContainedEntities.Count)
{
if (_timing.IsFirstTimePredicted)
_popupSystem.PopupEntity(Loc.GetString("encryption-key-slots-already-full"), uid, args.User);
if (_net.IsClient && _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-key-slots-already-full"), uid, args.User);
return;
}
if (component.KeyContainer.Insert(args.Used))
{
if (_timing.IsFirstTimePredicted)
_popupSystem.PopupEntity(Loc.GetString("encryption-key-successfully-installed"), uid, args.User);
if (_net.IsClient&& _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-key-successfully-installed"), uid, args.User);
_audio.PlayPredicted(component.KeyInsertionSound, args.Target, args.User);
args.Handled = true;
return;
}
}
@@ -131,21 +140,28 @@ public sealed class EncryptionKeySystem : EntitySystem
if (!TryComp<ToolComponent>(args.Used, out var tool) || !tool.Qualities.Contains(component.KeysExtractionMethod))
return;
args.Handled = true;
if (component.KeyContainer.ContainedEntities.Count == 0)
if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
{
if (_timing.IsFirstTimePredicted)
_popupSystem.PopupEntity(Loc.GetString("encryption-keys-no-keys"), uid, args.User);
if (_net.IsClient && _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-keys-panel-locked"), uid, args.User);
return;
}
//This is honestly the poor mans fix because the InteractUsingEvent fires off 12 times
component.Removing = true;
if (component.KeyContainer.ContainedEntities.Count == 0)
{
if (_net.IsClient && _timing.IsFirstTimePredicted)
_popup.PopupEntity(Loc.GetString("encryption-keys-no-keys"), uid, args.User);
return;
}
var toolEvData = new ToolEventData(new EncryptionRemovalFinishedEvent(args.User), cancelledEv: new EncryptionRemovalCancelledEvent(), targetEntity: uid);
_toolSystem.UseTool(args.Used, args.User, uid, 1f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool);
if (_net.IsServer)
{
//This is honestly the poor mans fix because the InteractUsingEvent fires off 12 times
component.Removing = true;
var toolEvData = new ToolEventData(new EncryptionRemovalFinishedEvent(args.User), cancelledEv: new EncryptionRemovalCancelledEvent(), targetEntity: uid);
if (_tool.UseTool(args.Used, args.User, uid, 1f, new[] { component.KeysExtractionMethod }, toolEvData, toolComponent: tool))
args.Handled = true;
}
}
private void OnStartup(EntityUid uid, EncryptionKeyHolderComponent component, ComponentStartup args)