1
0

SharedGodmodeSystem.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // SPDX-FileCopyrightText: 2023 Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
  2. // SPDX-FileCopyrightText: 2023 metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
  3. // SPDX-FileCopyrightText: 2024 SlamBamActionman <83650252+SlamBamActionman@users.noreply.github.com>
  4. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  5. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  6. //
  7. // SPDX-License-Identifier: AGPL-3.0-or-later
  8. using Content.Shared.Damage.Components;
  9. using Content.Shared.Rejuvenate;
  10. using Content.Shared.Slippery;
  11. using Content.Shared.StatusEffect;
  12. using Content.Shared.Body.Systems; // Shitmed Change
  13. namespace Content.Shared.Damage.Systems;
  14. public abstract class SharedGodmodeSystem : EntitySystem
  15. {
  16. [Dependency] private readonly DamageableSystem _damageable = default!;
  17. [Dependency] private readonly SharedBodySystem _bodySystem = default!; // Shitmed Change
  18. public override void Initialize()
  19. {
  20. base.Initialize();
  21. SubscribeLocalEvent<GodmodeComponent, BeforeDamageChangedEvent>(OnBeforeDamageChanged);
  22. SubscribeLocalEvent<GodmodeComponent, BeforeStatusEffectAddedEvent>(OnBeforeStatusEffect);
  23. SubscribeLocalEvent<GodmodeComponent, BeforeStaminaDamageEvent>(OnBeforeStaminaDamage);
  24. SubscribeLocalEvent<GodmodeComponent, SlipAttemptEvent>(OnSlipAttempt);
  25. }
  26. private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args)
  27. {
  28. args.NoSlip = true;
  29. }
  30. private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args)
  31. {
  32. args.Cancelled = true;
  33. }
  34. private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args)
  35. {
  36. args.Cancelled = true;
  37. }
  38. private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent args)
  39. {
  40. args.Cancelled = true;
  41. }
  42. public virtual void EnableGodmode(EntityUid uid, GodmodeComponent? godmode = null)
  43. {
  44. godmode ??= EnsureComp<GodmodeComponent>(uid);
  45. if (TryComp<DamageableComponent>(uid, out var damageable))
  46. {
  47. godmode.OldDamage = new DamageSpecifier(damageable.Damage);
  48. }
  49. // Rejuv to cover other stuff
  50. RaiseLocalEvent(uid, new RejuvenateEvent());
  51. foreach (var (id, _) in _bodySystem.GetBodyChildren(uid)) // Shitmed Change
  52. EnableGodmode(id);
  53. }
  54. public virtual void DisableGodmode(EntityUid uid, GodmodeComponent? godmode = null)
  55. {
  56. if (!Resolve(uid, ref godmode, false))
  57. return;
  58. if (TryComp<DamageableComponent>(uid, out var damageable) && godmode.OldDamage != null)
  59. {
  60. _damageable.SetDamage(uid, damageable, godmode.OldDamage);
  61. }
  62. RemComp<GodmodeComponent>(uid);
  63. foreach (var (id, _) in _bodySystem.GetBodyChildren(uid)) // Shitmed Change
  64. DisableGodmode(id);
  65. }
  66. /// <summary>
  67. /// Toggles godmode for a given entity.
  68. /// </summary>
  69. /// <param name="uid">The entity to toggle godmode for.</param>
  70. /// <returns>true if enabled, false if disabled.</returns>
  71. public bool ToggleGodmode(EntityUid uid)
  72. {
  73. if (TryComp<GodmodeComponent>(uid, out var godmode))
  74. {
  75. DisableGodmode(uid, godmode);
  76. return false;
  77. }
  78. EnableGodmode(uid, godmode);
  79. return true;
  80. }
  81. }