Fix godmode mispredicts (#18524)
Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>
This commit is contained in:
14
Content.Shared/Damage/Components/GodmodeComponent.cs
Normal file
14
Content.Shared/Damage/Components/GodmodeComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Damage.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, Access(typeof(SharedGodmodeSystem))]
|
||||
public sealed class GodmodeComponent : Component
|
||||
{
|
||||
[DataField("wasMovedByPressure")]
|
||||
public bool WasMovedByPressure;
|
||||
|
||||
[DataField("oldDamage")]
|
||||
public DamageSpecifier? OldDamage = null;
|
||||
}
|
||||
84
Content.Shared/Damage/Systems/SharedGodmodeSystem.cs
Normal file
84
Content.Shared/Damage/Systems/SharedGodmodeSystem.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Content.Shared.Slippery;
|
||||
using Content.Shared.StatusEffect;
|
||||
|
||||
namespace Content.Shared.Damage.Systems;
|
||||
|
||||
public abstract class SharedGodmodeSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly DamageableSystem _damageable = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<GodmodeComponent, BeforeDamageChangedEvent>(OnBeforeDamageChanged);
|
||||
SubscribeLocalEvent<GodmodeComponent, BeforeStatusEffectAddedEvent>(OnBeforeStatusEffect);
|
||||
SubscribeLocalEvent<GodmodeComponent, BeforeStaminaDamageEvent>(OnBeforeStaminaDamage);
|
||||
SubscribeLocalEvent<GodmodeComponent, SlipAttemptEvent>(OnSlipAttempt);
|
||||
}
|
||||
|
||||
private void OnSlipAttempt(EntityUid uid, GodmodeComponent component, SlipAttemptEvent args)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
private void OnBeforeDamageChanged(EntityUid uid, GodmodeComponent component, ref BeforeDamageChangedEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnBeforeStatusEffect(EntityUid uid, GodmodeComponent component, ref BeforeStatusEffectAddedEvent args)
|
||||
{
|
||||
args.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnBeforeStaminaDamage(EntityUid uid, GodmodeComponent component, ref BeforeStaminaDamageEvent 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user