diff --git a/Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs b/Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs index 2144b5a0c1..56636c9601 100644 --- a/Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs +++ b/Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs @@ -69,7 +69,7 @@ public sealed partial class StatusEffectsSystem if (!TryGetStatusEffect(target, effectProto, out statusEffect)) return TryAddStatusEffect(target, effectProto, out statusEffect, duration); - SetStatusEffectTime(statusEffect.Value, duration); + SetStatusEffectEndTime(statusEffect.Value, duration); return true; } @@ -291,7 +291,7 @@ public sealed partial class StatusEffectsSystem var meta = MetaData(effect); if (meta.EntityPrototype is not null && meta.EntityPrototype == effectProto) { - SetStatusEffectTime(effect, time); + SetStatusEffectEndTime(effect, time); return true; } } diff --git a/Content.Shared/StatusEffectNew/StatusEffectsSystem.cs b/Content.Shared/StatusEffectNew/StatusEffectsSystem.cs index 1ffb74570a..b385a12fb8 100644 --- a/Content.Shared/StatusEffectNew/StatusEffectsSystem.cs +++ b/Content.Shared/StatusEffectNew/StatusEffectsSystem.cs @@ -125,47 +125,6 @@ public sealed partial class StatusEffectsSystem : EntitySystem PredictedQueueDel(ent.Owner); } - private void SetStatusEffectTime(EntityUid effect, TimeSpan? duration) - { - if (!_effectQuery.TryComp(effect, out var effectComp)) - return; - - if (duration is null) - { - if(effectComp.EndEffectTime is null) - return; - - effectComp.EndEffectTime = null; - } - else - effectComp.EndEffectTime = _timing.CurTime + duration; - - Dirty(effect, effectComp); - } - - private void UpdateStatusEffectTime(EntityUid effect, TimeSpan? duration) - { - if (!_effectQuery.TryComp(effect, out var effectComp)) - return; - - // It's already infinitely long - if (effectComp.EndEffectTime is null) - return; - - if (duration is null) - effectComp.EndEffectTime = null; - else - { - var newEndTime = _timing.CurTime + duration; - if (effectComp.EndEffectTime >= newEndTime) - return; - - effectComp.EndEffectTime = newEndTime; - } - - Dirty(effect, effectComp); - } - public bool CanAddStatusEffect(EntityUid uid, EntProtoId effectProto) { if (!_proto.TryIndex(effectProto, out var effectProtoData)) @@ -227,13 +186,39 @@ public sealed partial class StatusEffectsSystem : EntitySystem return true; } - private void AddStatusEffectTime(EntityUid effect, TimeSpan delta) + private void UpdateStatusEffectTime(Entity effect, TimeSpan? duration) { - if (!_effectQuery.TryComp(effect, out var effectComp)) + if (!_effectQuery.Resolve(effect, ref effect.Comp)) return; - // If we don't have an end time set, we want to just make the status effect end in delta time from now. - SetStatusEffectEndTime((effect, effectComp), (effectComp.EndEffectTime ?? _timing.CurTime) + delta); + // It's already infinitely long + if (effect.Comp.EndEffectTime is null) + return; + + TimeSpan? newEndTime = null; + + if (duration is not null) + { + // Don't update time to a smaller timespan... + newEndTime = _timing.CurTime + duration; + if (effect.Comp.EndEffectTime >= newEndTime) + return; + } + + SetStatusEffectEndTime(effect, newEndTime); + } + + private void AddStatusEffectTime(Entity effect, TimeSpan delta) + { + if (!_effectQuery.Resolve(effect, ref effect.Comp)) + return; + + // It's already infinitely long can't add or subtract from infinity... + if (effect.Comp.EndEffectTime is null) + return; + + // Add to the current end effect time, if we're here we should have one set already, and if it's null it's probably infinite. + SetStatusEffectEndTime((effect, effect.Comp), effect.Comp.EndEffectTime.Value + delta); } private void SetStatusEffectEndTime(Entity ent, TimeSpan? endTime)