Fix taser visuals not updating after charging. (#6065)
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Shared.Examine;
|
|||||||
using Content.Shared.PowerCell;
|
using Content.Shared.PowerCell;
|
||||||
using Content.Shared.PowerCell.Components;
|
using Content.Shared.PowerCell.Components;
|
||||||
using Content.Shared.Rounding;
|
using Content.Shared.Rounding;
|
||||||
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
@@ -20,6 +21,7 @@ public class PowerCellSystem : SharedPowerCellSystem
|
|||||||
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
|
||||||
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
|
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
|
||||||
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
[Dependency] private readonly AdminLogSystem _logSystem = default!;
|
||||||
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -48,6 +50,14 @@ public class PowerCellSystem : SharedPowerCellSystem
|
|||||||
var frac = battery.CurrentCharge / battery.MaxCharge;
|
var frac = battery.CurrentCharge / battery.MaxCharge;
|
||||||
var level = (byte) ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);
|
var level = (byte) ContentHelpers.RoundToNearestLevels(frac, 1, PowerCellComponent.PowerCellVisualsLevels);
|
||||||
appearance.SetData(PowerCellVisuals.ChargeLevel, level);
|
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)
|
private void Explode(EntityUid uid, BatteryComponent? battery = null)
|
||||||
|
|||||||
@@ -99,7 +99,12 @@ namespace Content.Server.Stunnable
|
|||||||
|
|
||||||
private void OnPowerCellChanged(EntityUid uid, StunbatonComponent comp, PowerCellChangedEvent args)
|
private void OnPowerCellChanged(EntityUid uid, StunbatonComponent comp, PowerCellChangedEvent args)
|
||||||
{
|
{
|
||||||
if (args.Ejected)
|
if (!comp.Activated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (args.Ejected
|
||||||
|
|| !_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery)
|
||||||
|
|| battery.CurrentCharge < comp.EnergyPerUse)
|
||||||
{
|
{
|
||||||
TurnOff(comp);
|
TurnOff(comp);
|
||||||
}
|
}
|
||||||
@@ -175,9 +180,6 @@ namespace Content.Server.Stunnable
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var playerFilter = Filter.Pvs(comp.Owner);
|
var playerFilter = Filter.Pvs(comp.Owner);
|
||||||
if (!EntityManager.TryGetComponent<PowerCellSlotComponent?>(comp.Owner, out var slot))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery))
|
if (!_cellSystem.TryGetBatteryFromSlot(comp.Owner, out var battery))
|
||||||
{
|
{
|
||||||
SoundSystem.Play(playerFilter, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
SoundSystem.Play(playerFilter, comp.TurnOnFailSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f));
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ namespace Content.Server.Weapon.Ranged.Barrels.Components
|
|||||||
throw new InvalidOperationException("Ammo doesn't have hitscan or projectile?");
|
throw new InvalidOperationException("Ammo doesn't have hitscan or projectile?");
|
||||||
}
|
}
|
||||||
|
|
||||||
Dirty();
|
// capacitor.UseCharge() triggers a PowerCellChangedEvent which will cause appearance to be updated.
|
||||||
UpdateAppearance();
|
// So let's not double-call UpdateAppearance() here.
|
||||||
return entity.Value;
|
return entity.Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ public sealed class PowerCellSlotComponent : Component
|
|||||||
public bool FitsInCharger = true;
|
public bool FitsInCharger = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised directed at an entity with a power cell slot when the power cell inside has its charge updated or is ejected/inserted.
|
||||||
|
/// </summary>
|
||||||
public class PowerCellChangedEvent : EntityEventArgs
|
public class PowerCellChangedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public readonly bool Ejected;
|
public readonly bool Ejected;
|
||||||
|
|||||||
Reference in New Issue
Block a user