replace apc panel with wires panel (#14832)

This commit is contained in:
Slava0135
2023-04-20 09:42:22 +03:00
committed by GitHub
parent 32a3ee945c
commit adb12676c6
16 changed files with 47 additions and 257 deletions

View File

@@ -5,19 +5,12 @@ using Content.Server.Power.Pow3r;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.APC;
using Content.Shared.DoAfter;
using Content.Shared.Emag.Components;
using Content.Shared.Emag.Systems;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.Power;
using Content.Shared.Tools;
using Content.Shared.Tools.Components;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Timing;
namespace Content.Server.Power.EntitySystems
@@ -26,15 +19,12 @@ namespace Content.Server.Power.EntitySystems
internal sealed class ApcSystem : EntitySystem
{
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
private const float ScrewTime = 2f;
public override void Initialize()
{
base.Initialize();
@@ -47,10 +37,6 @@ namespace Content.Server.Power.EntitySystems
SubscribeLocalEvent<ApcComponent, ApcToggleMainBreakerMessage>(OnToggleMainBreaker);
SubscribeLocalEvent<ApcComponent, GotEmaggedEvent>(OnEmagged);
SubscribeLocalEvent<ApcComponent, ApcToolFinishedEvent>(OnToolFinished);
SubscribeLocalEvent<ApcComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<ApcComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<ApcComponent, EmpPulseEvent>(OnEmpPulse);
}
@@ -93,7 +79,7 @@ namespace Content.Server.Power.EntitySystems
}
else
{
_popupSystem.PopupCursor(Loc.GetString("apc-component-insufficient-access"),
_popup.PopupCursor(Loc.GetString("apc-component-insufficient-access"),
args.Session, PopupType.Medium);
}
}
@@ -107,7 +93,7 @@ namespace Content.Server.Power.EntitySystems
battery.CanDischarge = apc.MainBreakerEnabled;
UpdateUIState(uid, apc);
SoundSystem.Play(apc.OnReceiveMessageSound.GetSound(), Filter.Pvs(uid), uid, AudioParams.Default.WithVolume(-2f));
_audio.PlayPvs(apc.OnReceiveMessageSound, uid, AudioParams.Default.WithVolume(-2f));
}
private void OnEmagged(EntityUid uid, ApcComponent comp, ref GotEmaggedEvent args)
@@ -123,18 +109,13 @@ namespace Content.Server.Power.EntitySystems
if (!Resolve(uid, ref apc, ref battery))
return;
if (TryComp(uid, out AppearanceComponent? appearance))
{
UpdatePanelAppearance(uid, appearance, apc);
}
var newState = CalcChargeState(uid, battery.NetworkBattery);
if (newState != apc.LastChargeState && apc.LastChargeStateTime + ApcComponent.VisualsChangeDelay < _gameTiming.CurTime)
{
apc.LastChargeState = newState;
apc.LastChargeStateTime = _gameTiming.CurTime;
if (appearance != null)
if (TryComp(uid, out AppearanceComponent? appearance))
{
_appearance.SetData(uid, ApcVisuals.ChargeState, newState, appearance);
}
@@ -164,7 +145,7 @@ namespace Content.Server.Power.EntitySystems
(int) MathF.Ceiling(battery.CurrentSupply), apc.LastExternalState,
battery.AvailableSupply / battery.Capacity);
_userInterfaceSystem.TrySetUiState(uid, ApcUiKey.Key, state, ui: ui);
_ui.TrySetUiState(uid, ApcUiKey.Key, state, ui: ui);
}
private ApcChargeState CalcChargeState(EntityUid uid, PowerState.Battery battery)
@@ -197,51 +178,6 @@ namespace Content.Server.Power.EntitySystems
return ApcExternalPowerState.Good;
}
public static ApcPanelState GetPanelState(ApcComponent apc)
{
if (apc.IsApcOpen)
return ApcPanelState.Open;
else
return ApcPanelState.Closed;
}
private void OnInteractUsing(EntityUid uid, ApcComponent component, InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.Used, out ToolComponent? tool))
return;
if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new ApcToolFinishedEvent(), toolComponent:tool))
args.Handled = true;
}
private void OnToolFinished(EntityUid uid, ApcComponent component, ApcToolFinishedEvent args)
{
if (args.Cancelled)
return;
component.IsApcOpen = !component.IsApcOpen;
UpdatePanelAppearance(uid, apc: component);
// this will play on top of the normal screw driver tool sound.
var sound = component.IsApcOpen ? component.ScrewdriverOpenSound : component.ScrewdriverCloseSound;
_audio.PlayPvs(sound, uid);
}
private void UpdatePanelAppearance(EntityUid uid, AppearanceComponent? appearance = null, ApcComponent? apc = null)
{
if (!Resolve(uid, ref appearance, ref apc, false))
return;
_appearance.SetData(uid, ApcVisuals.PanelState, GetPanelState(apc), appearance);
}
private void OnExamine(EntityUid uid, ApcComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString(component.IsApcOpen
? "apc-component-on-examine-panel-open"
: "apc-component-on-examine-panel-closed"));
}
private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args)
{
if (component.MainBreakerEnabled)