DamageStateVisualizerSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Shared.Mobs;
  2. using Robust.Client.GameObjects;
  3. using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
  4. namespace Content.Client.DamageState;
  5. public sealed class DamageStateVisualizerSystem : VisualizerSystem<DamageStateVisualsComponent>
  6. {
  7. protected override void OnAppearanceChange(EntityUid uid, DamageStateVisualsComponent component, ref AppearanceChangeEvent args)
  8. {
  9. var sprite = args.Sprite;
  10. if (sprite == null || !AppearanceSystem.TryGetData<MobState>(uid, MobStateVisuals.State, out var data, args.Component))
  11. {
  12. return;
  13. }
  14. if (!component.States.TryGetValue(data, out var layers))
  15. {
  16. return;
  17. }
  18. // Brain no worky rn so this was just easier.
  19. foreach (var key in new []{ DamageStateVisualLayers.Base, DamageStateVisualLayers.BaseUnshaded })
  20. {
  21. if (!sprite.LayerMapTryGet(key, out _)) continue;
  22. sprite.LayerSetVisible(key, false);
  23. }
  24. foreach (var (key, state) in layers)
  25. {
  26. // Inheritance moment.
  27. if (!sprite.LayerMapTryGet(key, out _)) continue;
  28. sprite.LayerSetVisible(key, true);
  29. sprite.LayerSetState(key, state);
  30. }
  31. // So they don't draw over mobs anymore
  32. if (data == MobState.Dead)
  33. {
  34. if (sprite.DrawDepth > (int) DrawDepth.DeadMobs)
  35. {
  36. component.OriginalDrawDepth = sprite.DrawDepth;
  37. sprite.DrawDepth = (int) DrawDepth.DeadMobs;
  38. }
  39. }
  40. else if (component.OriginalDrawDepth != null)
  41. {
  42. sprite.DrawDepth = component.OriginalDrawDepth.Value;
  43. component.OriginalDrawDepth = null;
  44. }
  45. }
  46. }