CatStation/Content.Shared/Damage/Systems/SharedGodmodeSystem.cs
SlamBamActionman b303948da6
Make glue/lube apply their effects immediately on held items (#44552)
* Initial commit

* Admin ghost/godmode immunity, inventory relay support

* Alphabetize review
2026-07-16 15:17:17 +00:00

110 lines
3.6 KiB
C#

using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Destructible;
using Content.Shared.Glue;
using Content.Shared.Lube;
using Content.Shared.Nutrition;
using Content.Shared.Prototypes;
using Content.Shared.Rejuvenate;
using Content.Shared.Slippery;
using Content.Shared.StatusEffect;
using Content.Shared.StatusEffectNew;
using Content.Shared.StatusEffectNew.Components;
namespace Content.Shared.Damage.Systems;
public abstract partial class SharedGodmodeSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<GodmodeComponent, BeforeDamageChangedEvent>(OnBeforeDamageChanged);
SubscribeLocalEvent<GodmodeComponent, BeforeStatusEffectAddedEvent>(OnBeforeStatusEffect);
SubscribeLocalEvent<GodmodeComponent, BeforeOldStatusEffectAddedEvent>(OnBeforeOldStatusEffect);
SubscribeLocalEvent<GodmodeComponent, BeforeStaminaDamageEvent>(OnBeforeStaminaDamage);
SubscribeLocalEvent<GodmodeComponent, IngestibleEvent>(BeforeEdible);
SubscribeLocalEvent<GodmodeComponent, SlipAttemptEvent>(OnSlipAttempt);
SubscribeLocalEvent<GodmodeComponent, DestructionAttemptEvent>(OnDestruction);
}
private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args)
{
args.NoSlip = true;
}
private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args)
{
args.Cancelled = true;
}
private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args)
{
if (ProtoMan.Index(args.Effect).HasComp<RejuvenateRemovedStatusEffectComponent>(Factory))
args.Cancelled = true;
}
private void OnBeforeOldStatusEffect(Entity<GodmodeComponent> ent, ref BeforeOldStatusEffectAddedEvent args)
{
// Old status effect system doesn't distinguish between good and bad status effects
args.Cancelled = true;
}
private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent args)
{
args.Cancelled = true;
}
private void OnDestruction(Entity<GodmodeComponent> ent, ref DestructionAttemptEvent args)
{
args.Cancel();
}
private void BeforeEdible(Entity<GodmodeComponent> ent, ref IngestibleEvent args)
{
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnGluedEffectAttemptEvent(Entity<GodmodeComponent> entity, ref GluedEffectAttemptEvent args)
{
args.Cancelled = true;
}
[SubscribeLocalEvent]
private void OnGluedEffectAttemptEvent(Entity<GodmodeComponent> entity, ref LubedEffectAttemptEvent args)
{
args.Cancelled = true;
}
public virtual void EnableGodmode(EntityUid uid, GodmodeComponent? godmode = null)
{
// Rejuv to cover other stuff
RaiseLocalEvent(uid, new RejuvenateEvent());
}
public virtual void DisableGodmode(EntityUid uid, GodmodeComponent? godmode = null)
{
if (!Resolve(uid, ref godmode, false))
return;
RemComp<GodmodeComponent>(uid);
}
/// <summary>
/// Toggles godmode for a given entity.
/// </summary>
/// <param name="uid">The entity to toggle godmode for.</param>
/// <returns>true if enabled, false if disabled.</returns>
public bool ToggleGodmode(EntityUid uid)
{
if (TryComp<GodmodeComponent>(uid, out var godmode))
{
DisableGodmode(uid, godmode);
return false;
}
EnableGodmode(uid, godmode);
return true;
}
}