mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
# Description Power cell draw wasn't tick invariant, so batteries on this codebase were being drained anywhere from 30 to 60x faster than people expect, depending on server performance. This was notably something that severely effected MODSuits, which can now enjoy a battery lifespan of around 30 minutes. But it's also a big deal for IPCs. Closes https://github.com/Simple-Station/Einstein-Engines/issues/1956 # Changelog 🆑 - fix: Batteries no longer drain power 30 to 60 times faster than physics states. This is particularly a large buff to IPCs and MODSuits, who both no longer have to deal with batteries lasting an absurdly short amount of time. - tweak: Solarian Modsuit now provides protection from cold. (cherry picked from commit 7df5eccecfe8a5a9eb6d12bbcdb2c545dfbe9b55)
74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using Content.Server.Power.Components;
|
|
using Content.Shared.PowerCell;
|
|
using Content.Shared.PowerCell.Components;
|
|
|
|
namespace Content.Server.PowerCell;
|
|
|
|
public sealed partial class PowerCellSystem
|
|
{
|
|
/*
|
|
* Handles PowerCellDraw
|
|
*/
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
var query = EntityQueryEnumerator<PowerCellDrawComponent, PowerCellSlotComponent>();
|
|
|
|
while (query.MoveNext(out var uid, out var comp, out var slot))
|
|
{
|
|
if (!comp.Enabled)
|
|
continue;
|
|
|
|
if (Timing.CurTime < comp.NextUpdateTime)
|
|
continue;
|
|
|
|
comp.NextUpdateTime += comp.Delay;
|
|
|
|
if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
|
|
continue;
|
|
|
|
// TCJ: "Multiplying by frameTime to make this tick-invariant. Otherwise it'll draw 30x to 60x faster than you expect."
|
|
if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * frameTime, battery))
|
|
continue;
|
|
|
|
var ev = new PowerCellSlotEmptyEvent();
|
|
RaiseLocalEvent(uid, ref ev);
|
|
}
|
|
}
|
|
|
|
private void OnDrawChargeChanged(EntityUid uid, PowerCellDrawComponent component, ref ChargeChangedEvent args)
|
|
{
|
|
// Update the bools for client prediction.
|
|
var canUse = component.UseRate <= 0f || args.Charge > component.UseRate;
|
|
|
|
var canDraw = component.DrawRate <= 0f || args.Charge > 0f;
|
|
|
|
if (canUse != component.CanUse || canDraw != component.CanDraw)
|
|
{
|
|
component.CanDraw = canDraw;
|
|
component.CanUse = canUse;
|
|
Dirty(uid, component);
|
|
}
|
|
}
|
|
|
|
private void OnDrawCellChanged(EntityUid uid, PowerCellDrawComponent component, PowerCellChangedEvent args)
|
|
{
|
|
var canDraw = !args.Ejected && HasCharge(uid, float.MinValue);
|
|
var canUse = !args.Ejected && HasActivatableCharge(uid, component);
|
|
|
|
if (!canDraw)
|
|
{
|
|
var ev = new PowerCellSlotEmptyEvent();
|
|
RaiseLocalEvent(uid, ref ev);
|
|
}
|
|
|
|
if (canUse != component.CanUse || canDraw != component.CanDraw)
|
|
{
|
|
component.CanDraw = canDraw;
|
|
component.CanUse = canUse;
|
|
Dirty(uid, component);
|
|
}
|
|
}
|
|
}
|