@@ -6,7 +6,6 @@ using Content.Shared.PowerCell.Components;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
|
||||||
using Content.Shared.Storage.Components;
|
using Content.Shared.Storage.Components;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
|
|
||||||
@@ -179,7 +178,7 @@ internal sealed class ChargerSystem : EntitySystem
|
|||||||
if (container.ContainedEntities.Count == 0)
|
if (container.ContainedEntities.Count == 0)
|
||||||
return CellChargerStatus.Empty;
|
return CellChargerStatus.Empty;
|
||||||
|
|
||||||
if (!SearchForBattery(container.ContainedEntities.First(), out var heldBattery))
|
if (!SearchForBattery(container.ContainedEntities[0], out _, out var heldBattery))
|
||||||
return CellChargerStatus.Off;
|
return CellChargerStatus.Off;
|
||||||
|
|
||||||
if (Math.Abs(heldBattery.MaxCharge - heldBattery.CurrentCharge) < 0.01)
|
if (Math.Abs(heldBattery.MaxCharge - heldBattery.CurrentCharge) < 0.01)
|
||||||
@@ -199,27 +198,28 @@ internal sealed class ChargerSystem : EntitySystem
|
|||||||
if (component.Whitelist?.IsValid(targetEntity, EntityManager) == false)
|
if (component.Whitelist?.IsValid(targetEntity, EntityManager) == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!SearchForBattery(targetEntity, out var heldBattery))
|
if (!SearchForBattery(targetEntity, out var batteryUid, out var heldBattery))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_battery.SetCharge(targetEntity, heldBattery.CurrentCharge + component.ChargeRate * frameTime, heldBattery);
|
_battery.SetCharge(batteryUid.Value, heldBattery.CurrentCharge + component.ChargeRate * frameTime, heldBattery);
|
||||||
// Just so the sprite won't be set to 99.99999% visibility
|
// Just so the sprite won't be set to 99.99999% visibility
|
||||||
if (heldBattery.MaxCharge - heldBattery.CurrentCharge < 0.01)
|
if (heldBattery.MaxCharge - heldBattery.CurrentCharge < 0.01)
|
||||||
{
|
{
|
||||||
_battery.SetCharge(targetEntity, heldBattery.MaxCharge, heldBattery);
|
_battery.SetCharge(batteryUid.Value, heldBattery.MaxCharge, heldBattery);
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateStatus(uid, component);
|
UpdateStatus(uid, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SearchForBattery(EntityUid uid, [NotNullWhen(true)] out BatteryComponent? component)
|
private bool SearchForBattery(EntityUid uid, [NotNullWhen(true)] out EntityUid? batteryUid, [NotNullWhen(true)] out BatteryComponent? component)
|
||||||
{
|
{
|
||||||
// try get a battery directly on the inserted entity
|
// try get a battery directly on the inserted entity
|
||||||
if (!TryComp(uid, out component))
|
if (!TryComp(uid, out component))
|
||||||
{
|
{
|
||||||
// or by checking for a power cell slot on the inserted entity
|
// or by checking for a power cell slot on the inserted entity
|
||||||
return _powerCell.TryGetBatteryFromSlot(uid, out component);
|
return _powerCell.TryGetBatteryFromSlot(uid, out batteryUid, out component);
|
||||||
}
|
}
|
||||||
|
batteryUid = uid;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user