Fix taser visuals not updating after charging. (#6065)

This commit is contained in:
Leon Friedrich
2022-01-10 01:48:58 +13:00
committed by GitHub
parent 259914b919
commit 5a64936ade
4 changed files with 21 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ using Content.Shared.Examine;
using Content.Shared.PowerCell;
using Content.Shared.PowerCell.Components;
using Content.Shared.Rounding;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
@@ -20,6 +21,7 @@ public class PowerCellSystem : SharedPowerCellSystem
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = default!;
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
public override void Initialize()
{
@@ -48,6 +50,14 @@ public class PowerCellSystem : SharedPowerCellSystem
var frac = battery.CurrentCharge / battery.MaxCharge;
var level = (byte) ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);
appearance.SetData(PowerCellVisuals.ChargeLevel, level);
// If this power cell is inside a cell-slot, inform that entity that the power has changed (for updating visuals n such).
if (_containerSystem.TryGetContainingContainer(uid, out var container)
&& TryComp(container.Owner, out PowerCellSlotComponent? slot)
&& slot.CellSlot.Item == uid)
{
RaiseLocalEvent(container.Owner, new PowerCellChangedEvent(false), false);
}
}
private void Explode(EntityUid uid, BatteryComponent? battery = null)