PoweredLightVariationPassSystem.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Content.Server.GameTicking.Rules.VariationPass.Components;
  2. using Content.Server.Light.Components;
  3. using Content.Server.Light.EntitySystems;
  4. using Content.Shared.Light.Components;
  5. using Robust.Shared.Random;
  6. namespace Content.Server.GameTicking.Rules.VariationPass;
  7. /// <inheritdoc cref="PoweredLightVariationPassComponent"/>
  8. public sealed class PoweredLightVariationPassSystem : VariationPassSystem<PoweredLightVariationPassComponent>
  9. {
  10. [Dependency] private readonly PoweredLightSystem _poweredLight = default!;
  11. protected override void ApplyVariation(Entity<PoweredLightVariationPassComponent> ent, ref StationVariationPassEvent args)
  12. {
  13. var query = AllEntityQuery<PoweredLightComponent, TransformComponent>();
  14. while (query.MoveNext(out var uid, out var comp, out var xform))
  15. {
  16. if (!IsMemberOfStation((uid, xform), ref args))
  17. continue;
  18. if (Random.Prob(ent.Comp.LightBreakChance))
  19. {
  20. var proto = comp.BulbType switch
  21. {
  22. LightBulbType.Tube => ent.Comp.BrokenLightTubePrototype,
  23. _ => ent.Comp.BrokenLightBulbPrototype,
  24. };
  25. _poweredLight.ReplaceSpawnedPrototype((uid, comp), proto);
  26. continue;
  27. }
  28. if (!Random.Prob(ent.Comp.LightAgingChance))
  29. continue;
  30. if (comp.BulbType == LightBulbType.Tube)
  31. {
  32. // some aging fluorescents (tubes) start to flicker
  33. // its also way too annoying right now so we wrap it in another prob lol
  34. if (Random.Prob(ent.Comp.AgedLightTubeFlickerChance))
  35. _poweredLight.ToggleBlinkingLight(uid, comp, true);
  36. _poweredLight.ReplaceSpawnedPrototype((uid, comp), ent.Comp.AgedLightTubePrototype);
  37. }
  38. else
  39. {
  40. _poweredLight.ReplaceSpawnedPrototype((uid, comp), ent.Comp.AgedLightBulbPrototype);
  41. }
  42. }
  43. }
  44. }