Predict some power PowerReceiver stuff (#33834)

* Predict some power PowerReceiver stuff

Need it for some atmos device prediction.

* Also this
This commit is contained in:
metalgearsloth
2025-03-10 13:00:49 +11:00
committed by GitHub
parent 6689cae5a1
commit 75a7407e33
9 changed files with 96 additions and 61 deletions

View File

@@ -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<ApcPowerReceiverComponent> _recQuery;
private EntityQuery<ApcPowerProviderComponent> _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;
}
/// <summary>
/// Turn this machine on or off.
/// Returns true if we turned it on, false if we turned it off.
/// </summary>
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;