1
0

PopupMessage.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Content.Shared.EntityEffects;
  2. using Content.Shared.Popups;
  3. using Robust.Shared.Prototypes;
  4. using Robust.Shared.Random;
  5. namespace Content.Server.EntityEffects.Effects
  6. {
  7. public sealed partial class PopupMessage : EntityEffect
  8. {
  9. [DataField(required: true)]
  10. public string[] Messages = default!;
  11. [DataField]
  12. public PopupRecipients Type = PopupRecipients.Local;
  13. [DataField]
  14. public PopupType VisualType = PopupType.Small;
  15. // JUSTIFICATION: This is purely cosmetic.
  16. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  17. => null;
  18. public override void Effect(EntityEffectBaseArgs args)
  19. {
  20. var popupSys = args.EntityManager.EntitySysManager.GetEntitySystem<SharedPopupSystem>();
  21. var random = IoCManager.Resolve<IRobustRandom>();
  22. var msg = random.Pick(Messages);
  23. var msgArgs = new (string, object)[]
  24. {
  25. ("entity", args.TargetEntity),
  26. };
  27. if (args is EntityEffectReagentArgs reagentArgs)
  28. {
  29. msgArgs = new (string, object)[]
  30. {
  31. ("entity", reagentArgs.TargetEntity),
  32. ("organ", reagentArgs.OrganEntity.GetValueOrDefault()),
  33. };
  34. }
  35. if (Type == PopupRecipients.Local)
  36. popupSys.PopupEntity(Loc.GetString(msg, msgArgs), args.TargetEntity, args.TargetEntity, VisualType);
  37. else if (Type == PopupRecipients.Pvs)
  38. popupSys.PopupEntity(Loc.GetString(msg, msgArgs), args.TargetEntity, VisualType);
  39. }
  40. }
  41. public enum PopupRecipients
  42. {
  43. Pvs,
  44. Local
  45. }
  46. }