Files

113 lines
3.8 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Destructible;
using Content.Shared.Nutrition;
using Content.Shared.Prototypes;
using Content.Shared.Rejuvenate;
using Content.Shared.Slippery;
using Content.Shared.StatusEffect;
New status effect system (#37238) * spectra * documentation * added into liquid anomaly * Update TemporaryStealthComponent.cs * Update TemporaryStealthComponent.cs * integrated * new system * mark old status effect system as obsolete * ForcedSleeping new status effect * work with reagents * networking??? * Revert "integrated" This reverts commit bca02b82bae18ae131af593d7eb86e6de2745157. * Revert "Update TemporaryStealthComponent.cs" This reverts commit 4a5be8c4b704a0d1ff9544b2e245d8b2701ec580. * Revert "Update TemporaryStealthComponent.cs" This reverts commit a4875bcb41347638854bd723d96a51c3e6d38034. * Revert "added into liquid anomaly" This reverts commit df5086b14bb35f1467158a36807c0f2163a16d99. * Revert "documentation" This reverts commit 3629b9466758cbdfa4dd5e67ece122fa2f181138. * Revert "spectra" This reverts commit 2d03d88c16d16ad6831c19a7921b84600daeb284. * drowsiness status effect remove * reagents work * polish, remove test changes * first Fildrance review part * Update misc.yml * more fildrance review * final part * fix trailing spaces * sleeping status effect * drowsiness status effect * Create ModifyStatusEffect.cs * some tweak * Yay!!! Manual networking * minor nitpick * oopsie * refactor: xml-docs, notnullwhen attributes, whitespaces * fildrance and emo review * refactor: simplify check in SharedStatusEffectsSystem by using pattern matching, TryEffectsWithComp now returns set of Entity<T, StatusEffectComponent> --------- Co-authored-by: pa.pecherskij <pa.pecherskij@interfax.ru>
2025-06-25 14:41:35 +03:00
using Content.Shared.StatusEffectNew;
using Content.Shared.StatusEffectNew.Components;
using Robust.Shared.Prototypes;
namespace Content.Shared.Damage.Systems;
public abstract class SharedGodmodeSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
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).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
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;
}
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;
}
}