1
0

DamagePopupSystem.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Linq;
  2. using Content.Server.Damage.Components;
  3. using Content.Server.Popups;
  4. using Content.Shared.Damage;
  5. using Content.Shared.Interaction;
  6. namespace Content.Server.Damage.Systems;
  7. public sealed class DamagePopupSystem : EntitySystem
  8. {
  9. [Dependency] private readonly PopupSystem _popupSystem = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<DamagePopupComponent, DamageChangedEvent>(OnDamageChange);
  14. SubscribeLocalEvent<DamagePopupComponent, InteractHandEvent>(OnInteractHand);
  15. }
  16. private void OnDamageChange(EntityUid uid, DamagePopupComponent component, DamageChangedEvent args)
  17. {
  18. if (args.DamageDelta != null)
  19. {
  20. var damageTotal = args.Damageable.TotalDamage;
  21. var damageDelta = args.DamageDelta.GetTotal();
  22. var msg = component.Type switch
  23. {
  24. DamagePopupType.Delta => damageDelta.ToString(),
  25. DamagePopupType.Total => damageTotal.ToString(),
  26. DamagePopupType.Combined => damageDelta + " | " + damageTotal,
  27. DamagePopupType.Hit => "!",
  28. _ => "Invalid type",
  29. };
  30. _popupSystem.PopupEntity(msg, uid);
  31. }
  32. }
  33. private void OnInteractHand(EntityUid uid, DamagePopupComponent component, InteractHandEvent args)
  34. {
  35. if (component.AllowTypeChange)
  36. {
  37. if (component.Type == Enum.GetValues(typeof(DamagePopupType)).Cast<DamagePopupType>().Last())
  38. {
  39. component.Type = Enum.GetValues(typeof(DamagePopupType)).Cast<DamagePopupType>().First();
  40. }
  41. else
  42. {
  43. component.Type = (DamagePopupType) (int) component.Type + 1;
  44. }
  45. _popupSystem.PopupEntity("Target set to type: " + component.Type.ToString(), uid);
  46. }
  47. }
  48. }