Proto-kinetic crusher (#16277)

Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
This commit is contained in:
metalgearsloth
2023-05-14 13:15:18 +10:00
committed by GitHub
parent 356bf96039
commit 6417bb4fa0
68 changed files with 926 additions and 312 deletions

View File

@@ -0,0 +1,91 @@
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
*/
private static readonly TimeSpan Delay = TimeSpan.FromSeconds(1);
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.Drawing)
continue;
if (_timing.CurTime < comp.NextUpdateTime)
continue;
comp.NextUpdateTime += Delay;
if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
continue;
if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery))
continue;
comp.Drawing = false;
var ev = new PowerCellSlotEmptyEvent();
RaiseLocalEvent(uid, ref ev);
}
}
private void OnUnpaused(EntityUid uid, PowerCellDrawComponent component, ref EntityUnpausedEvent args)
{
component.NextUpdateTime += args.PausedTime;
}
private void OnDrawChargeChanged(EntityUid uid, PowerCellDrawComponent component, ref ChargeChangedEvent args)
{
// Update the bools for client prediction.
bool canDraw;
bool canUse;
if (component.UseRate > 0f)
{
canUse = args.Charge > component.UseRate;
}
else
{
canUse = true;
}
if (component.DrawRate > 0f)
{
canDraw = args.Charge > 0f;
}
else
{
canDraw = true;
}
if (canUse != component.CanUse || canDraw != component.CanDraw)
{
component.CanDraw = canDraw;
component.CanUse = canUse;
Dirty(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 (canUse != component.CanUse || canDraw != component.CanDraw)
{
component.CanDraw = canDraw;
component.CanUse = canUse;
Dirty(component);
}
}
}