SecretDataAnomalySystem.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Content.Server.Anomaly.Components;
  2. using Robust.Shared.Random;
  3. namespace Content.Server.Anomaly.Effects;
  4. public sealed class SecretDataAnomalySystem : EntitySystem
  5. {
  6. [Dependency] private readonly IRobustRandom _random = default!;
  7. private readonly List<AnomalySecretData> _deita = new();
  8. public override void Initialize()
  9. {
  10. SubscribeLocalEvent<SecretDataAnomalyComponent, MapInitEvent>(OnMapInit);
  11. }
  12. private void OnMapInit(EntityUid uid, SecretDataAnomalyComponent anomaly, MapInitEvent args)
  13. {
  14. RandomizeSecret(uid,_random.Next(anomaly.RandomStartSecretMin, anomaly.RandomStartSecretMax), anomaly);
  15. }
  16. public void RandomizeSecret(EntityUid uid, int count, SecretDataAnomalyComponent? component = null)
  17. {
  18. if (!Resolve(uid, ref component))
  19. return;
  20. component.Secret.Clear();
  21. // I also considered just adding all the enum values and pruning but that seems more wasteful.
  22. _deita.Clear();
  23. _deita.AddRange(Enum.GetValues<AnomalySecretData>());
  24. var actualCount = Math.Min(count, _deita.Count);
  25. for (int i = 0; i < actualCount; i++)
  26. {
  27. component.Secret.Add(_random.PickAndTake(_deita));
  28. }
  29. }
  30. }