Skip to content

Commit

Permalink
Fix borg charger error (#26230)
Browse files Browse the repository at this point in the history
Fix borg chargers not working
  • Loading branch information
Tayrtahn authored Mar 18, 2024
1 parent 646f7e0 commit 2988763
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Content.Server/Power/EntitySystems/ChargerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using JetBrains.Annotations;
using Robust.Shared.Containers;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.Storage.Components;
using Robust.Server.Containers;

Expand Down Expand Up @@ -179,7 +178,7 @@ private CellChargerStatus GetStatus(EntityUid uid, ChargerComponent component)
if (container.ContainedEntities.Count == 0)
return CellChargerStatus.Empty;

if (!SearchForBattery(container.ContainedEntities.First(), out var heldBattery))
if (!SearchForBattery(container.ContainedEntities[0], out _, out var heldBattery))
return CellChargerStatus.Off;

if (Math.Abs(heldBattery.MaxCharge - heldBattery.CurrentCharge) < 0.01)
Expand All @@ -199,27 +198,28 @@ private void TransferPower(EntityUid uid, EntityUid targetEntity, ChargerCompone
if (component.Whitelist?.IsValid(targetEntity, EntityManager) == false)
return;

if (!SearchForBattery(targetEntity, out var heldBattery))
if (!SearchForBattery(targetEntity, out var batteryUid, out var heldBattery))
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
if (heldBattery.MaxCharge - heldBattery.CurrentCharge < 0.01)
{
_battery.SetCharge(targetEntity, heldBattery.MaxCharge, heldBattery);
_battery.SetCharge(batteryUid.Value, heldBattery.MaxCharge, heldBattery);
}

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
if (!TryComp(uid, out component))
{
// 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;
}
}

0 comments on commit 2988763

Please sign in to comment.