2023-08-04 14:53:07 +10:00
|
|
|
using Content.Shared.Damage.Components;
|
2025-04-14 17:27:26 +02:00
|
|
|
using Content.Shared.Damage.Events;
|
2025-05-09 22:06:19 -07:00
|
|
|
using Content.Shared.Destructible;
|
2025-08-06 09:53:38 -07:00
|
|
|
using Content.Shared.Nutrition;
|
2025-07-24 11:13:29 -04:00
|
|
|
using Content.Shared.Prototypes;
|
2023-08-04 14:53:07 +10:00
|
|
|
using Content.Shared.Rejuvenate;
|
|
|
|
|
using Content.Shared.Slippery;
|
2025-07-24 11:13:29 -04:00
|
|
|
using Content.Shared.StatusEffect;
|
2025-06-25 14:41:35 +03:00
|
|
|
using Content.Shared.StatusEffectNew;
|
2025-07-24 11:13:29 -04:00
|
|
|
using Content.Shared.StatusEffectNew.Components;
|
|
|
|
|
using Robust.Shared.Prototypes;
|
2023-08-04 14:53:07 +10:00
|
|
|
|
|
|
|
|
namespace Content.Shared.Damage.Systems;
|
|
|
|
|
|
|
|
|
|
public abstract class SharedGodmodeSystem : EntitySystem
|
|
|
|
|
{
|
2025-07-24 11:13:29 -04:00
|
|
|
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
2023-08-04 14:53:07 +10:00
|
|
|
[Dependency] private readonly DamageableSystem _damageable = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<GodmodeComponent, BeforeDamageChangedEvent>(OnBeforeDamageChanged);
|
|
|
|
|
SubscribeLocalEvent<GodmodeComponent, BeforeStatusEffectAddedEvent>(OnBeforeStatusEffect);
|
2025-07-24 11:13:29 -04:00
|
|
|
SubscribeLocalEvent<GodmodeComponent, BeforeOldStatusEffectAddedEvent>(OnBeforeOldStatusEffect);
|
2023-08-04 14:53:07 +10:00
|
|
|
SubscribeLocalEvent<GodmodeComponent, BeforeStaminaDamageEvent>(OnBeforeStaminaDamage);
|
2025-08-06 09:53:38 -07:00
|
|
|
SubscribeLocalEvent<GodmodeComponent, IngestibleEvent>(BeforeEdible);
|
2023-08-04 14:53:07 +10:00
|
|
|
SubscribeLocalEvent<GodmodeComponent, SlipAttemptEvent>(OnSlipAttempt);
|
2025-05-09 22:06:19 -07:00
|
|
|
SubscribeLocalEvent<GodmodeComponent, DestructionAttemptEvent>(OnDestruction);
|
2023-08-04 14:53:07 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args)
|
|
|
|
|
{
|
2024-08-23 11:59:51 +02:00
|
|
|
args.NoSlip = true;
|
2023-08-04 14:53:07 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args)
|
|
|
|
|
{
|
2025-07-24 11:13:29 -04:00
|
|
|
if (_protoMan.Index(args.Effect).HasComponent<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
|
2023-08-04 14:53:07 +10:00
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-09 22:06:19 -07:00
|
|
|
private void OnDestruction(Entity<GodmodeComponent> ent, ref DestructionAttemptEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancel();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-06 09:53:38 -07:00
|
|
|
private void BeforeEdible(Entity<GodmodeComponent> ent, ref IngestibleEvent args)
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 14:53:07 +10:00
|
|
|
public virtual void EnableGodmode(EntityUid uid, GodmodeComponent? godmode = null)
|
|
|
|
|
{
|
|
|
|
|
godmode ??= EnsureComp<GodmodeComponent>(uid);
|
|
|
|
|
|
|
|
|
|
if (TryComp<DamageableComponent>(uid, out var damageable))
|
|
|
|
|
{
|
|
|
|
|
godmode.OldDamage = new DamageSpecifier(damageable.Damage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
if (TryComp<DamageableComponent>(uid, out var damageable) && godmode.OldDamage != null)
|
|
|
|
|
{
|
|
|
|
|
_damageable.SetDamage(uid, damageable, godmode.OldDamage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|