Optimize status effects (#7429)
This commit is contained in:
@@ -24,6 +24,9 @@ namespace Content.Shared.StatusEffect
|
||||
public List<string> AllowedEffects = default!;
|
||||
}
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed class ActiveStatusEffectsComponent : Component {}
|
||||
|
||||
/// <summary>
|
||||
/// Holds information about an active status effect.
|
||||
/// </summary>
|
||||
|
||||
@@ -32,9 +32,8 @@ namespace Content.Shared.StatusEffect
|
||||
base.Update(frameTime);
|
||||
|
||||
var curTime = _gameTiming.CurTime;
|
||||
foreach (var status in EntityManager.EntityQuery<StatusEffectsComponent>(false))
|
||||
foreach (var (_, status) in EntityManager.EntityQuery<ActiveStatusEffectsComponent, StatusEffectsComponent>())
|
||||
{
|
||||
if (status.ActiveEffects.Count == 0) continue;
|
||||
foreach (var state in status.ActiveEffects.ToArray())
|
||||
{
|
||||
// if we're past the end point of the effect
|
||||
@@ -190,6 +189,7 @@ namespace Content.Shared.StatusEffect
|
||||
else
|
||||
{
|
||||
status.ActiveEffects.Add(key, new StatusEffectState(cooldown, refresh, null));
|
||||
EnsureComp<ActiveStatusEffectsComponent>(uid);
|
||||
}
|
||||
|
||||
if (proto.Alert != null)
|
||||
@@ -271,6 +271,10 @@ namespace Content.Shared.StatusEffect
|
||||
}
|
||||
|
||||
status.ActiveEffects.Remove(key);
|
||||
if (status.ActiveEffects.Count == 0)
|
||||
{
|
||||
RemComp<ActiveStatusEffectsComponent>(uid);
|
||||
}
|
||||
|
||||
Dirty(status);
|
||||
// event?
|
||||
|
||||
Reference in New Issue
Block a user