Status Effect Alerts and Time Bugfixes (#39529)

* Bugefix

* Clean up

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2025-08-10 13:55:13 -07:00
committed by GitHub
parent 7825d30562
commit 458e2d222c
2 changed files with 32 additions and 47 deletions

View File

@@ -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;
}
}

View File

@@ -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<StatusEffectComponent?> 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<StatusEffectComponent?> 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<StatusEffectComponent?> ent, TimeSpan? endTime)