New Status Effects API Overload (#38617)

* I love API changes

* Update Content.Shared/StatusEffectNew/StatusEffectSystem.API.cs

* fix

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
This commit is contained in:
Princess Cheeseballs
2025-06-27 05:00:20 -07:00
committed by GitHub
parent 1d2907fb4e
commit cf4a883f11

View File

@@ -18,23 +18,27 @@ public abstract partial class SharedStatusEffectsSystem
/// If True, the effect duration time will be reset and reapplied. If False, the effect duration time will be overlaid with the existing one. /// If True, the effect duration time will be reset and reapplied. If False, the effect duration time will be overlaid with the existing one.
/// In the other case, the effect will either be added for the specified time or its time will be extended for the specified time. /// In the other case, the effect will either be added for the specified time or its time will be extended for the specified time.
/// </param> /// </param>
/// <param name="statusEffect">The EntityUid of the status effect we have just created or null if it doesn't exist.</param>
public bool TryAddStatusEffect( public bool TryAddStatusEffect(
EntityUid target, EntityUid target,
EntProtoId effectProto, EntProtoId effectProto,
out EntityUid? statusEffect,
TimeSpan? duration = null, TimeSpan? duration = null,
bool resetCooldown = false bool resetCooldown = false
) )
{ {
if (TryGetStatusEffect(target, effectProto, out var existedEffect)) statusEffect = null;
if (TryGetStatusEffect(target, effectProto, out var existingEffect))
{ {
statusEffect = existingEffect;
//We don't need to add the effect if it already exists //We don't need to add the effect if it already exists
if (duration is null) if (duration is null)
return true; return true;
if (resetCooldown) if (resetCooldown)
SetStatusEffectTime(existedEffect.Value, duration.Value); SetStatusEffectTime(existingEffect.Value, duration.Value);
else else
AddStatusEffectTime(existedEffect.Value, duration.Value); AddStatusEffectTime(existingEffect.Value, duration.Value);
return true; return true;
} }
@@ -46,6 +50,7 @@ public abstract partial class SharedStatusEffectsSystem
//And only if all checks passed we spawn the effect //And only if all checks passed we spawn the effect
var effect = PredictedSpawnAttachedTo(effectProto, Transform(target).Coordinates); var effect = PredictedSpawnAttachedTo(effectProto, Transform(target).Coordinates);
statusEffect = effect;
_transform.SetParent(effect, target); _transform.SetParent(effect, target);
if (!_effectQuery.TryComp(effect, out var effectComp)) if (!_effectQuery.TryComp(effect, out var effectComp))
return false; return false;
@@ -64,6 +69,20 @@ public abstract partial class SharedStatusEffectsSystem
return true; return true;
} }
/// <summary>
/// An overload of <see cref="TryAddStatusEffect(EntityUid,EntProtoId,out EntityUid?,TimeSpan?,bool)"/>
/// that doesn't return a status effect EntityUid.
/// </summary>
public bool TryAddStatusEffect(
EntityUid target,
EntProtoId effectProto,
TimeSpan? duration = null,
bool resetCooldown = false
)
{
return TryAddStatusEffect(target, effectProto, out _, duration, resetCooldown);
}
/// <summary> /// <summary>
/// Attempting to remove a status effect from an entity. /// Attempting to remove a status effect from an entity.
/// Returns True if the status effect existed on the entity and was successfully removed, and False in otherwise. /// Returns True if the status effect existed on the entity and was successfully removed, and False in otherwise.