Fix instant power cell drainage (#15927)
This commit is contained in:
@@ -113,7 +113,7 @@ public sealed class ProximityBeeperSystem : EntitySystem
|
|||||||
component.NextBeepTime = _timing.CurTime;
|
component.NextBeepTime = _timing.CurTime;
|
||||||
UpdateBeep(uid, component, false);
|
UpdateBeep(uid, component, false);
|
||||||
if (draw != null)
|
if (draw != null)
|
||||||
draw.Enabled = true;
|
_powerCell.SetPowerCellDrawEnabled(uid, true, draw);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,8 +130,7 @@ public sealed class ProximityBeeperSystem : EntitySystem
|
|||||||
|
|
||||||
component.Enabled = false;
|
component.Enabled = false;
|
||||||
_appearance.SetData(uid, ProximityBeeperVisuals.Enabled, false);
|
_appearance.SetData(uid, ProximityBeeperVisuals.Enabled, false);
|
||||||
if (TryComp<PowerCellDrawComponent>(uid, out var draw))
|
_powerCell.SetPowerCellDrawEnabled(uid, true);
|
||||||
draw.Enabled = true;
|
|
||||||
UpdateBeep(uid, component);
|
UpdateBeep(uid, component);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ namespace Content.Server.PowerCell;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates that the entity's ActivatableUI requires power or else it closes.
|
/// Indicates that the entity's ActivatableUI requires power or else it closes.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent, Access(typeof(PowerCellSystem))]
|
||||||
public sealed class PowerCellDrawComponent : Component
|
public sealed class PowerCellDrawComponent : Component
|
||||||
{
|
{
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
|
||||||
public bool Enabled = false;
|
public bool Enabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How much the entity draws while the UI is open.
|
/// How much the entity draws while the UI is open.
|
||||||
@@ -23,7 +23,7 @@ public sealed class PowerCellDrawComponent : Component
|
|||||||
/// This is used to ensure the UI won't open again without a minimum use power.
|
/// This is used to ensure the UI won't open again without a minimum use power.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
|
[ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
|
||||||
public float UseRate = 0f;
|
public float UseRate;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When the next automatic power draw will occur
|
/// When the next automatic power draw will occur
|
||||||
|
|||||||
@@ -194,6 +194,15 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public void SetPowerCellDrawEnabled(EntityUid uid, bool enabled, PowerCellDrawComponent? component = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(uid, ref component, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
component.Enabled = enabled;
|
||||||
|
component.NextUpdateTime = _timing.CurTime;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns whether the entity has a slotted battery and charge for the requested action.
|
/// Returns whether the entity has a slotted battery and charge for the requested action.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ public sealed partial class ActivatableUISystem
|
|||||||
|
|
||||||
private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
|
private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
|
||||||
{
|
{
|
||||||
if (TryComp<PowerCellDrawComponent>(uid, out var draw))
|
_cell.SetPowerCellDrawEnabled(uid, false);
|
||||||
{
|
|
||||||
draw.Enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
|
if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
|
||||||
TryComp<ActivatableUIComponent>(uid, out var activatable) &&
|
TryComp<ActivatableUIComponent>(uid, out var activatable) &&
|
||||||
@@ -34,18 +31,12 @@ public sealed partial class ActivatableUISystem
|
|||||||
|
|
||||||
private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
|
private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
|
_cell.SetPowerCellDrawEnabled(uid, true);
|
||||||
return;
|
|
||||||
|
|
||||||
draw.Enabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
|
private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
|
_cell.SetPowerCellDrawEnabled(uid, false);
|
||||||
return;
|
|
||||||
|
|
||||||
draw.Enabled = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user