From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Mon, 10 Mar 2025 02:00:49 +0000 (+1100)
Subject: Predict some power PowerReceiver stuff (#33834)
X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=75a7407e33f328c230ad7309b0d1571a4f7f8256;p=space-station-14.git
Predict some power PowerReceiver stuff (#33834)
* Predict some power PowerReceiver stuff
Need it for some atmos device prediction.
* Also this
---
diff --git a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs
index ebf6c18c95..319ab5c56d 100644
--- a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs
+++ b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs
@@ -27,6 +27,8 @@ public sealed class PowerReceiverSystem : SharedPowerReceiverSystem
return;
component.Powered = state.Powered;
+ component.NeedsPower = state.NeedsPower;
+ component.PowerDisabled = state.PowerDisabled;
}
public override bool ResolveApc(EntityUid entity, [NotNullWhen(true)] ref SharedApcPowerReceiverComponent? component)
diff --git a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs
index ebb3c6b42f..aa8feff3e0 100644
--- a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs
+++ b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs
@@ -24,7 +24,7 @@ namespace Content.Server.Power.Components
/// When false, causes this to appear powered even if not receiving power from an Apc.
///
[ViewVariables(VVAccess.ReadWrite)]
- public bool NeedsPower
+ public override bool NeedsPower
{
get => _needsPower;
set
@@ -41,9 +41,9 @@ namespace Content.Server.Power.Components
///
/// When true, causes this to never appear powered.
///
- [ViewVariables(VVAccess.ReadWrite)]
[DataField("powerDisabled")]
- public bool PowerDisabled {
+ public override bool PowerDisabled
+ {
get => !NetworkLoad.Enabled;
set => NetworkLoad.Enabled = !value;
}
diff --git a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs
index 38d7376e54..0239273455 100644
--- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs
+++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs
@@ -1,18 +1,12 @@
using System.Diagnostics.CodeAnalysis;
-using Content.Server.Administration.Logs;
using Content.Server.Administration.Managers;
using Content.Server.Power.Components;
using Content.Shared.Administration;
-using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.Hands.Components;
-using Content.Shared.Power;
using Content.Shared.Power.Components;
using Content.Shared.Power.EntitySystems;
using Content.Shared.Verbs;
-using Robust.Server.Audio;
-using Robust.Server.GameObjects;
-using Robust.Shared.Audio;
using Robust.Shared.GameStates;
using Robust.Shared.Utility;
@@ -20,9 +14,8 @@ namespace Content.Server.Power.EntitySystems
{
public sealed class PowerReceiverSystem : SharedPowerReceiverSystem
{
- [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IAdminManager _adminManager = default!;
- [Dependency] private readonly AudioSystem _audio = default!;
+
private EntityQuery _recQuery;
private EntityQuery _provQuery;
@@ -63,7 +56,10 @@ namespace Content.Server.Power.EntitySystems
Text = Loc.GetString("verb-debug-toggle-need-power"),
Category = VerbCategory.Debug,
Icon = new SpriteSpecifier.Texture(new ("/Textures/Interface/VerbIcons/smite.svg.192dpi.png")), // "smite" is a lightning bolt
- Act = () => component.NeedsPower = !component.NeedsPower
+ Act = () =>
+ {
+ SetNeedsPower(uid, !component.NeedsPower, component);
+ }
});
}
@@ -143,7 +139,9 @@ namespace Content.Server.Power.EntitySystems
{
args.State = new ApcPowerReceiverComponentState
{
- Powered = component.Powered
+ Powered = component.Powered,
+ NeedsPower = component.NeedsPower,
+ PowerDisabled = component.PowerDisabled,
};
}
@@ -164,36 +162,6 @@ namespace Content.Server.Power.EntitySystems
return !_recQuery.Resolve(uid, ref receiver, false) || receiver.Powered;
}
- ///
- /// Turn this machine on or off.
- /// Returns true if we turned it on, false if we turned it off.
- ///
- public bool TogglePower(EntityUid uid, bool playSwitchSound = true, ApcPowerReceiverComponent? receiver = null, EntityUid? user = null)
- {
- if (!_recQuery.Resolve(uid, ref receiver, false))
- return true;
-
- // it'll save a lot of confusion if 'always powered' means 'always powered'
- if (!receiver.NeedsPower)
- {
- receiver.PowerDisabled = false;
- return true;
- }
-
- receiver.PowerDisabled = !receiver.PowerDisabled;
-
- if (user != null)
- _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(user.Value):player} hit power button on {ToPrettyString(uid)}, it's now {(!receiver.PowerDisabled ? "on" : "off")}");
-
- if (playSwitchSound)
- {
- _audio.PlayPvs(new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"), uid,
- AudioParams.Default.WithVolume(-2f));
- }
-
- return !receiver.PowerDisabled; // i.e. PowerEnabled
- }
-
public void SetLoad(ApcPowerReceiverComponent comp, float load)
{
comp.Load = load;
diff --git a/Content.Server/Power/Generation/Teg/TegSystem.cs b/Content.Server/Power/Generation/Teg/TegSystem.cs
index 027f257040..5c2ac27352 100644
--- a/Content.Server/Power/Generation/Teg/TegSystem.cs
+++ b/Content.Server/Power/Generation/Teg/TegSystem.cs
@@ -11,6 +11,7 @@ using Content.Shared.Atmos;
using Content.Shared.DeviceNetwork;
using Content.Shared.Examine;
using Content.Shared.Power;
+using Content.Shared.Power.EntitySystems;
using Content.Shared.Power.Generation.Teg;
using Content.Shared.Rounding;
using Robust.Server.GameObjects;
@@ -66,11 +67,12 @@ public sealed class TegSystem : EntitySystem
///
public const string DeviceNetworkCommandSyncData = "teg_sync_data";
+ [Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
+ [Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetwork = default!;
- [Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly PointLightSystem _pointLight = default!;
- [Dependency] private readonly AmbientSoundSystem _ambientSound = default!;
+ [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
private EntityQuery _nodeContainerQuery;
@@ -241,8 +243,7 @@ public sealed class TegSystem : EntitySystem
var powerReceiver = Comp(uid);
- powerReceiver.PowerDisabled = !group.IsFullyBuilt;
-
+ _receiver.SetPowerDisabled(uid, !group.IsFullyBuilt, powerReceiver);
UpdateAppearance(uid, component, powerReceiver, group);
}
diff --git a/Content.Server/Power/PowerWireAction.cs b/Content.Server/Power/PowerWireAction.cs
index 9e4e6a6086..8273615546 100644
--- a/Content.Server/Power/PowerWireAction.cs
+++ b/Content.Server/Power/PowerWireAction.cs
@@ -1,6 +1,7 @@
using Content.Server.Electrocution;
using Content.Shared.Electrocution;
using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
using Content.Server.Wires;
using Content.Shared.Power;
using Content.Shared.Wires;
@@ -61,15 +62,17 @@ public sealed partial class PowerWireAction : BaseWireAction
return;
}
+ var receiverSys = EntityManager.System();
+
if (pulsed)
{
- power.PowerDisabled = true;
+ receiverSys.SetPowerDisabled(owner, true, power);
return;
}
if (AllWiresCut(owner))
{
- power.PowerDisabled = true;
+ receiverSys.SetPowerDisabled(owner, true, power);
}
else
{
@@ -79,7 +82,7 @@ public sealed partial class PowerWireAction : BaseWireAction
return;
}
- power.PowerDisabled = false;
+ receiverSys.SetPowerDisabled(owner, false, power);
}
}
diff --git a/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs b/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs
index 67c67de57f..a5670ec8ee 100644
--- a/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs
+++ b/Content.Server/Xenoarchaeology/Equipment/Systems/ArtifactAnalyzerSystem.cs
@@ -12,6 +12,7 @@ using Content.Shared.Paper;
using Content.Shared.Placeable;
using Content.Shared.Popups;
using Content.Shared.Power;
+using Content.Shared.Power.EntitySystems;
using Content.Shared.Research.Components;
using Content.Shared.Xenoarchaeology.Equipment;
using Content.Shared.Xenoarchaeology.XenoArtifacts;
@@ -33,15 +34,16 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
- [Dependency] private readonly SharedAudioSystem _audio = default!;
- [Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
- [Dependency] private readonly SharedPopupSystem _popup = default!;
- [Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly ArtifactSystem _artifact = default!;
+ [Dependency] private readonly MetaDataSystem _metaSystem = default!;
[Dependency] private readonly PaperSystem _paper = default!;
[Dependency] private readonly ResearchSystem _research = default!;
- [Dependency] private readonly MetaDataSystem _metaSystem = default!;
+ [Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;
+ [Dependency] private readonly SharedAudioSystem _audio = default!;
+ [Dependency] private readonly SharedPopupSystem _popup = default!;
+ [Dependency] private readonly SharedPowerReceiverSystem _receiver = default!;
[Dependency] private readonly TraversalDistorterSystem _traversalDistorter = default!;
+ [Dependency] private readonly UserInterfaceSystem _ui = default!;
///
public override void Initialize()
@@ -492,17 +494,13 @@ public sealed class ArtifactAnalyzerSystem : EntitySystem
private void OnAnalyzeStart(EntityUid uid, ActiveArtifactAnalyzerComponent component, ComponentStartup args)
{
- if (TryComp(uid, out var powa))
- powa.NeedsPower = true;
-
+ _receiver.SetNeedsPower(uid, true);
_ambientSound.SetAmbience(uid, true);
}
private void OnAnalyzeEnd(EntityUid uid, ActiveArtifactAnalyzerComponent component, ComponentShutdown args)
{
- if (TryComp(uid, out var powa))
- powa.NeedsPower = false;
-
+ _receiver.SetNeedsPower(uid, false);
_ambientSound.SetAmbience(uid, false);
}
diff --git a/Content.Shared/Power/Components/ApcPowerReceiverComponentState.cs b/Content.Shared/Power/Components/ApcPowerReceiverComponentState.cs
index 9b18d6ad93..31456c86f2 100644
--- a/Content.Shared/Power/Components/ApcPowerReceiverComponentState.cs
+++ b/Content.Shared/Power/Components/ApcPowerReceiverComponentState.cs
@@ -6,4 +6,6 @@ namespace Content.Shared.Power.Components;
public sealed class ApcPowerReceiverComponentState : ComponentState
{
public bool Powered;
+ public bool NeedsPower;
+ public bool PowerDisabled;
}
diff --git a/Content.Shared/Power/Components/SharedApcPowerReceiverComponent.cs b/Content.Shared/Power/Components/SharedApcPowerReceiverComponent.cs
index d73993357a..69c3bd790e 100644
--- a/Content.Shared/Power/Components/SharedApcPowerReceiverComponent.cs
+++ b/Content.Shared/Power/Components/SharedApcPowerReceiverComponent.cs
@@ -7,4 +7,10 @@ public abstract partial class SharedApcPowerReceiverComponent : Component
{
[ViewVariables]
public bool Powered;
+
+ [ViewVariables]
+ public virtual bool NeedsPower { get; set; }
+
+ [ViewVariables]
+ public virtual bool PowerDisabled { get; set; }
}
diff --git a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs
index b7ba2a31c5..2d152d8b45 100644
--- a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs
+++ b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs
@@ -1,12 +1,67 @@
using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Administration.Logs;
+using Content.Shared.Database;
using Content.Shared.Power.Components;
+using Robust.Shared.Audio;
+using Robust.Shared.Audio.Systems;
namespace Content.Shared.Power.EntitySystems;
public abstract class SharedPowerReceiverSystem : EntitySystem
{
+ [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
+ [Dependency] private readonly SharedAudioSystem _audio = default!;
+
public abstract bool ResolveApc(EntityUid entity, [NotNullWhen(true)] ref SharedApcPowerReceiverComponent? component);
+ public void SetNeedsPower(EntityUid uid, bool value, SharedApcPowerReceiverComponent? receiver = null)
+ {
+ if (!ResolveApc(uid, ref receiver) || receiver.NeedsPower == value)
+ return;
+
+ receiver.NeedsPower = value;
+ Dirty(uid, receiver);
+ }
+
+ public void SetPowerDisabled(EntityUid uid, bool value, SharedApcPowerReceiverComponent? receiver = null)
+ {
+ if (!ResolveApc(uid, ref receiver) || receiver.PowerDisabled == value)
+ return;
+
+ receiver.PowerDisabled = value;
+ Dirty(uid, receiver);
+ }
+
+ ///
+ /// Turn this machine on or off.
+ /// Returns true if we turned it on, false if we turned it off.
+ ///
+ public bool TogglePower(EntityUid uid, bool playSwitchSound = true, SharedApcPowerReceiverComponent? receiver = null, EntityUid? user = null)
+ {
+ if (!ResolveApc(uid, ref receiver))
+ return true;
+
+ // it'll save a lot of confusion if 'always powered' means 'always powered'
+ if (!receiver.NeedsPower)
+ {
+ SetPowerDisabled(uid, false, receiver);
+ return true;
+ }
+
+ SetPowerDisabled(uid, !receiver.PowerDisabled, receiver);
+
+ if (user != null)
+ _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(user.Value):player} hit power button on {ToPrettyString(uid)}, it's now {(!receiver.PowerDisabled ? "on" : "off")}");
+
+ if (playSwitchSound)
+ {
+ _audio.PlayPredicted(new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg"), uid, user: user,
+ AudioParams.Default.WithVolume(-2f));
+ }
+
+ return !receiver.PowerDisabled; // i.e. PowerEnabled
+ }
+
///
/// Checks if entity is APC-powered device, and if it have power.
///