FlashReactionEffect.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Content.Shared.EntityEffects;
  2. using Content.Server.Flash;
  3. using Robust.Server.GameObjects;
  4. using Robust.Shared.Audio;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.EntityEffects.Effects;
  7. [DataDefinition]
  8. public sealed partial class FlashReactionEffect : EntityEffect
  9. {
  10. /// <summary>
  11. /// Flash range per unit of reagent.
  12. /// </summary>
  13. [DataField]
  14. public float RangePerUnit = 0.2f;
  15. /// <summary>
  16. /// Maximum flash range.
  17. /// </summary>
  18. [DataField]
  19. public float MaxRange = 10f;
  20. /// <summary>
  21. /// How much to entities are slowed down.
  22. /// </summary>
  23. [DataField]
  24. public float SlowTo = 0.5f;
  25. /// <summary>
  26. /// The time entities will be flashed in seconds.
  27. /// The default is chosen to be better than the hand flash so it is worth using it for grenades etc.
  28. /// </summary>
  29. [DataField]
  30. public float Duration = 4f;
  31. /// <summary>
  32. /// The prototype ID used for the visual effect.
  33. /// </summary>
  34. [DataField]
  35. public EntProtoId? FlashEffectPrototype = "ReactionFlash";
  36. /// <summary>
  37. /// The sound the flash creates.
  38. /// </summary>
  39. [DataField]
  40. public SoundSpecifier? Sound = new SoundPathSpecifier("/Audio/Weapons/flash.ogg");
  41. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  42. => Loc.GetString("reagent-effect-guidebook-flash-reaction-effect", ("chance", Probability));
  43. public override void Effect(EntityEffectBaseArgs args)
  44. {
  45. var transform = args.EntityManager.GetComponent<TransformComponent>(args.TargetEntity);
  46. var transformSystem = args.EntityManager.System<SharedTransformSystem>();
  47. var range = 1f;
  48. if (args is EntityEffectReagentArgs reagentArgs)
  49. range = MathF.Min((float)(reagentArgs.Quantity * RangePerUnit), MaxRange);
  50. args.EntityManager.System<FlashSystem>().FlashArea(
  51. args.TargetEntity,
  52. null,
  53. range,
  54. Duration * 1000,
  55. slowTo: SlowTo,
  56. sound: Sound);
  57. if (FlashEffectPrototype == null)
  58. return;
  59. var uid = args.EntityManager.SpawnEntity(FlashEffectPrototype, transformSystem.GetMapCoordinates(transform));
  60. transformSystem.AttachToGridOrMap(uid);
  61. if (!args.EntityManager.TryGetComponent<PointLightComponent>(uid, out var pointLightComp))
  62. return;
  63. var pointLightSystem = args.EntityManager.System<SharedPointLightSystem>();
  64. // PointLights with a radius lower than 1.1 are too small to be visible, so this is hardcoded
  65. pointLightSystem.SetRadius(uid, MathF.Max(1.1f, range), pointLightComp);
  66. }
  67. }