VentCrittersRule.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Content.Server.StationEvents.Components;
  2. using Content.Shared.GameTicking.Components;
  3. using Content.Shared.Station.Components;
  4. using Content.Shared.Storage;
  5. using Robust.Shared.Map;
  6. using Robust.Shared.Random;
  7. namespace Content.Server.StationEvents.Events;
  8. public sealed class VentCrittersRule : StationEventSystem<VentCrittersRuleComponent>
  9. {
  10. /*
  11. * DO NOT COPY PASTE THIS TO MAKE YOUR MOB EVENT.
  12. * USE THE PROTOTYPE.
  13. */
  14. protected override void Started(EntityUid uid, VentCrittersRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  15. {
  16. base.Started(uid, component, gameRule, args);
  17. if (!TryGetRandomStation(out var station))
  18. {
  19. return;
  20. }
  21. var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
  22. var validLocations = new List<EntityCoordinates>();
  23. while (locations.MoveNext(out _, out _, out var transform))
  24. {
  25. if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station == station)
  26. {
  27. validLocations.Add(transform.Coordinates);
  28. foreach (var spawn in EntitySpawnCollection.GetSpawns(component.Entries, RobustRandom))
  29. {
  30. Spawn(spawn, transform.Coordinates);
  31. }
  32. }
  33. }
  34. if (component.SpecialEntries.Count == 0 || validLocations.Count == 0)
  35. {
  36. return;
  37. }
  38. // guaranteed spawn
  39. var specialEntry = RobustRandom.Pick(component.SpecialEntries);
  40. var specialSpawn = RobustRandom.Pick(validLocations);
  41. Spawn(specialEntry.PrototypeId, specialSpawn);
  42. foreach (var location in validLocations)
  43. {
  44. foreach (var spawn in EntitySpawnCollection.GetSpawns(component.SpecialEntries, RobustRandom))
  45. {
  46. Spawn(spawn, location);
  47. }
  48. }
  49. }
  50. }