Add a sleep delay to Nocturine (NewStatusEffect version) (#40231)
* Initial commit * Minor fix * Why is this uncommented here? Hmmm * No wait this can't be here, oops * Do better time * Also guidebook * Review changes * Add rejuvination, fix mispredicts
This commit is contained in:
@@ -13,13 +13,15 @@ public sealed partial class StatusEffectsSystem
|
||||
/// <param name="target">The target entity to which the effect should be added.</param>
|
||||
/// <param name="effectProto">ProtoId of the status effect entity. Make sure it has StatusEffectComponent on it.</param>
|
||||
/// <param name="duration">Duration of status effect. Leave null and the effect will be permanent until it is removed using <c>TryRemoveStatusEffect</c>.</param>
|
||||
/// <param name="delay">The delay of the effect. If a start time already exists, the closest time takes precedence. Leave null for the effect to be instant.</param>
|
||||
/// <param name="statusEffect">The EntityUid of the status effect we have just created or null if it doesn't exist.</param>
|
||||
/// <returns>True if effect exists and its duration is set properly, false in case effect cannot be applied.</returns>
|
||||
public bool TryAddStatusEffectDuration(
|
||||
EntityUid target,
|
||||
EntProtoId effectProto,
|
||||
[NotNullWhen(true)] out EntityUid? statusEffect,
|
||||
TimeSpan duration
|
||||
TimeSpan duration,
|
||||
TimeSpan? delay = null
|
||||
)
|
||||
{
|
||||
if (duration == TimeSpan.Zero)
|
||||
@@ -30,18 +32,19 @@ public sealed partial class StatusEffectsSystem
|
||||
|
||||
// We check to make sure time is greater than zero here because sometimes you want to use TryAddStatusEffect to remove duration instead...
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration, delay);
|
||||
|
||||
AddStatusEffectTime(statusEffect.Value, duration);
|
||||
UpdateStatusEffectDelay(statusEffect.Value, delay);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///<inheritdoc cref="TryAddStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan)"/>
|
||||
public bool TryAddStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan duration)
|
||||
///<inheritdoc cref="TryAddStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan,TimeSpan?)"/>
|
||||
public bool TryAddStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan duration, TimeSpan? delay = null)
|
||||
{
|
||||
return TryAddStatusEffectDuration(target, effectProto, out _, duration);
|
||||
return TryAddStatusEffectDuration(target, effectProto, out _, duration, delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,13 +54,15 @@ public sealed partial class StatusEffectsSystem
|
||||
/// <param name="target">The target entity to which the effect should be added.</param>
|
||||
/// <param name="effectProto">ProtoId of the status effect entity. Make sure it has StatusEffectComponent on it.</param>
|
||||
/// <param name="duration">Duration of status effect. Leave null and the effect will be permanent until it is removed using <c>TryRemoveStatusEffect</c>.</param>
|
||||
/// <param name="delay">The delay of the effect. If a start time already exists, the closest time takes precedence. Leave null for the effect to be instant.</param>
|
||||
/// <param name="statusEffect">The EntityUid of the status effect we have just created or null if it doesn't exist.</param>
|
||||
/// <returns>True if effect exists and its duration is set properly, false in case effect cannot be applied.</returns>
|
||||
public bool TrySetStatusEffectDuration(
|
||||
EntityUid target,
|
||||
EntProtoId effectProto,
|
||||
[NotNullWhen(true)] out EntityUid? statusEffect,
|
||||
TimeSpan? duration = null
|
||||
TimeSpan? duration = null,
|
||||
TimeSpan? delay = null
|
||||
)
|
||||
{
|
||||
if (duration <= TimeSpan.Zero)
|
||||
@@ -67,17 +72,22 @@ public sealed partial class StatusEffectsSystem
|
||||
}
|
||||
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration, delay);
|
||||
|
||||
SetStatusEffectEndTime(statusEffect.Value, duration);
|
||||
if (!_effectQuery.TryComp(statusEffect, out var statusEffectComponent))
|
||||
return false;
|
||||
|
||||
var endTime = delay == null || statusEffectComponent.Applied ? _timing.CurTime + duration : _timing.CurTime + delay + duration;
|
||||
SetStatusEffectEndTime(statusEffect.Value, endTime);
|
||||
UpdateStatusEffectDelay(statusEffect.Value, delay);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TrySetStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan?)"/>
|
||||
public bool TrySetStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan? duration = null)
|
||||
/// <inheritdoc cref="TrySetStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan?,TimeSpan?)"/>
|
||||
public bool TrySetStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan? duration = null, TimeSpan? delay = null)
|
||||
{
|
||||
return TrySetStatusEffectDuration(target, effectProto, out _, duration);
|
||||
return TrySetStatusEffectDuration(target, effectProto, out _, duration, delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,13 +97,15 @@ public sealed partial class StatusEffectsSystem
|
||||
/// <param name="target">The target entity to which the effect should be added.</param>
|
||||
/// <param name="effectProto">ProtoId of the status effect entity. Make sure it has StatusEffectComponent on it.</param>
|
||||
/// <param name="duration">Duration of status effect. Leave null and the effect will be permanent until it is removed using <c>TryRemoveStatusEffect</c>.</param>
|
||||
/// <param name="delay">The delay of the effect. If a start time already exists, the closest time takes precedence. Leave null for the effect to be instant.</param>
|
||||
/// <param name="statusEffect">The EntityUid of the status effect we have just created or null if it doesn't exist.</param>
|
||||
/// <returns>True if effect exists and its duration is set properly, false in case effect cannot be applied.</returns>
|
||||
public bool TryUpdateStatusEffectDuration(
|
||||
EntityUid target,
|
||||
EntProtoId effectProto,
|
||||
[NotNullWhen(true)] out EntityUid? statusEffect,
|
||||
TimeSpan? duration = null
|
||||
TimeSpan? duration = null,
|
||||
TimeSpan? delay = null
|
||||
)
|
||||
{
|
||||
if (duration <= TimeSpan.Zero)
|
||||
@@ -103,17 +115,22 @@ public sealed partial class StatusEffectsSystem
|
||||
}
|
||||
|
||||
if (!TryGetStatusEffect(target, effectProto, out statusEffect))
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration);
|
||||
return TryAddStatusEffect(target, effectProto, out statusEffect, duration, delay);
|
||||
|
||||
UpdateStatusEffectTime(statusEffect.Value, duration);
|
||||
if (!_effectQuery.TryComp(statusEffect, out var statusEffectComponent))
|
||||
return false;
|
||||
|
||||
var endTime = delay == null || statusEffectComponent.Applied ? duration : delay + duration;
|
||||
UpdateStatusEffectTime(statusEffect.Value, endTime);
|
||||
UpdateStatusEffectDelay(statusEffect.Value, delay);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="TryUpdateStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan?)"/>
|
||||
public bool TryUpdateStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan? duration = null)
|
||||
/// <inheritdoc cref="TryUpdateStatusEffectDuration(EntityUid,EntProtoId,out EntityUid?,TimeSpan?,TimeSpan?)"/>
|
||||
public bool TryUpdateStatusEffectDuration(EntityUid target, EntProtoId effectProto, TimeSpan? duration = null, TimeSpan? delay = null)
|
||||
{
|
||||
return TryUpdateStatusEffectDuration(target, effectProto, out _, duration);
|
||||
return TryUpdateStatusEffectDuration(target, effectProto, out _, duration, delay);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,7 +210,7 @@ public sealed partial class StatusEffectsSystem
|
||||
public bool TryGetTime(
|
||||
EntityUid uid,
|
||||
EntProtoId effectProto,
|
||||
out (EntityUid EffectEnt, TimeSpan? EndEffectTime) time,
|
||||
out (EntityUid EffectEnt, TimeSpan? EndEffectTime, TimeSpan? StartEffectTime) time,
|
||||
StatusEffectContainerComponent? container = null
|
||||
)
|
||||
{
|
||||
@@ -209,7 +226,7 @@ public sealed partial class StatusEffectsSystem
|
||||
if (!_effectQuery.TryComp(effect, out var effectComp))
|
||||
return false;
|
||||
|
||||
time = (effect, effectComp.EndEffectTime);
|
||||
time = (effect, effectComp.EndEffectTime, effectComp.StartEffectTime);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user