TelepathicArtifactSystem.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
  2. using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
  3. using Content.Shared.Popups;
  4. using Robust.Server.GameObjects;
  5. using Robust.Shared.Player;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
  8. public sealed class TelepathicArtifactSystem : EntitySystem
  9. {
  10. [Dependency] private readonly IRobustRandom _random = default!;
  11. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  12. [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
  13. public override void Initialize()
  14. {
  15. base.Initialize();
  16. SubscribeLocalEvent<TelepathicArtifactComponent, ArtifactActivatedEvent>(OnActivate);
  17. }
  18. private void OnActivate(EntityUid uid, TelepathicArtifactComponent component, ArtifactActivatedEvent args)
  19. {
  20. // try to find victims nearby
  21. var victims = _lookup.GetEntitiesInRange(uid, component.Range);
  22. foreach (var victimUid in victims)
  23. {
  24. if (!EntityManager.HasComponent<ActorComponent>(victimUid))
  25. continue;
  26. // roll if msg should be usual or drastic
  27. List<string> msgArr;
  28. if (_random.NextFloat() <= component.DrasticMessageProb && component.DrasticMessages != null)
  29. {
  30. msgArr = component.DrasticMessages;
  31. }
  32. else
  33. {
  34. msgArr = component.Messages;
  35. }
  36. // pick a random message
  37. var msgId = _random.Pick(msgArr);
  38. var msg = Loc.GetString(msgId);
  39. // show it as a popup, but only for the victim
  40. _popupSystem.PopupEntity(msg, victimUid, victimUid);
  41. }
  42. }
  43. }