LightningTargetSystem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Content.Server.Explosion.EntitySystems;
  2. using Content.Server.Lightning;
  3. using Content.Server.Lightning.Components;
  4. using Content.Shared.Damage;
  5. using Robust.Server.GameObjects;
  6. namespace Content.Server.Tesla.EntitySystems;
  7. /// <summary>
  8. /// The component allows lightning to strike this target. And determining the behavior of the target when struck by lightning.
  9. /// </summary>
  10. public sealed class LightningTargetSystem : EntitySystem
  11. {
  12. [Dependency] private readonly DamageableSystem _damageable = default!;
  13. [Dependency] private readonly ExplosionSystem _explosionSystem = default!;
  14. [Dependency] private readonly TransformSystem _transform = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<LightningTargetComponent, HitByLightningEvent>(OnHitByLightning);
  19. }
  20. private void OnHitByLightning(Entity<LightningTargetComponent> uid, ref HitByLightningEvent args)
  21. {
  22. DamageSpecifier damage = new();
  23. damage.DamageDict.Add("Structural", uid.Comp.DamageFromLightning);
  24. _damageable.TryChangeDamage(uid, damage, true);
  25. if (uid.Comp.LightningExplode)
  26. {
  27. _explosionSystem.QueueExplosion(
  28. _transform.GetMapCoordinates(uid),
  29. uid.Comp.ExplosionPrototype,
  30. uid.Comp.TotalIntensity, uid.Comp.Dropoff,
  31. uid.Comp.MaxTileIntensity,
  32. uid,
  33. canCreateVacuum: false);
  34. }
  35. }
  36. }