SpawnExplosionEui.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Content.Server.EUI;
  2. using Content.Server.Explosion.EntitySystems;
  3. using Content.Shared.Administration;
  4. using Content.Shared.Eui;
  5. using JetBrains.Annotations;
  6. namespace Content.Server.Administration.UI;
  7. /// <summary>
  8. /// Admin Eui for spawning and preview-ing explosions
  9. /// </summary>
  10. [UsedImplicitly]
  11. public sealed class SpawnExplosionEui : BaseEui
  12. {
  13. private readonly ExplosionSystem _explosionSystem;
  14. private readonly ISawmill _sawmill;
  15. public SpawnExplosionEui()
  16. {
  17. _explosionSystem = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ExplosionSystem>();
  18. _sawmill = IoCManager.Resolve<ILogManager>().GetSawmill("explosion");
  19. }
  20. public override void HandleMessage(EuiMessageBase msg)
  21. {
  22. base.HandleMessage(msg);
  23. if (msg is not SpawnExplosionEuiMsg.PreviewRequest request)
  24. return;
  25. if (request.TotalIntensity <= 0 || request.IntensitySlope <= 0)
  26. return;
  27. var explosion = _explosionSystem.GenerateExplosionPreview(request);
  28. if (explosion == null)
  29. {
  30. _sawmill.Error("Failed to generate explosion preview.");
  31. return;
  32. }
  33. SendMessage(new SpawnExplosionEuiMsg.PreviewData(explosion, request.IntensitySlope, request.TotalIntensity));
  34. }
  35. }