SharedElectrocutionSystem.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Content.Shared.Inventory;
  2. using Content.Shared.StatusEffect;
  3. namespace Content.Shared.Electrocution
  4. {
  5. public abstract class SharedElectrocutionSystem : EntitySystem
  6. {
  7. [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
  8. public override void Initialize()
  9. {
  10. base.Initialize();
  11. SubscribeLocalEvent<InsulatedComponent, ElectrocutionAttemptEvent>(OnInsulatedElectrocutionAttempt);
  12. // as long as legally distinct electric-mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer).
  13. SubscribeLocalEvent<InsulatedComponent, InventoryRelayedEvent<ElectrocutionAttemptEvent>>((e, c, ev) => OnInsulatedElectrocutionAttempt(e, c, ev.Args));
  14. }
  15. public void SetInsulatedSiemensCoefficient(EntityUid uid, float siemensCoefficient, InsulatedComponent? insulated = null)
  16. {
  17. if (!Resolve(uid, ref insulated))
  18. return;
  19. insulated.Coefficient = siemensCoefficient;
  20. Dirty(uid, insulated);
  21. }
  22. /// <summary>
  23. /// Sets electrified value of component and marks dirty if required.
  24. /// </summary>
  25. public void SetElectrified(Entity<ElectrifiedComponent> ent, bool value)
  26. {
  27. if (ent.Comp.Enabled == value)
  28. {
  29. return;
  30. }
  31. ent.Comp.Enabled = value;
  32. Dirty(ent, ent.Comp);
  33. _appearance.SetData(ent.Owner, ElectrifiedVisuals.IsElectrified, value);
  34. }
  35. public void SetElectrifiedWireCut(Entity<ElectrifiedComponent> ent, bool value)
  36. {
  37. if (ent.Comp.IsWireCut == value)
  38. {
  39. return;
  40. }
  41. ent.Comp.IsWireCut = value;
  42. Dirty(ent);
  43. }
  44. /// <param name="uid">Entity being electrocuted.</param>
  45. /// <param name="sourceUid">Source entity of the electrocution.</param>
  46. /// <param name="shockDamage">How much shock damage the entity takes.</param>
  47. /// <param name="time">How long the entity will be stunned.</param>
  48. /// <param name="refresh">Should <paramref>time</paramref> be refreshed (instead of accumilated) if the entity is already electrocuted?</param>
  49. /// <param name="siemensCoefficient">How insulated the entity is from the shock. 0 means completely insulated, and 1 means no insulation.</param>
  50. /// <param name="statusEffects">Status effects to apply to the entity.</param>
  51. /// <param name="ignoreInsulation">Should the electrocution bypass the Insulated component?</param>
  52. /// <returns>Whether the entity <see cref="uid"/> was stunned by the shock.</returns>
  53. public virtual bool TryDoElectrocution(
  54. EntityUid uid, EntityUid? sourceUid, int shockDamage, TimeSpan time, bool refresh, float siemensCoefficient = 1f,
  55. StatusEffectsComponent? statusEffects = null, bool ignoreInsulation = false)
  56. {
  57. // only done serverside
  58. return false;
  59. }
  60. private void OnInsulatedElectrocutionAttempt(EntityUid uid, InsulatedComponent insulated, ElectrocutionAttemptEvent args)
  61. {
  62. args.SiemensCoefficient *= insulated.Coefficient;
  63. }
  64. }
  65. }