feat: add a component for rejuvenateable status effects (#39025)

* feat: add a component for rejuvenateable effects

* feat: let god mode'd entities get buffs

* fix: handle old status effect system

Didn't realize BeforeStatusEffectAddedEvent was called by both systems,
oops.

* refactor: rename to RejuvenateRemovedStatusEffect

* fix: make forced sleeping a debuff again

Missed in rebase.

* refactor: make BeforeStatusEffectAdded two events
This commit is contained in:
Perry Fraser
2025-07-24 11:13:29 -04:00
committed by GitHub
parent 82c0f63d50
commit b0e1ce7c0c
7 changed files with 63 additions and 9 deletions

View File

@@ -1,14 +1,19 @@
using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Destructible;
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;
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()
@@ -17,6 +22,7 @@ public abstract class SharedGodmodeSystem : EntitySystem
SubscribeLocalEvent<GodmodeComponent, BeforeDamageChangedEvent>(OnBeforeDamageChanged);
SubscribeLocalEvent<GodmodeComponent, BeforeStatusEffectAddedEvent>(OnBeforeStatusEffect);
SubscribeLocalEvent<GodmodeComponent, BeforeOldStatusEffectAddedEvent>(OnBeforeOldStatusEffect);
SubscribeLocalEvent<GodmodeComponent, BeforeStaminaDamageEvent>(OnBeforeStaminaDamage);
SubscribeLocalEvent<GodmodeComponent, SlipAttemptEvent>(OnSlipAttempt);
SubscribeLocalEvent<GodmodeComponent, DestructionAttemptEvent>(OnDestruction);
@@ -34,6 +40,13 @@ public abstract class SharedGodmodeSystem : EntitySystem
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;
}

View File

@@ -353,7 +353,7 @@ namespace Content.Shared.StatusEffect
if (!Resolve(uid, ref status, false))
return false;
var ev = new BeforeStatusEffectAddedEvent(key);
var ev = new BeforeOldStatusEffectAddedEvent(key);
RaiseLocalEvent(uid, ref ev);
if (ev.Cancelled)
return false;
@@ -481,6 +481,13 @@ namespace Content.Shared.StatusEffect
}
}
/// <summary>
/// Raised on an entity before a status effect is added to determine if adding it should be cancelled.
/// Obsolete version of <see cref="BeforeStatusEffectAddedEvent" />
/// </summary>
[ByRefEvent, Obsolete("Migration to StatusEffectNew.StatusEffectsSystem is required")]
public record struct BeforeOldStatusEffectAddedEvent(string EffectKey, bool Cancelled = false);
public readonly struct StatusEffectAddedEvent
{
public readonly EntityUid Uid;

View File

@@ -0,0 +1,14 @@
using Content.Shared.Damage.Components;
using Content.Shared.Rejuvenate;
using Robust.Shared.GameStates;
namespace Content.Shared.StatusEffectNew.Components;
/// <summary>
/// Marker component for a status effect that should be removed on rejuvenation
/// and should not be applied on targets with <see cref="GodmodeComponent" />.
/// Only applies to effects using the new <see cref="StatusEffectsSystem" />.
/// </summary>
/// <seealso cref="RejuvenateEvent"/>
[RegisterComponent, NetworkedComponent]
public sealed partial class RejuvenateRemovedStatusEffectComponent : Component;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Rejuvenate;
using Content.Shared.StatusEffectNew.Components;
using Content.Shared.Stunnable;
using Robust.Shared.Player;
@@ -12,6 +13,7 @@ public sealed partial class StatusEffectsSystem
{
SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerAttachedEvent>(RelayStatusEffectEvent);
SubscribeLocalEvent<StatusEffectContainerComponent, LocalPlayerDetachedEvent>(RelayStatusEffectEvent);
SubscribeLocalEvent<StatusEffectContainerComponent, RejuvenateEvent>(RelayStatusEffectEvent);
SubscribeLocalEvent<StatusEffectContainerComponent, RefreshMovementSpeedModifiersEvent>(RelayStatusEffectEvent);
SubscribeLocalEvent<StatusEffectContainerComponent, UpdateCanMoveEvent>(RelayStatusEffectEvent);

View File

@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Rejuvenate;
using Content.Shared.StatusEffectNew.Components;
using Content.Shared.Whitelist;
using Robust.Shared.Containers;
@@ -32,6 +33,8 @@ public sealed partial class StatusEffectsSystem : EntitySystem
SubscribeLocalEvent<StatusEffectContainerComponent, EntInsertedIntoContainerMessage>(OnEntityInserted);
SubscribeLocalEvent<StatusEffectContainerComponent, EntRemovedFromContainerMessage>(OnEntityRemoved);
SubscribeLocalEvent<RejuvenateRemovedStatusEffectComponent, StatusEffectRelayedEvent<RejuvenateEvent>>(OnRejuvenate);
_containerQuery = GetEntityQuery<StatusEffectContainerComponent>();
_effectQuery = GetEntityQuery<StatusEffectComponent>();
}
@@ -115,6 +118,12 @@ public sealed partial class StatusEffectsSystem : EntitySystem
Dirty(args.Entity, statusComp);
}
private void OnRejuvenate(Entity<RejuvenateRemovedStatusEffectComponent> ent,
ref StatusEffectRelayedEvent<RejuvenateEvent> args)
{
PredictedQueueDel(ent.Owner);
}
private void SetStatusEffectTime(EntityUid effect, TimeSpan? duration)
{
if (!_effectQuery.TryComp(effect, out var effectComp))

View File

@@ -19,8 +19,17 @@
components:
- MobState
# Things that should be removed by rejuvenation should parent to this
# Also blocks the status effect being added to godmode-ed entities.
- type: entity
parent: StatusEffectBase
parent: MobStatusEffectBase
id: MobStatusEffectDebuff
abstract: true
components:
- type: RejuvenateRemovedStatusEffect
- type: entity
parent: MobStatusEffectDebuff
id: MobStandStatusEffectBase
abstract: true
components:
@@ -36,7 +45,7 @@
# The creature sleeps so heavily that nothing can wake him up. Not even its own death.
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff
id: StatusEffectForcedSleeping
name: forced sleep
components:
@@ -46,7 +55,7 @@
# This creature is asleep because it's disconnected from the game.
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectBase # Not even rejuvenate can cure SSD...
id: StatusEffectSSDSleeping
name: forced sleep
components:
@@ -56,7 +65,7 @@
# Blurs your vision and makes you randomly fall asleep
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff
id: StatusEffectDrowsiness
name: drowsiness
components:
@@ -64,7 +73,7 @@
# Adds drugs overlay
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff
id: StatusEffectSeeingRainbow
name: hallucinations
components:

View File

@@ -1,5 +1,5 @@
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff
id: StatusEffectSlowdown
abstract: true
name: slowdown
@@ -35,7 +35,7 @@
# Makes you more slippery, or perhaps less slippery.
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff # Debatable if this should be MobStatusEffectBase or not
id: StatusEffectFriction
name: friction
components:
@@ -44,7 +44,7 @@
# Stunnable Status Effect
- type: entity
parent: MobStatusEffectBase
parent: MobStatusEffectDebuff
id: StatusEffectStunned
name: stunned
components: