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