Refactor SeeingRainbows to new status effect system (#38620)

This commit is contained in:
Red
2025-06-27 21:19:04 +03:00
committed by GitHub
parent ad2616a53f
commit bb116e3219
14 changed files with 110 additions and 100 deletions

View File

@@ -269,7 +269,7 @@ public abstract partial class SharedStatusEffectsSystem
foreach (var effect in container.ActiveStatusEffects)
{
if (!TryComp<StatusEffectComponent>(effect, out var statusComp))
if (!_effectQuery.TryComp(effect, out var statusComp))
continue;
if (TryComp<T>(effect, out var comp))
@@ -279,6 +279,39 @@ public abstract partial class SharedStatusEffectsSystem
}
}
return effects != null;
return effects is not null;
}
/// <summary>
/// Helper function for calculating how long it takes for all effects with a particular component to disappear. Useful for overlays.
/// </summary>
/// <param name="target">An entity from which status effects are checked.</param>
/// <param name="endTime">The farthest end time of effects with this component is returned. Can be null if one of the effects is infinite.</param>
/// <returns>True if effects with the specified component were found, or False if there are no such effects.</returns>
public bool TryGetEffectsEndTimeWithComp<T>(EntityUid? target, out TimeSpan? endTime) where T : IComponent
{
endTime = _timing.CurTime;
if (!_containerQuery.TryComp(target, out var container))
return false;
foreach (var effect in container.ActiveStatusEffects)
{
if (!HasComp<T>(effect))
continue;
if (!_effectQuery.TryComp(effect, out var statusComp))
continue;
if (statusComp.EndEffectTime is null)
{
endTime = null;
return true; //This effect never ends, so we return null at endTime, but return true that there is time.
}
if (statusComp.EndEffectTime > endTime)
endTime = statusComp.EndEffectTime;
}
return endTime is not null;
}
}