ExplosionReactionEffect.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using Content.Server.Explosion.EntitySystems;
  2. using Content.Shared.Database;
  3. using Content.Shared.EntityEffects;
  4. using Content.Shared.Explosion;
  5. using Robust.Shared.Prototypes;
  6. using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
  7. using System.Text.Json.Serialization;
  8. namespace Content.Server.EntityEffects.Effects;
  9. [DataDefinition]
  10. public sealed partial class ExplosionReactionEffect : EntityEffect
  11. {
  12. /// <summary>
  13. /// The type of explosion. Determines damage types and tile break chance scaling.
  14. /// </summary>
  15. [DataField(required: true, customTypeSerializer: typeof(PrototypeIdSerializer<ExplosionPrototype>))]
  16. public string ExplosionType = default!;
  17. /// <summary>
  18. /// The max intensity the explosion can have at a given tile. Places an upper limit of damage and tile break
  19. /// chance.
  20. /// </summary>
  21. [DataField]
  22. public float MaxIntensity = 5;
  23. /// <summary>
  24. /// How quickly intensity drops off as you move away from the epicenter
  25. /// </summary>
  26. [DataField]
  27. public float IntensitySlope = 1;
  28. /// <summary>
  29. /// The maximum total intensity that this chemical reaction can achieve. Basically here to prevent people
  30. /// from creating a nuke by collecting enough potassium and water.
  31. /// </summary>
  32. /// <remarks>
  33. /// A slope of 1 and MaxTotalIntensity of 100 corresponds to a radius of around 4.5 tiles.
  34. /// </remarks>
  35. [DataField]
  36. public float MaxTotalIntensity = 100;
  37. /// <summary>
  38. /// The intensity of the explosion per unit reaction.
  39. /// </summary>
  40. [DataField]
  41. public float IntensityPerUnit = 1;
  42. /// <summary>
  43. /// Factor used to scale the explosion intensity when calculating tile break chances. Allows for stronger
  44. /// explosives that don't space tiles, without having to create a new explosion-type prototype.
  45. /// </summary>
  46. [DataField]
  47. public float TileBreakScale = 1f;
  48. public override bool ShouldLog => true;
  49. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  50. => Loc.GetString("reagent-effect-guidebook-explosion-reaction-effect", ("chance", Probability));
  51. public override LogImpact LogImpact => LogImpact.High;
  52. public override void Effect(EntityEffectBaseArgs args)
  53. {
  54. var intensity = IntensityPerUnit;
  55. if (args is EntityEffectReagentArgs reagentArgs)
  56. {
  57. intensity = MathF.Min((float) reagentArgs.Quantity * IntensityPerUnit, MaxTotalIntensity);
  58. }
  59. args.EntityManager.System<ExplosionSystem>()
  60. .QueueExplosion(
  61. args.TargetEntity,
  62. ExplosionType,
  63. intensity,
  64. IntensitySlope,
  65. MaxIntensity,
  66. TileBreakScale);
  67. }
  68. }