Predicted stamina (#12413)

* Predicted stamina

Needed to do some semblence of predicted melee.

* Okay now done.

* Pause support

* Comment
This commit is contained in:
metalgearsloth
2022-11-09 07:34:07 +11:00
committed by GitHub
parent 43b529f647
commit fb3f6fa80f
23 changed files with 148 additions and 95 deletions

View File

@@ -1,6 +1,6 @@
using Content.Server.Damage.Events; using Content.Shared.Damage.Events;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Containers; using Robust.Shared.Containers;
namespace Content.Server.Abilities.Boxer namespace Content.Server.Abilities.Boxer

View File

@@ -3,7 +3,6 @@ using Content.Server.Atmos.Components;
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Server.Temperature.Components; using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems; using Content.Server.Temperature.Systems;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.Atmos; using Content.Shared.Atmos;
@@ -14,6 +13,7 @@ using Content.Shared.Physics;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Rejuvenate; using Content.Shared.Rejuvenate;
using Content.Shared.Temperature; using Content.Shared.Temperature;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;

View File

@@ -1,6 +1,5 @@
using System.Linq; using System.Linq;
using Content.Server.Chemistry.Components; using Content.Server.Chemistry.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;

View File

@@ -2,6 +2,7 @@ using Content.Shared.Damage;
using Content.Shared.MobState.EntitySystems; using Content.Shared.MobState.EntitySystems;
using Content.Shared.MobState.Components; using Content.Shared.MobState.Components;
using Content.Server.Damage.Components; using Content.Server.Damage.Components;
using Content.Shared.Damage.Components;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
namespace Content.Server.Contests namespace Content.Server.Contests

View File

@@ -1,7 +1,6 @@
using Content.Server.Flash.Components; using Content.Server.Flash.Components;
using Content.Server.Light.EntitySystems; using Content.Server.Light.EntitySystems;
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Flash; using Content.Shared.Flash;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
@@ -11,6 +10,7 @@ using Content.Shared.Inventory;
using Content.Shared.Physics; using Content.Shared.Physics;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Tag; using Content.Shared.Tag;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;

View File

@@ -10,6 +10,7 @@ using Content.Server.Storage.EntitySystems;
using Content.Server.Strip; using Content.Server.Strip;
using Content.Server.Stunnable; using Content.Server.Stunnable;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.CombatMode;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems; using Content.Shared.Hands.EntitySystems;

View File

@@ -1,24 +1,16 @@
using System.Linq;
using Content.Server.Damage.Components;
using Content.Server.Damage.Events;
using Content.Server.Power.Components; using Content.Server.Power.Components;
using Content.Server.Power.Events; using Content.Server.Power.Events;
using Content.Server.Speech.EntitySystems;
using Content.Server.Stunnable.Components; using Content.Server.Stunnable.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Damage.Events;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Item; using Content.Shared.Item;
using Content.Shared.Jittering;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.StatusEffect;
using Content.Shared.Throwing;
using Content.Shared.Toggleable; using Content.Shared.Toggleable;
using Robust.Server.GameObjects; using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Stunnable.Systems namespace Content.Server.Stunnable.Systems
{ {

View File

@@ -3,7 +3,6 @@ using Content.Server.Chemistry.Components;
using Content.Server.Chemistry.Components.SolutionManager; using Content.Server.Chemistry.Components.SolutionManager;
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Tools.Components; using Content.Server.Tools.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -11,6 +10,7 @@ using Content.Shared.Item;
using Content.Shared.Temperature; using Content.Shared.Temperature;
using Content.Shared.Toggleable; using Content.Shared.Toggleable;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;

View File

@@ -1,7 +1,6 @@
using Content.Server.CombatMode.Disarm; using Content.Server.CombatMode.Disarm;
using Content.Server.Kitchen.Components; using Content.Server.Kitchen.Components;
using Content.Server.Weapons.Melee.EnergySword.Components; using Content.Server.Weapons.Melee.EnergySword.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Item; using Content.Shared.Item;
@@ -11,6 +10,7 @@ using Content.Shared.Temperature;
using Content.Shared.Toggleable; using Content.Shared.Toggleable;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;

View File

@@ -14,9 +14,9 @@ using Content.Server.Examine;
using Content.Server.Hands.Components; using Content.Server.Hands.Components;
using Content.Server.Movement.Systems; using Content.Server.Movement.Systems;
using Content.Server.Weapons.Melee.Components; using Content.Server.Weapons.Melee.Components;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.CombatMode; using Content.Shared.CombatMode;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;

View File

@@ -9,6 +9,7 @@ using Content.Server.Stunnable;
using Content.Server.Weapons.Melee; using Content.Server.Weapons.Melee;
using Content.Server.Weapons.Ranged.Components; using Content.Server.Weapons.Ranged.Components;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Weapons.Melee; using Content.Shared.Weapons.Melee;

View File

@@ -11,7 +11,7 @@ using Content.Shared.Popups;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Shared.Player; using Robust.Shared.Player;
using Content.Server.Actions.Events; using Content.Server.Actions.Events;
using Content.Server.Weapons.Melee.Events; using Content.Shared.Weapons.Melee.Events;
namespace Content.Server.Wieldable namespace Content.Server.Wieldable

View File

@@ -12,9 +12,9 @@ using Content.Server.Inventory;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Content.Server.Speech; using Content.Server.Speech;
using Content.Server.Chat.Systems; using Content.Server.Chat.Systems;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Movement.Systems; using Content.Shared.Movement.Systems;
using Content.Shared.Damage; using Content.Shared.Damage;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Zombies; using Content.Shared.Zombies;
namespace Content.Server.Zombies namespace Content.Server.Zombies

View File

@@ -1,4 +1,4 @@
namespace Content.Server.CombatMode namespace Content.Shared.CombatMode
{ {
public sealed class DisarmedEvent : HandledEntityEventArgs public sealed class DisarmedEvent : HandledEntityEventArgs
{ {

View File

@@ -1,4 +1,4 @@
namespace Content.Server.Damage.Components; namespace Content.Shared.Damage.Components;
/// <summary> /// <summary>
/// Tracks whether an entity has ANY stamina damage for update purposes only. /// Tracks whether an entity has ANY stamina damage for update purposes only.

View File

@@ -1,12 +1,13 @@
using Content.Server.Damage.Systems;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization.TypeSerializers.Implementations;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Damage.Components; namespace Content.Shared.Damage.Components;
/// <summary> /// <summary>
/// Add to an entity to paralyze it whenever it reaches critical amounts of Stamina DamageType. /// Add to an entity to paralyze it whenever it reaches critical amounts of Stamina DamageType.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent, NetworkedComponent]
public sealed class StaminaComponent : Component public sealed class StaminaComponent : Component
{ {
/// <summary> /// <summary>
@@ -40,8 +41,8 @@ public sealed class StaminaComponent : Component
public float CritThreshold = 100f; public float CritThreshold = 100f;
/// <summary> /// <summary>
/// Next time we're allowed to decrease stamina damage. Refreshes whenever the stam damage is changed. /// To avoid continuously updating our data we track the last time we updated so we can extrapolate our current stamina.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("decayAccumulator")] [ViewVariables, DataField("lastUpdate", customTypeSerializer:typeof(TimeOffsetSerializer))]
public float StaminaDecayAccumulator; public TimeSpan NextUpdate = TimeSpan.Zero;
} }

View File

@@ -1,6 +1,4 @@
using Robust.Shared.GameStates; namespace Content.Shared.Damage.Components;
namespace Content.Server.Damage.Components;
/// <summary> /// <summary>
/// Applies stamina damage when colliding with an entity. /// Applies stamina damage when colliding with an entity.

View File

@@ -1,6 +1,4 @@
using Robust.Shared.Audio; namespace Content.Shared.Damage.Components;
namespace Content.Server.Damage.Components;
[RegisterComponent] [RegisterComponent]
public sealed class StaminaDamageOnHitComponent : Component public sealed class StaminaDamageOnHitComponent : Component

View File

@@ -1,6 +1,6 @@
using Robust.Shared.Audio; using Robust.Shared.Audio;
namespace Content.Server.Damage.Events; namespace Content.Shared.Damage.Events;
/// <summary> /// <summary>
/// Attempting to apply stamina damage on a melee hit to an entity. /// Attempting to apply stamina damage on a melee hit to an entity.
@@ -10,4 +10,10 @@ public struct StaminaDamageOnHitAttemptEvent
{ {
public bool Cancelled; public bool Cancelled;
public SoundSpecifier? HitSoundOverride; public SoundSpecifier? HitSoundOverride;
public StaminaDamageOnHitAttemptEvent(bool cancelled, SoundSpecifier? hitSoundOverride)
{
Cancelled = cancelled;
HitSoundOverride = hitSoundOverride;
}
} }

View File

@@ -1,7 +1,7 @@
using Content.Shared.Damage.Components;
using Robust.Shared.Collections; using Robust.Shared.Collections;
using Content.Server.Damage.Components;
namespace Content.Server.Damage.Events; namespace Content.Shared.Damage.Events;
/// <summary> /// <summary>
/// The components in the list are going to be hit, /// The components in the list are going to be hit,
@@ -11,9 +11,10 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
{ {
/// <summary> /// <summary>
/// List of hit stamina components. /// List of hit stamina components.
public ValueList<StaminaComponent> HitList; /// </summary>
public List<StaminaComponent> HitList;
/// <summmary> /// <summary>
/// The multiplier. Generally, try to use *= or /= instead of overwriting. /// The multiplier. Generally, try to use *= or /= instead of overwriting.
/// </summary> /// </summary>
public float Multiplier = 1; public float Multiplier = 1;
@@ -23,7 +24,7 @@ public sealed class StaminaMeleeHitEvent : HandledEntityEventArgs
/// </summary> /// </summary>
public float FlatModifier = 0; public float FlatModifier = 0;
public StaminaMeleeHitEvent(ValueList<StaminaComponent> hitList) public StaminaMeleeHitEvent(List<StaminaComponent> hitList)
{ {
HitList = hitList; HitList = hitList;
} }

View File

@@ -1,59 +1,96 @@
using Content.Server.Damage.Components; using Content.Shared.Administration.Logs;
using Content.Server.Damage.Events;
using Content.Server.Popups;
using Content.Server.Administration.Logs;
using Content.Server.CombatMode;
using Content.Server.Weapons.Melee.Events;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.Rounding; using Content.Shared.CombatMode;
using Content.Shared.Stunnable; using Content.Shared.Damage.Components;
using Content.Shared.Damage.Events;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
using Content.Shared.Popups; using Content.Shared.Popups;
using Robust.Shared.Collections; using Content.Shared.Rounding;
using Robust.Shared.Physics.Dynamics; using Content.Shared.Stunnable;
using Robust.Shared.Player; using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Timing; using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.GameStates;
using Robust.Shared.Random;
using Robust.Shared.Physics.Events; using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
namespace Content.Shared.Damage.Systems;
namespace Content.Server.Damage.Systems;
public sealed class StaminaSystem : EntitySystem public sealed class StaminaSystem : EntitySystem
{ {
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly MetaDataSystem _metadata = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!; [Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
private const float UpdateCooldown = 2f;
private float _accumulator;
private const string CollideFixture = "projectile"; private const string CollideFixture = "projectile";
/// <summary> /// <summary>
/// How much of a buffer is there between the stun duration and when stuns can be re-applied. /// How much of a buffer is there between the stun duration and when stuns can be re-applied.
/// </summary> /// </summary>
private const float StamCritBufferTime = 3f; private static readonly TimeSpan StamCritBufferTime = TimeSpan.FromSeconds(3f);
private readonly List<EntityUid> _dirtyEntities = new();
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<StaminaComponent, ComponentStartup>(OnStartup); SubscribeLocalEvent<StaminaComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<StaminaComponent, ComponentShutdown>(OnShutdown); SubscribeLocalEvent<StaminaComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<StaminaComponent, ComponentGetState>(OnStamGetState);
SubscribeLocalEvent<StaminaComponent, ComponentHandleState>(OnStamHandleState);
SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed); SubscribeLocalEvent<StaminaComponent, DisarmedEvent>(OnDisarmed);
SubscribeLocalEvent<StaminaDamageOnCollideComponent, StartCollideEvent>(OnCollide); SubscribeLocalEvent<StaminaDamageOnCollideComponent, StartCollideEvent>(OnCollide);
SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnHit); SubscribeLocalEvent<StaminaDamageOnHitComponent, MeleeHitEvent>(OnHit);
} }
private void OnStamGetState(EntityUid uid, StaminaComponent component, ref ComponentGetState args)
{
args.State = new StaminaComponentState()
{
Critical = component.Critical,
Decay = component.Decay,
CritThreshold = component.CritThreshold,
DecayCooldown = component.DecayCooldown,
LastUpdate = component.NextUpdate,
StaminaDamage = component.StaminaDamage,
};
}
private void OnStamHandleState(EntityUid uid, StaminaComponent component, ref ComponentHandleState args)
{
if (args.Current is not StaminaComponentState state)
return;
component.Critical = state.Critical;
component.Decay = state.Decay;
component.CritThreshold = state.CritThreshold;
component.DecayCooldown = state.DecayCooldown;
component.NextUpdate = state.LastUpdate;
component.StaminaDamage = state.StaminaDamage;
if (component.Critical)
EnterStamCrit(uid, component);
else
{
if (component.StaminaDamage > 0f)
EnsureComp<ActiveStaminaComponent>(uid);
ExitStamCrit(uid, component);
}
}
private void OnShutdown(EntityUid uid, StaminaComponent component, ComponentShutdown args) private void OnShutdown(EntityUid uid, StaminaComponent component, ComponentShutdown args)
{ {
if (MetaData(uid).EntityLifeStage < EntityLifeStage.Terminating)
{
RemCompDeferred<ActiveStaminaComponent>(uid);
}
SetStaminaAlert(uid); SetStaminaAlert(uid);
} }
@@ -62,6 +99,17 @@ public sealed class StaminaSystem : EntitySystem
SetStaminaAlert(uid, component); SetStaminaAlert(uid, component);
} }
[PublicAPI]
public float GetStaminaDamage(EntityUid uid, StaminaComponent? component = null)
{
if (!Resolve(uid, ref component))
return 0f;
var curTime = _timing.CurTime;
var pauseTime = _metadata.GetPauseTime(uid);
return MathF.Max(0f, component.StaminaDamage - MathF.Max(0f, (float) (curTime - (component.NextUpdate + pauseTime)).TotalSeconds * component.Decay));
}
private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args) private void OnDisarmed(EntityUid uid, StaminaComponent component, DisarmedEvent args)
{ {
if (args.Handled || !_random.Prob(args.PushProbability)) if (args.Handled || !_random.Prob(args.PushProbability))
@@ -102,7 +150,7 @@ public sealed class StaminaSystem : EntitySystem
args.HitSoundOverride = ev.HitSoundOverride; args.HitSoundOverride = ev.HitSoundOverride;
var stamQuery = GetEntityQuery<StaminaComponent>(); var stamQuery = GetEntityQuery<StaminaComponent>();
var toHit = new ValueList<StaminaComponent>(); var toHit = new List<StaminaComponent>();
// Split stamina damage between all eligible targets. // Split stamina damage between all eligible targets.
foreach (var ent in args.HitEntities) foreach (var ent in args.HitEntities)
@@ -155,7 +203,8 @@ public sealed class StaminaSystem : EntitySystem
public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null) public void TakeStaminaDamage(EntityUid uid, float value, StaminaComponent? component = null)
{ {
if (!Resolve(uid, ref component, false) || component.Critical) return; if (!Resolve(uid, ref component, false) || component.Critical)
return;
var oldDamage = component.StaminaDamage; var oldDamage = component.StaminaDamage;
component.StaminaDamage = MathF.Max(0f, component.StaminaDamage + value); component.StaminaDamage = MathF.Max(0f, component.StaminaDamage + value);
@@ -163,7 +212,10 @@ public sealed class StaminaSystem : EntitySystem
// Reset the decay cooldown upon taking damage. // Reset the decay cooldown upon taking damage.
if (oldDamage < component.StaminaDamage) if (oldDamage < component.StaminaDamage)
{ {
component.StaminaDecayAccumulator = component.DecayCooldown; var nextUpdate = _timing.CurTime + TimeSpan.FromSeconds(component.DecayCooldown);
if (component.NextUpdate < nextUpdate)
component.NextUpdate = nextUpdate;
} }
var slowdownThreshold = component.CritThreshold / 2f; var slowdownThreshold = component.CritThreshold / 2f;
@@ -177,9 +229,6 @@ public sealed class StaminaSystem : EntitySystem
SetStaminaAlert(uid, component); SetStaminaAlert(uid, component);
// Can't do it here as resetting prediction gets cooked.
_dirtyEntities.Add(uid);
if (!component.Critical) if (!component.Critical)
{ {
if (component.StaminaDamage >= component.CritThreshold) if (component.StaminaDamage >= component.CritThreshold)
@@ -194,6 +243,9 @@ public sealed class StaminaSystem : EntitySystem
ExitStamCrit(uid, component); ExitStamCrit(uid, component);
} }
} }
EnsureComp<ActiveStaminaComponent>(uid);
Dirty(component);
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -202,35 +254,25 @@ public sealed class StaminaSystem : EntitySystem
if (!_timing.IsFirstTimePredicted) return; if (!_timing.IsFirstTimePredicted) return;
_accumulator -= frameTime; var metaQuery = GetEntityQuery<MetaDataComponent>();
if (_accumulator > 0f) return;
var stamQuery = GetEntityQuery<StaminaComponent>(); var stamQuery = GetEntityQuery<StaminaComponent>();
var curTime = _timing.CurTime;
foreach (var uid in _dirtyEntities)
{
// Don't need to RemComp as they will get handled below.
if (!stamQuery.TryGetComponent(uid, out var comp) || comp.StaminaDamage <= 0f) continue;
EnsureComp<ActiveStaminaComponent>(uid);
}
_dirtyEntities.Clear();
_accumulator += UpdateCooldown;
foreach (var active in EntityQuery<ActiveStaminaComponent>()) foreach (var active in EntityQuery<ActiveStaminaComponent>())
{ {
// Just in case we have active but not stamina we'll check and account for it. // Just in case we have active but not stamina we'll check and account for it.
if (!stamQuery.TryGetComponent(active.Owner, out var comp) || if (!stamQuery.TryGetComponent(active.Owner, out var comp) ||
comp.StaminaDamage <= 0f) comp.StaminaDamage <= 0f && !comp.Critical)
{ {
RemComp<ActiveStaminaComponent>(active.Owner); RemComp<ActiveStaminaComponent>(active.Owner);
continue; continue;
} }
comp.StaminaDecayAccumulator -= UpdateCooldown; // Shouldn't need to consider paused time as we're only iterating non-paused stamina components.
var nextUpdate = comp.NextUpdate;
if (comp.StaminaDecayAccumulator > 0f) continue; if (nextUpdate > curTime)
continue;
// We were in crit so come out of it and continue. // We were in crit so come out of it and continue.
if (comp.Critical) if (comp.Critical)
@@ -239,8 +281,9 @@ public sealed class StaminaSystem : EntitySystem
continue; continue;
} }
comp.StaminaDecayAccumulator = 0f; comp.NextUpdate += TimeSpan.FromSeconds(1f);
TakeStaminaDamage(comp.Owner, -comp.Decay * UpdateCooldown, comp); TakeStaminaDamage(comp.Owner, -comp.Decay, comp);
Dirty(comp);
} }
} }
@@ -254,13 +297,14 @@ public sealed class StaminaSystem : EntitySystem
component.Critical = true; component.Critical = true;
component.StaminaDamage = component.CritThreshold; component.StaminaDamage = component.CritThreshold;
component.StaminaDecayAccumulator = 0f;
var stunTime = TimeSpan.FromSeconds(6); var stunTime = TimeSpan.FromSeconds(6);
_stunSystem.TryParalyze(uid, stunTime, true); _stunSystem.TryParalyze(uid, stunTime, true);
// Give them buffer before being able to be re-stunned // Give them buffer before being able to be re-stunned
component.StaminaDecayAccumulator = (float) stunTime.TotalSeconds + StamCritBufferTime; component.NextUpdate = _timing.CurTime + stunTime + StamCritBufferTime;
EnsureComp<ActiveStaminaComponent>(uid);
Dirty(component);
} }
private void ExitStamCrit(EntityUid uid, StaminaComponent? component = null) private void ExitStamCrit(EntityUid uid, StaminaComponent? component = null)
@@ -270,6 +314,20 @@ public sealed class StaminaSystem : EntitySystem
component.Critical = false; component.Critical = false;
component.StaminaDamage = 0f; component.StaminaDamage = 0f;
component.NextUpdate = _timing.CurTime;
SetStaminaAlert(uid, component); SetStaminaAlert(uid, component);
RemComp<ActiveStaminaComponent>(uid);
Dirty(component);
}
[Serializable, NetSerializable]
private sealed class StaminaComponentState : ComponentState
{
public bool Critical;
public float Decay;
public float DecayCooldown;
public float StaminaDamage;
public float CritThreshold;
public TimeSpan LastUpdate;
} }
} }

View File

@@ -1,7 +1,7 @@
using Content.Shared.Damage; using Content.Shared.Damage;
using Robust.Shared.Audio; using Robust.Shared.Audio;
namespace Content.Server.Weapons.Melee.Events; namespace Content.Shared.Weapons.Melee.Events;
/// <summary> /// <summary>
/// Raised directed on the melee weapon entity used to attack something in combat mode, /// Raised directed on the melee weapon entity used to attack something in combat mode,

View File

@@ -1,11 +1,8 @@
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Clothing.Components;
using Content.Shared.CombatMode; using Content.Shared.CombatMode;
using Content.Shared.Hands; using Content.Shared.Hands;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory; using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Weapons.Melee.Events; using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;