GunSystem.SpentAmmo.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Content.Client.Weapons.Ranged.Components;
  2. using Content.Shared.Weapons.Ranged.Systems;
  3. using Robust.Client.GameObjects;
  4. namespace Content.Client.Weapons.Ranged.Systems;
  5. public sealed partial class GunSystem
  6. {
  7. private void InitializeSpentAmmo()
  8. {
  9. SubscribeLocalEvent<SpentAmmoVisualsComponent, AppearanceChangeEvent>(OnSpentAmmoAppearance);
  10. }
  11. private void OnSpentAmmoAppearance(EntityUid uid, SpentAmmoVisualsComponent component, ref AppearanceChangeEvent args)
  12. {
  13. var sprite = args.Sprite;
  14. if (sprite == null) return;
  15. if (!args.AppearanceData.TryGetValue(AmmoVisuals.Spent, out var varSpent))
  16. {
  17. return;
  18. }
  19. var spent = (bool) varSpent;
  20. string state;
  21. if (spent)
  22. state = component.Suffix ? $"{component.State}-spent" : "spent";
  23. else
  24. state = component.State;
  25. sprite.LayerSetState(AmmoVisualLayers.Base, state);
  26. if (sprite.LayerExists(AmmoVisualLayers.Tip)){
  27. sprite.RemoveLayer(AmmoVisualLayers.Tip);
  28. }
  29. }
  30. }