Status effects fix. Refresh the status effect cooldown. (#5708)

This commit is contained in:
pointer-to-null
2021-12-07 09:18:07 +03:00
committed by GitHub
parent 4688c74d43
commit 090e74792c
26 changed files with 111 additions and 62 deletions

View File

@@ -53,12 +53,13 @@ namespace Content.Shared.Jittering
/// </remarks>
/// <param name="uid">Entity in question.</param>
/// <param name="time">For how much time to apply the effect.</param>
/// <param name="refresh">The status effect cooldown should be refreshed (true) or accumulated (false).</param>
/// <param name="amplitude">Jitteriness of the animation. See <see cref="MaxAmplitude"/> and <see cref="MinAmplitude"/>.</param>
/// <param name="frequency">Frequency for jittering. See <see cref="MaxFrequency"/> and <see cref="MinFrequency"/>.</param>
/// <param name="forceValueChange">Whether to change any existing jitter value even if they're greater than the ones we're setting.</param>
/// <param name="status">The status effects component to modify.</param>
/// <param name="alerts">The alerts component.</param>
public void DoJitter(EntityUid uid, TimeSpan time, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false,
public void DoJitter(EntityUid uid, TimeSpan time, bool refresh, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
@@ -68,7 +69,7 @@ namespace Content.Shared.Jittering
amplitude = Math.Clamp(amplitude, MinAmplitude, MaxAmplitude);
frequency = Math.Clamp(frequency, MinFrequency, MaxFrequency);
if (StatusEffects.TryAddStatusEffect<JitteringComponent>(uid, "Jitter", time, status, alerts))
if (StatusEffects.TryAddStatusEffect<JitteringComponent>(uid, "Jitter", time, refresh, status, alerts))
{
var jittering = EntityManager.GetComponent<JitteringComponent>(uid);

View File

@@ -68,7 +68,7 @@ namespace Content.Shared.Nutrition.EntitySystems
CreamedEntity(uid, creamPied, args);
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime));
_stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime), true);
}
protected virtual void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) {}

View File

@@ -64,7 +64,7 @@ namespace Content.Shared.Slippery
if (!component.Slippery
|| component.Owner.IsInContainer()
|| component.Slipped.Contains(uid)
|| !_statusEffectsSystem.CanApplyEffect(uid, "Stun"))
|| !_statusEffectsSystem.CanApplyEffect(uid, "Stun")) //Should be KnockedDown instead?
{
return false;
}
@@ -95,11 +95,17 @@ namespace Content.Shared.Slippery
otherBody.LinearVelocity *= component.LaunchForwardsMultiplier;
_stunSystem.TryParalyze(otherBody.OwnerUid, TimeSpan.FromSeconds(5));
bool playSound = !_statusEffectsSystem.HasStatusEffect(otherBody.OwnerUid, "KnockedDown");
_stunSystem.TryParalyze(otherBody.OwnerUid, TimeSpan.FromSeconds(component.ParalyzeTime), true);
component.Slipped.Add(otherBody.OwnerUid);
component.Dirty();
PlaySound(component);
//Preventing from playing the slip sound when you are already knocked down.
if(playSound)
{
PlaySound(component);
}
_adminLog.Add(LogType.Slip, LogImpact.Low, $"{component.Owner} slipped on collision with {otherBody.Owner}");

View File

@@ -18,7 +18,7 @@ namespace Content.Shared.Slippery
{
public override string Name => "Slippery";
private float _paralyzeTime = 3f;
private float _paralyzeTime = 5f;
private float _intersectPercentage = 0.3f;
private float _requiredSlipSpeed = 5f;
private float _launchForwardsMultiplier = 1f;

View File

@@ -8,7 +8,7 @@ namespace Content.Shared.Speech.EntitySystems
public abstract class SharedStutteringSystem : EntitySystem
{
// For code in shared... I imagine we ain't getting accent prediction anytime soon so let's not bother.
public virtual void DoStutter(EntityUid uid, TimeSpan time, StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null)
public virtual void DoStutter(EntityUid uid, TimeSpan time, bool refresh, StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null)
{
}
}

View File

@@ -38,6 +38,13 @@ namespace Content.Shared.StatusEffect
[ViewVariables]
public (TimeSpan, TimeSpan) Cooldown;
/// <summary>
/// Specifies whether to refresh or accumulate the cooldown of the status effect.
/// true - refresh time, false - accumulate time.
/// </summary>
[ViewVariables]
public bool CooldownRefresh = true;
/// <summary>
/// The name of the relevant component that
/// was added alongside the effect, if any.
@@ -45,9 +52,10 @@ namespace Content.Shared.StatusEffect
[ViewVariables]
public string? RelevantComponent;
public StatusEffectState((TimeSpan, TimeSpan) cooldown, string? relevantComponent=null)
public StatusEffectState((TimeSpan, TimeSpan) cooldown, bool refresh, string? relevantComponent=null)
{
Cooldown = cooldown;
CooldownRefresh = refresh;
RelevantComponent = relevantComponent;
}
}

View File

@@ -64,7 +64,8 @@ namespace Content.Shared.StatusEffect
}
var time = effect.Value.Cooldown.Item2 - effect.Value.Cooldown.Item1;
TryAddStatusEffect(uid, effect.Key, time);
//TODO: Not sure how to handle refresh here.
TryAddStatusEffect(uid, effect.Key, time, true);
}
}
}
@@ -75,11 +76,12 @@ namespace Content.Shared.StatusEffect
/// <param name="uid">The entity to add the effect to.</param>
/// <param name="key">The status effect ID to add.</param>
/// <param name="time">How long the effect should last for.</param>
/// <param name="refresh">The status effect cooldown should be refreshed (true) or accumulated (false).</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if the effect could not be added or the component already exists, true otherwise.</returns>
/// <typeparam name="T">The component type to add and remove from the entity.</typeparam>
public bool TryAddStatusEffect<T>(EntityUid uid, string key, TimeSpan time,
public bool TryAddStatusEffect<T>(EntityUid uid, string key, TimeSpan time, bool refresh,
StatusEffectsComponent? status=null,
SharedAlertsComponent? alerts=null)
where T: Component, new()
@@ -89,7 +91,7 @@ namespace Content.Shared.StatusEffect
Resolve(uid, ref alerts, false);
if (TryAddStatusEffect(uid, key, time, status, alerts))
if (TryAddStatusEffect(uid, key, time, refresh, status, alerts))
{
// If they already have the comp, we just won't bother updating anything.
if (!EntityManager.HasComponent<T>(uid))
@@ -103,7 +105,7 @@ namespace Content.Shared.StatusEffect
return false;
}
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, string component,
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, bool refresh, string component,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
@@ -112,7 +114,7 @@ namespace Content.Shared.StatusEffect
Resolve(uid, ref alerts, false);
if (TryAddStatusEffect(uid, key, time, status, alerts))
if (TryAddStatusEffect(uid, key, time, refresh, status, alerts))
{
// If they already have the comp, we just won't bother updating anything.
if (!EntityManager.HasComponent(uid, _componentFactory.GetRegistration(component).Type))
@@ -136,6 +138,7 @@ namespace Content.Shared.StatusEffect
/// <param name="uid">The entity to add the effect to.</param>
/// <param name="key">The status effect ID to add.</param>
/// <param name="time">How long the effect should last for.</param>
/// <param name="refresh">The status effect cooldown should be refreshed (true) or accumulated (false).</param>
/// <param name="status">The status effects component to change, if you already have it.</param>
/// <param name="alerts">The alerts component to modify, if the status effect has an alert.</param>
/// <returns>False if the effect could not be added, or if the effect already existed.</returns>
@@ -146,7 +149,7 @@ namespace Content.Shared.StatusEffect
/// If the effect already exists, it will simply replace the cooldown with the new one given.
/// If you want special 'effect merging' behavior, do it your own damn self!
/// </remarks>
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time,
public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, bool refresh,
StatusEffectsComponent? status=null,
SharedAlertsComponent? alerts=null)
{
@@ -163,14 +166,27 @@ namespace Content.Shared.StatusEffect
(TimeSpan, TimeSpan) cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time);
// If they already have this status effect, add the time onto it's cooldown rather than anything else.
if (HasStatusEffect(uid, key, status))
{
status.ActiveEffects[key].Cooldown.Item2 += time;
status.ActiveEffects[key].CooldownRefresh = refresh;
if(refresh)
{
//Making sure we don't reset a longer cooldown by applying a shorter one.
if((status.ActiveEffects[key].Cooldown.Item2 - _gameTiming.CurTime) < time)
{
//Refresh cooldown time.
status.ActiveEffects[key].Cooldown = cooldown;
}
}
else
{
//Accumulate cooldown time.
status.ActiveEffects[key].Cooldown.Item2 += time;
}
}
else
{
status.ActiveEffects.Add(key, new StatusEffectState(cooldown, null));
status.ActiveEffects.Add(key, new StatusEffectState(cooldown, refresh, null));
}
if (proto.Alert != null && alerts != null)

View File

@@ -118,7 +118,7 @@ namespace Content.Shared.Stunnable
/// <summary>
/// Stuns the entity, disallowing it from doing many interactions temporarily.
/// </summary>
public bool TryStun(EntityUid uid, TimeSpan time,
public bool TryStun(EntityUid uid, TimeSpan time, bool refresh,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
@@ -130,13 +130,13 @@ namespace Content.Shared.Stunnable
Resolve(uid, ref alerts, false);
return _statusEffectSystem.TryAddStatusEffect<StunnedComponent>(uid, "Stun", time, alerts: alerts);
return _statusEffectSystem.TryAddStatusEffect<StunnedComponent>(uid, "Stun", time, refresh, alerts: alerts);
}
/// <summary>
/// Knocks down the entity, making it fall to the ground.
/// </summary>
public bool TryKnockdown(EntityUid uid, TimeSpan time,
public bool TryKnockdown(EntityUid uid, TimeSpan time, bool refresh,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
@@ -148,13 +148,13 @@ namespace Content.Shared.Stunnable
Resolve(uid, ref alerts, false);
return _statusEffectSystem.TryAddStatusEffect<KnockedDownComponent>(uid, "KnockedDown", time, alerts: alerts);
return _statusEffectSystem.TryAddStatusEffect<KnockedDownComponent>(uid, "KnockedDown", time, refresh, alerts: alerts);
}
/// <summary>
/// Applies knockdown and stun to the entity temporarily.
/// </summary>
public bool TryParalyze(EntityUid uid, TimeSpan time,
public bool TryParalyze(EntityUid uid, TimeSpan time, bool refresh,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
{
@@ -164,13 +164,13 @@ namespace Content.Shared.Stunnable
// Optional component.
Resolve(uid, ref alerts, false);
return TryKnockdown(uid, time, status, alerts) && TryStun(uid, time, status, alerts);
return TryKnockdown(uid, time, refresh, status, alerts) && TryStun(uid, time, refresh, status, alerts);
}
/// <summary>
/// Slows down the mob's walking/running speed temporarily
/// </summary>
public bool TrySlowdown(EntityUid uid, TimeSpan time,
public bool TrySlowdown(EntityUid uid, TimeSpan time, bool refresh,
float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f,
StatusEffectsComponent? status = null,
SharedAlertsComponent? alerts = null)
@@ -184,7 +184,7 @@ namespace Content.Shared.Stunnable
if (time <= TimeSpan.Zero)
return false;
if (_statusEffectSystem.TryAddStatusEffect<SlowedDownComponent>(uid, "SlowedDown", time, status, alerts))
if (_statusEffectSystem.TryAddStatusEffect<SlowedDownComponent>(uid, "SlowedDown", time, refresh, status, alerts))
{
var slowed = EntityManager.GetComponent<SlowedDownComponent>(uid);
// Doesn't make much sense to have the "TrySlowdown" method speed up entities now does it?