2023-05-14 13:15:18 +10:00
|
|
|
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);
|
2024-08-25 12:17:03 +00:00
|
|
|
var query = EntityQueryEnumerator<PowerCellDrawComponent, PowerCellSlotComponent>();
|
2023-05-14 13:15:18 +10:00
|
|
|
|
2024-08-25 12:17:03 +00:00
|
|
|
while (query.MoveNext(out var uid, out var comp, out var slot))
|
2023-05-14 13:15:18 +10:00
|
|
|
{
|
2024-08-25 12:17:03 +00:00
|
|
|
if (!comp.Enabled)
|
2023-05-14 13:15:18 +10:00
|
|
|
continue;
|
|
|
|
|
|
2023-11-07 20:25:43 -05:00
|
|
|
if (Timing.CurTime < comp.NextUpdateTime)
|
2023-05-14 13:15:18 +10:00
|
|
|
continue;
|
|
|
|
|
|
2024-07-11 05:55:56 +00:00
|
|
|
comp.NextUpdateTime += comp.Delay;
|
2023-05-14 13:15:18 +10:00
|
|
|
|
|
|
|
|
if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-06-25 15:38:57 +02:00
|
|
|
if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * (float)comp.Delay.TotalSeconds, battery))
|
2023-05-14 13:15:18 +10:00
|
|
|
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.
|
2024-07-11 05:55:56 +00:00
|
|
|
var canUse = component.UseRate <= 0f || args.Charge > component.UseRate;
|
2023-05-14 13:15:18 +10:00
|
|
|
|
2024-07-11 05:55:56 +00:00
|
|
|
var canDraw = component.DrawRate <= 0f || args.Charge > 0f;
|
2023-05-14 13:15:18 +10:00
|
|
|
|
|
|
|
|
if (canUse != component.CanUse || canDraw != component.CanDraw)
|
|
|
|
|
{
|
|
|
|
|
component.CanDraw = canDraw;
|
|
|
|
|
component.CanUse = canUse;
|
2024-03-19 23:27:02 -04:00
|
|
|
Dirty(uid, component);
|
2023-05-14 13:15:18 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDrawCellChanged(EntityUid uid, PowerCellDrawComponent component, PowerCellChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
var canDraw = !args.Ejected && HasCharge(uid, float.MinValue);
|
|
|
|
|
var canUse = !args.Ejected && HasActivatableCharge(uid, component);
|
|
|
|
|
|
2024-07-11 05:55:56 +00:00
|
|
|
if (!canDraw)
|
2024-08-25 12:17:03 +00:00
|
|
|
{
|
|
|
|
|
var ev = new PowerCellSlotEmptyEvent();
|
|
|
|
|
RaiseLocalEvent(uid, ref ev);
|
|
|
|
|
}
|
2024-07-11 05:55:56 +00:00
|
|
|
|
2023-05-14 13:15:18 +10:00
|
|
|
if (canUse != component.CanUse || canDraw != component.CanDraw)
|
|
|
|
|
{
|
|
|
|
|
component.CanDraw = canDraw;
|
|
|
|
|
component.CanUse = canUse;
|
2024-03-19 23:27:02 -04:00
|
|
|
Dirty(uid, component);
|
2023-05-14 13:15:18 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|