* remove ItemToggle from PowerCellDraw query * add EntityQuery for resolves, make them all optional * move integration to ToggleCellDraw * add ToggleCellDraw to almost every PowerCellDraw prototype * :trollface: * :trollface: * :trollface: * let it disable on mapinit * set update time on mapinit, make borg power logic consistent now * :trollface: --------- Co-authored-by: deltanedas <@deltanedas:kde.org>
73 lines
2.1 KiB
C#
73 lines
2.1 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;
|
|
|
|
if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, 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);
|
|
}
|
|
}
|
|
}
|