diff --git a/Content.Client/Jittering/JitteringSystem.cs b/Content.Client/Jittering/JitteringSystem.cs index dc9662a37b..cd5bc3ea75 100644 --- a/Content.Client/Jittering/JitteringSystem.cs +++ b/Content.Client/Jittering/JitteringSystem.cs @@ -48,7 +48,7 @@ namespace Content.Client.Jittering private void OnAnimationCompleted(EntityUid uid, JitteringComponent jittering, AnimationCompletedEvent args) { - if(args.Key != _jitterAnimationKey || jittering.EndTime <= GameTiming.CurTime) + if(args.Key != _jitterAnimationKey) return; if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer) diff --git a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs index 0c044e9e57..b29302e55c 100644 --- a/Content.IntegrationTests/Tests/InventoryHelpersTest.cs +++ b/Content.IntegrationTests/Tests/InventoryHelpersTest.cs @@ -24,7 +24,9 @@ namespace Content.IntegrationTests.Tests id: InventoryStunnableDummy components: - type: Inventory - - type: Stunnable + - type: StatusEffects + allowed: + - Stun - type: entity name: InventoryJumpsuitJanitorDummy @@ -52,7 +54,6 @@ namespace Content.IntegrationTests.Tests IEntity human = null; InventoryComponent inventory = null; - StunnableComponent stun = null; server.Assert(() => { @@ -64,7 +65,6 @@ namespace Content.IntegrationTests.Tests human = entityMan.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace); inventory = human.GetComponent(); - stun = human.GetComponent(); // Can't do the test if this human doesn't have the slots for it. Assert.That(inventory.HasSlot(Slots.INNERCLOTHING)); @@ -76,7 +76,7 @@ namespace Content.IntegrationTests.Tests Assert.That(inventory.TryGetSlotItem(Slots.INNERCLOTHING, out ItemComponent uniform)); Assert.That(uniform.Owner.Prototype != null && uniform.Owner.Prototype.ID == "InventoryJumpsuitJanitorDummy"); - EntitySystem.Get().Stun(human.Uid, TimeSpan.FromSeconds(1f), stun); + EntitySystem.Get().TryStun(human.Uid, TimeSpan.FromSeconds(1f)); // Since the mob is stunned, they can't equip this. Assert.That(inventory.SpawnItemInSlot(Slots.IDCARD, "InventoryIDCardDummy", true), Is.False); diff --git a/Content.Server/Administration/Commands/RejuvenateCommand.cs b/Content.Server/Administration/Commands/RejuvenateCommand.cs index 63eb7fa6d9..76f65ff0d4 100644 --- a/Content.Server/Administration/Commands/RejuvenateCommand.cs +++ b/Content.Server/Administration/Commands/RejuvenateCommand.cs @@ -9,6 +9,7 @@ using Content.Shared.Damage; using Content.Shared.Jittering; using Content.Shared.MobState; using Content.Shared.Nutrition.Components; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Robust.Server.Player; using Robust.Shared.Console; @@ -59,10 +60,7 @@ namespace Content.Server.Administration.Commands target.GetComponentOrNull()?.ResetFood(); target.GetComponentOrNull()?.ResetThirst(); - if (target.TryGetComponent(out StunnableComponent? stunnable)) - { - EntitySystem.Get().Reset(target.Uid, stunnable); - } + EntitySystem.Get().TryRemoveAllStatusEffects(target.Uid); if (target.TryGetComponent(out FlammableComponent? flammable)) { diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index 5cf6530e6f..0b5dc62f51 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -153,10 +153,9 @@ namespace Content.Server.Atmos.EntitySystems public void Resist(EntityUid uid, FlammableComponent? flammable = null, - StunnableComponent? stunnable = null, ServerAlertsComponent? alerts = null) { - if (!Resolve(uid, ref flammable, ref stunnable)) + if (!Resolve(uid, ref flammable, ref alerts)) return; if (!flammable.OnFire || !_actionBlockerSystem.CanInteract(flammable.Owner) || flammable.Resisting) @@ -165,7 +164,7 @@ namespace Content.Server.Atmos.EntitySystems flammable.Resisting = true; flammable.Owner.PopupMessage(Loc.GetString("flammable-component-resist-message")); - _stunSystem.Paralyze(uid, TimeSpan.FromSeconds(2f), stunnable, alerts); + _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f), alerts: alerts); // TODO FLAMMABLE: Make this not use TimerComponent... flammable.Owner.SpawnTimer(2000, () => diff --git a/Content.Server/Buckle/Components/BuckleComponent.cs b/Content.Server/Buckle/Components/BuckleComponent.cs index 53af231968..9f941cedc5 100644 --- a/Content.Server/Buckle/Components/BuckleComponent.cs +++ b/Content.Server/Buckle/Components/BuckleComponent.cs @@ -40,7 +40,6 @@ namespace Content.Server.Buckle.Components [ComponentDependency] public readonly AppearanceComponent? Appearance = null; [ComponentDependency] private readonly ServerAlertsComponent? _serverAlerts = null; - [ComponentDependency] private readonly StunnableComponent? _stunnable = null; [ComponentDependency] private readonly MobStateComponent? _mobState = null; [DataField("size")] @@ -336,7 +335,7 @@ namespace Content.Server.Buckle.Components Appearance?.SetData(BuckleVisuals.Buckled, false); - if (_stunnable is { KnockedDown: true } + if (Owner.HasComponent() || (_mobState?.IsIncapacitated() ?? false)) { EntitySystem.Get().Down(Owner.Uid); diff --git a/Content.Server/Conveyor/ConveyorSystem.cs b/Content.Server/Conveyor/ConveyorSystem.cs index 898c4ef476..03dc9ed6e1 100644 --- a/Content.Server/Conveyor/ConveyorSystem.cs +++ b/Content.Server/Conveyor/ConveyorSystem.cs @@ -62,11 +62,8 @@ namespace Content.Server.Conveyor signal != TwoWayLeverSignal.Middle) { args.Cancel(); - if (args.Attemptee.TryGetComponent(out var stunnableComponent)) - { - _stunSystem.Paralyze(uid, TimeSpan.FromSeconds(2f), stunnableComponent); - component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link")); - } + _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(2f)); + component.Owner.PopupMessage(args.Attemptee, Loc.GetString("conveyor-component-failed-link")); } } diff --git a/Content.Server/Cuffs/Components/HandcuffComponent.cs b/Content.Server/Cuffs/Components/HandcuffComponent.cs index 368997af92..cb22ef244a 100644 --- a/Content.Server/Cuffs/Components/HandcuffComponent.cs +++ b/Content.Server/Cuffs/Components/HandcuffComponent.cs @@ -198,7 +198,7 @@ namespace Content.Server.Cuffs.Components { var cuffTime = CuffTime; - if (target.TryGetComponent(out var stun) && stun.Stunned) + if (target.HasComponent()) { cuffTime = MathF.Max(0.1f, cuffTime - StunBonus); } diff --git a/Content.Server/Damage/Systems/DamageOnHighSpeedImpactSystem.cs b/Content.Server/Damage/Systems/DamageOnHighSpeedImpactSystem.cs index 308dff0423..afa5d947f0 100644 --- a/Content.Server/Damage/Systems/DamageOnHighSpeedImpactSystem.cs +++ b/Content.Server/Damage/Systems/DamageOnHighSpeedImpactSystem.cs @@ -46,8 +46,8 @@ namespace Content.Server.Damage.Systems component.LastHit = _gameTiming.CurTime; - if (EntityManager.TryGetComponent(uid, out StunnableComponent? stun) && _robustRandom.Prob(component.StunChance)) - _stunSystem.Stun(uid, TimeSpan.FromSeconds(component.StunSeconds), stun); + if (_robustRandom.Prob(component.StunChance)) + _stunSystem.TryStun(uid, TimeSpan.FromSeconds(component.StunSeconds)); var damageScale = (speed / component.MinimumSpeed) * component.Factor; _damageableSystem.TryChangeDamage(uid, component.Damage * damageScale); diff --git a/Content.Server/DoAfter/DoAfter.cs b/Content.Server/DoAfter/DoAfter.cs index 0590cb7984..c95f1338c4 100644 --- a/Content.Server/DoAfter/DoAfter.cs +++ b/Content.Server/DoAfter/DoAfter.cs @@ -136,8 +136,7 @@ namespace Content.Server.DoAfter } if (EventArgs.BreakOnStun && - entityManager.TryGetComponent(EventArgs.User, out StunnableComponent? stunnableComponent) && - stunnableComponent.Stunned) + entityManager.HasComponent(EventArgs.User)) { return true; } diff --git a/Content.Server/Doors/Components/ServerDoorComponent.cs b/Content.Server/Doors/Components/ServerDoorComponent.cs index bd827469f6..1ae5d01f3b 100644 --- a/Content.Server/Doors/Components/ServerDoorComponent.cs +++ b/Content.Server/Doors/Components/ServerDoorComponent.cs @@ -565,8 +565,7 @@ namespace Content.Server.Doors.Components if (e.Owner.HasComponent()) EntitySystem.Get().TryChangeDamage(e.Owner.Uid, CrushDamage); - if(e.Owner.TryGetComponent(out StunnableComponent? stun)) - EntitySystem.Get().Paralyze(e.Owner.Uid, TimeSpan.FromSeconds(DoorStunTime), stun); + EntitySystem.Get().TryParalyze(e.Owner.Uid, TimeSpan.FromSeconds(DoorStunTime)); } // If we hit someone, open up after stun (opens right when stun ends) diff --git a/Content.Server/Flash/FlashSystem.cs b/Content.Server/Flash/FlashSystem.cs index 73b65772fa..c6cd3788ca 100644 --- a/Content.Server/Flash/FlashSystem.cs +++ b/Content.Server/Flash/FlashSystem.cs @@ -131,10 +131,8 @@ namespace Content.Server.Flash flashable.Dirty(); } - if (EntityManager.TryGetComponent(target, out var stunnable)) - { - _stunSystem.Slowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), slowTo, slowTo, stunnable); - } + _stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), + slowTo, slowTo); if (displayPopup && user != null && target != user) { diff --git a/Content.Server/Instruments/InstrumentComponent.cs b/Content.Server/Instruments/InstrumentComponent.cs index 9ee4bc16f1..bcbdf76fd0 100644 --- a/Content.Server/Instruments/InstrumentComponent.cs +++ b/Content.Server/Instruments/InstrumentComponent.cs @@ -361,14 +361,8 @@ namespace Content.Server.Instruments if (mob != null) { - if (Handheld) - EntitySystem.Get().Down(mob.Uid, false); - - if (mob.TryGetComponent(out StunnableComponent? stun)) - { - EntitySystem.Get().Stun(mob.Uid, TimeSpan.FromSeconds(1), stun); - Clean(); - } + EntitySystem.Get().TryParalyze(mob.Uid, TimeSpan.FromSeconds(1)); + Clean(); Owner.PopupMessage(mob, "instrument-component-finger-cramps-max-message"); } diff --git a/Content.Server/MobState/States/CriticalMobState.cs b/Content.Server/MobState/States/CriticalMobState.cs index f0347e29a5..660cded153 100644 --- a/Content.Server/MobState/States/CriticalMobState.cs +++ b/Content.Server/MobState/States/CriticalMobState.cs @@ -1,6 +1,7 @@ using Content.Server.Stunnable; using Content.Server.Stunnable.Components; using Content.Shared.MobState.State; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Robust.Shared.GameObjects; @@ -12,9 +13,9 @@ namespace Content.Server.MobState.States { base.EnterState(entity); - if (entity.TryGetComponent(out StunnableComponent? stun)) + if (entity.TryGetComponent(out StatusEffectsComponent? stun)) { - EntitySystem.Get().Reset(entity.Uid, stun); + EntitySystem.Get().TryRemoveStatusEffect(entity.Uid, "Stun"); } } } diff --git a/Content.Server/MobState/States/DeadMobState.cs b/Content.Server/MobState/States/DeadMobState.cs index 8e3d16f150..13030e723b 100644 --- a/Content.Server/MobState/States/DeadMobState.cs +++ b/Content.Server/MobState/States/DeadMobState.cs @@ -4,6 +4,7 @@ using Content.Server.Stunnable.Components; using Content.Shared.Alert; using Content.Shared.MobState; using Content.Shared.MobState.State; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Robust.Server.GameObjects; using Robust.Shared.GameObjects; @@ -21,10 +22,9 @@ namespace Content.Server.MobState.States status.ShowAlert(AlertType.HumanDead); } - if (entity.TryGetComponent(out StunnableComponent? stun)) + if (entity.TryGetComponent(out StatusEffectsComponent? stun)) { - // TODO: Use resolves to pass ServerAlertsComponent here. - EntitySystem.Get().Reset(entity.Uid, stun); + EntitySystem.Get().TryRemoveStatusEffect(entity.Uid, "Stun"); } } } diff --git a/Content.Server/Stunnable/Components/StunOnCollideComponent.cs b/Content.Server/Stunnable/Components/StunOnCollideComponent.cs index b93a4b4116..3af94b0ff6 100644 --- a/Content.Server/Stunnable/Components/StunOnCollideComponent.cs +++ b/Content.Server/Stunnable/Components/StunOnCollideComponent.cs @@ -13,7 +13,7 @@ namespace Content.Server.Stunnable.Components // TODO: Can probably predict this. public override string Name => "StunOnCollide"; - // See stunnable for what these do + // See stunsystem for what these do [DataField("stunAmount")] public int StunAmount; diff --git a/Content.Server/Stunnable/StunOnCollideSystem.cs b/Content.Server/Stunnable/StunOnCollideSystem.cs index a191e82875..4c34f1b32d 100644 --- a/Content.Server/Stunnable/StunOnCollideSystem.cs +++ b/Content.Server/Stunnable/StunOnCollideSystem.cs @@ -4,6 +4,7 @@ using Content.Server.Stunnable.Components; using Content.Shared.Alert; using Content.Shared.Movement.Components; using Content.Shared.Standing; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using JetBrains.Annotations; using Robust.Server.GameObjects; @@ -17,6 +18,7 @@ namespace Content.Server.Stunnable internal sealed class StunOnCollideSystem : EntitySystem { [Dependency] private readonly StunSystem _stunSystem = default!; + [Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!; public override void Initialize() { @@ -28,7 +30,7 @@ namespace Content.Server.Stunnable { var otherUid = args.OtherFixture.Body.Owner.Uid; - if (EntityManager.TryGetComponent(otherUid, out StunnableComponent? stunnableComponent)) + if (EntityManager.TryGetComponent(otherUid, out var status)) { ServerAlertsComponent? alerts = null; StandingStateComponent? standingState = null; @@ -38,13 +40,13 @@ namespace Content.Server.Stunnable // Let the actual methods log errors for these. Resolve(otherUid, ref alerts, ref standingState, ref appearance, ref speedModifier, false); - _stunSystem.Stun(otherUid, TimeSpan.FromSeconds(component.StunAmount), stunnableComponent, alerts); + _stunSystem.TryStun(otherUid, TimeSpan.FromSeconds(component.StunAmount), status, alerts); - _stunSystem.Knockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount), stunnableComponent, - alerts, standingState, appearance); + _stunSystem.TryKnockdown(otherUid, TimeSpan.FromSeconds(component.KnockdownAmount), + status, alerts); - _stunSystem.Slowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount), - component.WalkSpeedMultiplier, component.RunSpeedMultiplier, stunnableComponent, speedModifier, alerts); + _stunSystem.TrySlowdown(otherUid, TimeSpan.FromSeconds(component.SlowdownAmount), + component.WalkSpeedMultiplier, component.RunSpeedMultiplier, status, speedModifier, alerts); } } } diff --git a/Content.Server/Stunnable/StunSystem.cs b/Content.Server/Stunnable/StunSystem.cs index c947063c6a..62a9231c27 100644 --- a/Content.Server/Stunnable/StunSystem.cs +++ b/Content.Server/Stunnable/StunSystem.cs @@ -3,6 +3,7 @@ using Content.Server.Act; using Content.Server.Popups; using Content.Shared.Audio; using Content.Shared.Popups; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Robust.Shared.Audio; using Robust.Shared.GameObjects; @@ -21,28 +22,30 @@ namespace Content.Server.Stunnable { base.Initialize(); - SubscribeLocalEvent(OnDisarmed); + SubscribeLocalEvent(OnDisarmed); } - private void OnDisarmed(EntityUid uid, StunnableComponent stunnable, DisarmedActEvent args) + private void OnDisarmed(EntityUid uid, StatusEffectsComponent status, DisarmedActEvent args) { if (args.Handled || !_random.Prob(args.PushProbability)) return; - Paralyze(uid, TimeSpan.FromSeconds(4f), stunnable); + if (!TryParalyze(uid, TimeSpan.FromSeconds(4f), status)) + return; var source = args.Source; var target = args.Target; if (source != null) { - SoundSystem.Play(Filter.Pvs(source), stunnable.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); + var knock = EntityManager.GetComponent(uid); + SoundSystem.Play(Filter.Pvs(source), knock.StunAttemptSound.GetSound(), source, AudioHelpers.WithVariation(0.025f)); if (target != null) { // TODO: Use PopupSystem - source.PopupMessageOtherClients(Loc.GetString("stunnable-component-disarm-success-others", ("source", source.Name), ("target", target.Name))); - source.PopupMessageCursor(Loc.GetString("stunnable-component-disarm-success", ("target", target.Name))); + source.PopupMessageOtherClients(Loc.GetString("stunned-component-disarm-success-others", ("source", source.Name), ("target", target.Name))); + source.PopupMessageCursor(Loc.GetString("stunned-component-disarm-success", ("target", target.Name))); } } diff --git a/Content.Server/Stunnable/StunbatonSystem.cs b/Content.Server/Stunnable/StunbatonSystem.cs index 4e09e2052e..d6c23433c3 100644 --- a/Content.Server/Stunnable/StunbatonSystem.cs +++ b/Content.Server/Stunnable/StunbatonSystem.cs @@ -9,7 +9,9 @@ using Content.Shared.ActionBlocker; using Content.Shared.Audio; using Content.Shared.Examine; using Content.Shared.Interaction; +using Content.Shared.Jittering; using Content.Shared.Popups; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using Content.Shared.Throwing; using Robust.Server.GameObjects; @@ -25,6 +27,7 @@ namespace Content.Server.Stunnable public class StunbatonSystem : EntitySystem { [Dependency] private readonly StunSystem _stunSystem = default!; + [Dependency] private readonly SharedJitteringSystem _jitterSystem = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; public override void Initialize() @@ -62,11 +65,8 @@ namespace Content.Server.Stunnable if (!EntityManager.TryGetComponent(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse)) return; - if (args.Entity.HasComponent()) - { - args.CanInteract = true; - StunEntity(args.Entity, comp); - } + args.CanInteract = true; + StunEntity(args.Entity, comp); } private void OnUseInHand(EntityUid uid, StunbatonComponent comp, UseInHandEvent args) @@ -119,26 +119,27 @@ namespace Content.Server.Stunnable private void StunEntity(IEntity entity, StunbatonComponent comp) { - if (!entity.TryGetComponent(out StunnableComponent? stunnable) || !comp.Activated) return; + if (!entity.TryGetComponent(out StatusEffectsComponent? status) || !comp.Activated) return; // TODO: Make slowdown inflicted customizable. SoundSystem.Play(Filter.Pvs(comp.Owner), comp.StunSound.GetSound(), comp.Owner, AudioHelpers.WithVariation(0.25f)); - if (!stunnable.SlowedDown) + if (!EntityManager.HasComponent(entity.Uid)) { if (_robustRandom.Prob(comp.ParalyzeChanceNoSlowdown)) - _stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable); + _stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status); else - _stunSystem.Slowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, stunnable); + _stunSystem.TrySlowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, status); } else { if (_robustRandom.Prob(comp.ParalyzeChanceWithSlowdown)) - _stunSystem.Paralyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), stunnable); + _stunSystem.TryParalyze(entity.Uid, TimeSpan.FromSeconds(comp.ParalyzeTime), status); else - _stunSystem.Slowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, stunnable); + _stunSystem.TrySlowdown(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime), 0.5f, 0.5f, status); } + _jitterSystem.DoJitter(entity.Uid, TimeSpan.FromSeconds(comp.SlowdownTime)); if (!comp.Owner.TryGetComponent(out var slot) || slot.Cell == null || !(slot.Cell.CurrentCharge < comp.EnergyPerUse)) return; diff --git a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs index a76168eda2..5034616636 100644 --- a/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs +++ b/Content.Server/Weapon/Ranged/ServerRangedWeaponComponent.cs @@ -173,12 +173,7 @@ namespace Content.Server.Weapon.Ranged { //Wound them EntitySystem.Get().TryChangeDamage(user.Uid, ClumsyDamage); - - // Knock them down - if (user.TryGetComponent(out StunnableComponent? stun)) - { - EntitySystem.Get().Paralyze(user.Uid, TimeSpan.FromSeconds(3f), stun); - } + EntitySystem.Get().TryParalyze(user.Uid, TimeSpan.FromSeconds(3f)); // Apply salt to the wound ("Honk!") SoundSystem.Play( diff --git a/Content.Shared/Alert/SharedAlertsComponent.cs b/Content.Shared/Alert/SharedAlertsComponent.cs index b4eec8caed..2436ac0232 100644 --- a/Content.Shared/Alert/SharedAlertsComponent.cs +++ b/Content.Shared/Alert/SharedAlertsComponent.cs @@ -83,7 +83,7 @@ namespace Content.Shared.Alert /// severity, if supported by the alert /// cooldown start and end, if null there will be no cooldown (and it will /// be erased if there is currently a cooldown for the alert) - public void ShowAlert(AlertType alertType, short? severity = null, ValueTuple? cooldown = null) + public void ShowAlert(AlertType alertType, short? severity = null, (TimeSpan, TimeSpan)? cooldown = null) { if (AlertManager.TryGet(alertType, out var alert)) { @@ -196,7 +196,7 @@ namespace Content.Shared.Alert public struct AlertState { public short? Severity; - public ValueTuple? Cooldown; + public (TimeSpan, TimeSpan)? Cooldown; public AlertType Type; } } diff --git a/Content.Shared/Jittering/JitteringComponent.cs b/Content.Shared/Jittering/JitteringComponent.cs index ebc87b818b..8c5e0aa250 100644 --- a/Content.Shared/Jittering/JitteringComponent.cs +++ b/Content.Shared/Jittering/JitteringComponent.cs @@ -14,9 +14,6 @@ namespace Content.Shared.Jittering { public override string Name => "Jittering"; - [ViewVariables(VVAccess.ReadWrite)] - public TimeSpan EndTime { get; set; } - [ViewVariables(VVAccess.ReadWrite)] public float Amplitude { get; set; } @@ -30,13 +27,11 @@ namespace Content.Shared.Jittering [Serializable, NetSerializable] public class JitteringComponentState : ComponentState { - public TimeSpan EndTime { get; } public float Amplitude { get; } public float Frequency { get; } - public JitteringComponentState(TimeSpan endTime, float amplitude, float frequency) + public JitteringComponentState(float amplitude, float frequency) { - EndTime = endTime; Amplitude = amplitude; Frequency = frequency; } diff --git a/Content.Shared/Jittering/SharedJitteringSystem.cs b/Content.Shared/Jittering/SharedJitteringSystem.cs index 8e5295c610..64b5a23c1a 100644 --- a/Content.Shared/Jittering/SharedJitteringSystem.cs +++ b/Content.Shared/Jittering/SharedJitteringSystem.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using Content.Shared.Alert; +using Content.Shared.StatusEffect; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.IoC; @@ -13,6 +15,7 @@ namespace Content.Shared.Jittering public abstract class SharedJitteringSystem : EntitySystem { [Dependency] protected readonly IGameTiming GameTiming = default!; + [Dependency] protected readonly StatusEffectsSystem StatusEffects = default!; public float MaxAmplitude = 300f; public float MinAmplitude = 1f; @@ -20,11 +23,6 @@ namespace Content.Shared.Jittering public float MaxFrequency = 10f; public float MinFrequency = 1f; - /// - /// List of jitter components to be removed, cached so we don't allocate it every tick. - /// - private readonly List _removeList = new(); - public override void Initialize() { SubscribeLocalEvent(OnGetState); @@ -33,7 +31,7 @@ namespace Content.Shared.Jittering private void OnGetState(EntityUid uid, JitteringComponent component, ref ComponentGetState args) { - args.State = new JitteringComponentState(component.EndTime, component.Amplitude, component.Frequency); + args.State = new JitteringComponentState(component.Amplitude, component.Frequency); } private void OnHandleState(EntityUid uid, JitteringComponent component, ref ComponentHandleState args) @@ -41,7 +39,6 @@ namespace Content.Shared.Jittering if (args.Current is not JitteringComponentState jitteringState) return; - component.EndTime = jitteringState.EndTime; component.Amplitude = jitteringState.Amplitude; component.Frequency = jitteringState.Frequency; } @@ -59,56 +56,26 @@ namespace Content.Shared.Jittering /// Jitteriness of the animation. See and . /// Frequency for jittering. See and . /// Whether to change any existing jitter value even if they're greater than the ones we're setting. - public void DoJitter(EntityUid uid, TimeSpan time, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false) + /// The status effects component to modify. + public void DoJitter(EntityUid uid, TimeSpan time, float amplitude = 10f, float frequency = 4f, bool forceValueChange = false, + StatusEffectsComponent? status=null) { - var jittering = EntityManager.EnsureComponent(uid); - - var endTime = GameTiming.CurTime + time; + if (!Resolve(uid, ref status, false)) + return; amplitude = Math.Clamp(amplitude, MinAmplitude, MaxAmplitude); frequency = Math.Clamp(frequency, MinFrequency, MaxFrequency); - if (forceValueChange || jittering.EndTime < endTime) - jittering.EndTime = endTime; - - if(forceValueChange || jittering.Amplitude < amplitude) - jittering.Amplitude = amplitude; - - if (forceValueChange || jittering.Frequency < frequency) - jittering.Frequency = frequency; - - jittering.Dirty(); - } - - /// - /// Immediately stops any jitter animation from an entity. - /// - /// The entity in question. - public void StopJitter(EntityUid uid) - { - if (!EntityManager.HasComponent(uid)) - return; - - EntityManager.RemoveComponent(uid); - } - - public override void Update(float frameTime) - { - foreach (var jittering in EntityManager.EntityQuery()) + if (StatusEffects.TryAddStatusEffect(uid, "Jitter", time, status)) { - if(jittering.EndTime <= GameTiming.CurTime) - _removeList.Add(jittering); + var jittering = EntityManager.GetComponent(uid); + + if(forceValueChange || jittering.Amplitude < amplitude) + jittering.Amplitude = amplitude; + + if (forceValueChange || jittering.Frequency < frequency) + jittering.Frequency = frequency; } - - if (_removeList.Count == 0) - return; - - foreach (var jittering in _removeList) - { - jittering.Owner.RemoveComponent(); - } - - _removeList.Clear(); } } } diff --git a/Content.Shared/Nutrition/EntitySystems/SharedCreamPieSystem.cs b/Content.Shared/Nutrition/EntitySystems/SharedCreamPieSystem.cs index 4afb9fb5a0..23f309f3cb 100644 --- a/Content.Shared/Nutrition/EntitySystems/SharedCreamPieSystem.cs +++ b/Content.Shared/Nutrition/EntitySystems/SharedCreamPieSystem.cs @@ -68,10 +68,7 @@ namespace Content.Shared.Nutrition.EntitySystems CreamedEntity(uid, creamPied, args); - if (EntityManager.TryGetComponent(uid, out StunnableComponent? stun)) - { - _stunSystem.Paralyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime), stun); - } + _stunSystem.TryParalyze(uid, TimeSpan.FromSeconds(creamPie.ParalyzeTime)); } protected virtual void CreamedEntity(EntityUid uid, CreamPiedComponent creamPied, ThrowHitByEvent args) {} diff --git a/Content.Shared/Slippery/SharedSlipperySystem.cs b/Content.Shared/Slippery/SharedSlipperySystem.cs index ed31cf60e5..10a94012c5 100644 --- a/Content.Shared/Slippery/SharedSlipperySystem.cs +++ b/Content.Shared/Slippery/SharedSlipperySystem.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.EffectBlocker; +using Content.Shared.StatusEffect; using Content.Shared.Stunnable; using JetBrains.Annotations; using Robust.Shared.Containers; @@ -17,6 +18,7 @@ namespace Content.Shared.Slippery public abstract class SharedSlipperySystem : EntitySystem { [Dependency] private readonly SharedStunSystem _stunSystem = default!; + [Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!; private List _slipped = new(); @@ -30,7 +32,7 @@ namespace Content.Shared.Slippery { var otherUid = args.OtherFixture.Body.Owner.Uid; - if (!CanSlip(component, otherUid, out _)) return; + if (!CanSlip(component, otherUid)) return; if (!_slipped.Contains(component)) _slipped.Add(component); @@ -49,14 +51,13 @@ namespace Content.Shared.Slippery } } - public bool CanSlip(SlipperyComponent component, EntityUid uid, [NotNullWhen(true)] out StunnableComponent? stunnableComponent) + public bool CanSlip(SlipperyComponent component, EntityUid uid) { if (!component.Slippery || component.Owner.IsInContainer() || component.Slipped.Contains(uid) - || !EntityManager.TryGetComponent(uid, out stunnableComponent)) + || !_statusEffectsSystem.CanApplyEffect(uid, "Stun")) { - stunnableComponent = null; return false; } @@ -65,9 +66,9 @@ namespace Content.Shared.Slippery private bool TrySlip(SlipperyComponent component, IPhysBody ourBody, IPhysBody otherBody) { - if (!CanSlip(component, otherBody.Owner.Uid, out var stun)) return false; + if (!CanSlip(component, otherBody.Owner.Uid)) return false; - if (otherBody.LinearVelocity.Length < component.RequiredSlipSpeed || stun.KnockedDown) + if (otherBody.LinearVelocity.Length < component.RequiredSlipSpeed) { return false; } @@ -86,7 +87,7 @@ namespace Content.Shared.Slippery otherBody.LinearVelocity *= component.LaunchForwardsMultiplier; - _stunSystem.Paralyze(stun.Owner.Uid, TimeSpan.FromSeconds(5), stun); + _stunSystem.TryParalyze(component.Owner.Uid, TimeSpan.FromSeconds(5)); component.Slipped.Add(otherBody.Owner.Uid); component.Dirty(); diff --git a/Content.Shared/StatusEffect/StatusEffectPrototype.cs b/Content.Shared/StatusEffect/StatusEffectPrototype.cs new file mode 100644 index 0000000000..075a2b4fff --- /dev/null +++ b/Content.Shared/StatusEffect/StatusEffectPrototype.cs @@ -0,0 +1,23 @@ +using Content.Shared.Alert; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Shared.StatusEffect +{ + [Prototype("statusEffect")] + public class StatusEffectPrototype : IPrototype + { + [DataField("id", required: true)] + public string ID { get; } = default!; + + [DataField("alert")] + public AlertType? Alert { get; } + + /// + /// Whether a status effect should be able to apply to any entity, + /// regardless of whether it is in ALlowedEffects or not. + /// + [DataField("alwaysAllowed")] + public bool AlwaysAllowed { get; } + } +} diff --git a/Content.Shared/StatusEffect/StatusEffectsComponent.cs b/Content.Shared/StatusEffect/StatusEffectsComponent.cs new file mode 100644 index 0000000000..21833a5e58 --- /dev/null +++ b/Content.Shared/StatusEffect/StatusEffectsComponent.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using Robust.Shared.Analyzers; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; + +namespace Content.Shared.StatusEffect +{ + [RegisterComponent] + [NetworkedComponent] + [Friend(typeof(StatusEffectsSystem))] + public class StatusEffectsComponent : Component + { + public override string Name => "StatusEffects"; + + public Dictionary ActiveEffects = new(); + + /// + /// A list of status effect IDs to be allowed + /// + [DataField("allowed", required: true)] + public List AllowedEffects = default!; + } + + /// + /// Holds information about an active status effect. + /// + [Serializable, NetSerializable] + public class StatusEffectState + { + /// + /// The start and end times of the status effect. + /// + public (TimeSpan, TimeSpan) Cooldown; + + /// + /// The name of the relevant component that + /// was added alongside the effect, if any. + /// + public string? RelevantComponent; + + public StatusEffectState((TimeSpan, TimeSpan) cooldown, string? relevantComponent=null) + { + Cooldown = cooldown; + RelevantComponent = relevantComponent; + } + } + + [Serializable, NetSerializable] + public class StatusEffectsComponentState : ComponentState + { + public Dictionary ActiveEffects; + public List AllowedEffects; + + public StatusEffectsComponentState(Dictionary activeEffects, List allowedEffects) + { + ActiveEffects = activeEffects; + AllowedEffects = allowedEffects; + } + } +} diff --git a/Content.Shared/StatusEffect/StatusEffectsSystem.cs b/Content.Shared/StatusEffect/StatusEffectsSystem.cs new file mode 100644 index 0000000000..418451f9d7 --- /dev/null +++ b/Content.Shared/StatusEffect/StatusEffectsSystem.cs @@ -0,0 +1,387 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using System.Resources; +using Content.Shared.Alert; +using Robust.Shared.Exceptions; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.IoC; +using Robust.Shared.Prototypes; +using Robust.Shared.Timing; +using Robust.Shared.Utility; + +namespace Content.Shared.StatusEffect +{ + public sealed class StatusEffectsSystem : EntitySystem + { + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + [Dependency] private readonly IComponentFactory _componentFactory = default!; + [Dependency] private readonly IGameTiming _gameTiming = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnHandleState); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var curTime = _gameTiming.CurTime; + foreach (var status in EntityManager.EntityQuery(false)) + { + if (status.ActiveEffects.Count == 0) continue; + foreach (var state in status.ActiveEffects.ToArray()) + { + // if we're past the end point of the effect + if (_gameTiming.CurTime > state.Value.Cooldown.Item2) + { + TryRemoveStatusEffect(status.Owner.Uid, state.Key, status); + } + } + } + } + + private void OnGetState(EntityUid uid, StatusEffectsComponent component, ref ComponentGetState args) + { + args.State = new StatusEffectsComponentState(component.ActiveEffects, component.AllowedEffects); + } + + private void OnHandleState(EntityUid uid, StatusEffectsComponent component, ref ComponentHandleState args) + { + if (args.Current is StatusEffectsComponentState state) + { + component.AllowedEffects = state.AllowedEffects; + + foreach (var effect in state.ActiveEffects) + { + // don't bother with anything if we already have it + if (component.ActiveEffects.ContainsKey(effect.Key)) + { + component.ActiveEffects[effect.Key] = effect.Value; + continue; + } + + var time = effect.Value.Cooldown.Item2 - effect.Value.Cooldown.Item1; + TryAddStatusEffect(uid, effect.Key, time); + } + } + } + + /// + /// Tries to add a status effect to an entity, with a given component added as well. + /// + /// The entity to add the effect to. + /// The status effect ID to add. + /// How long the effect should last for. + /// The status effects component to change, if you already have it. + /// The alerts component to modify, if the status effect has an alert. + /// False if the effect could not be added or the component already exists, true otherwise. + /// The component type to add and remove from the entity. + public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, + StatusEffectsComponent? status=null, + SharedAlertsComponent? alerts=null) + where T: Component, new() + { + if (!Resolve(uid, ref status, false)) + return false; + + Resolve(uid, ref alerts, false); + + if (TryAddStatusEffect(uid, key, time, status, alerts)) + { + // If they already have the comp, we just won't bother updating anything. + if (!EntityManager.HasComponent(uid)) + { + var comp = EntityManager.AddComponent(uid); + status.ActiveEffects[key].RelevantComponent = comp.Name; + } + return true; + } + + return false; + } + + /// + /// Tries to add a status effect to an entity with a certain timer. + /// + /// The entity to add the effect to. + /// The status effect ID to add. + /// How long the effect should last for. + /// The status effects component to change, if you already have it. + /// The alerts component to modify, if the status effect has an alert. + /// False if the effect could not be added, or if the effect already existed. + /// + /// This obviously does not add any actual 'effects' on its own. Use the generic overload, + /// which takes in a component type, if you want to automatically add and remove a component. + /// + /// 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! + /// + public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, + StatusEffectsComponent? status=null, + SharedAlertsComponent? alerts=null) + { + if (!Resolve(uid, ref status, false)) + return false; + if (!CanApplyEffect(uid, key, status)) + return false; + + Resolve(uid, ref alerts, false); + + // we already checked if it has the index in CanApplyEffect so a straight index and not tryindex here + // is fine + var proto = _prototypeManager.Index(key); + + (TimeSpan, TimeSpan) cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time); + + // If they already have this status effect, just bulldoze its cooldown in favor of the new one + // and keep the relevant component the same. + if (HasStatusEffect(uid, key, status)) + { + status.ActiveEffects[key] = new StatusEffectState(cooldown, status.ActiveEffects[key].RelevantComponent); + } + else + { + status.ActiveEffects.Add(key, new StatusEffectState(cooldown, null)); + } + + if (proto.Alert != null && alerts != null) + { + alerts.ShowAlert(proto.Alert.Value, cooldown: GetAlertCooldown(uid, proto.Alert.Value, status)); + } + + status.Dirty(); + // event? + return true; + } + + /// + /// Finds the maximum cooldown among all status effects with the same alert + /// + /// + /// This is mostly for stuns, since Stun and Knockdown share an alert key. Other times this pretty much + /// will not be useful. + /// + private (TimeSpan, TimeSpan)? GetAlertCooldown(EntityUid uid, AlertType alert, StatusEffectsComponent status) + { + (TimeSpan, TimeSpan)? maxCooldown = null; + foreach (var kvp in status.ActiveEffects) + { + var proto = _prototypeManager.Index(kvp.Key); + + if (proto.Alert == alert) + { + if (maxCooldown == null || kvp.Value.Cooldown.Item2 > maxCooldown.Value.Item2) + { + maxCooldown = kvp.Value.Cooldown; + } + } + } + + return maxCooldown; + } + + /// + /// Attempts to remove a status effect from an entity. + /// + /// The entity to remove an effect from. + /// The effect ID to remove. + /// The status effects component to change, if you already have it. + /// The alerts component to modify, if the status effect has an alert. + /// False if the effect could not be removed, true otherwise. + /// + /// Obviously this doesn't automatically clear any effects a status effect might have. + /// That's up to the removed component to handle itself when it's removed. + /// + public bool TryRemoveStatusEffect(EntityUid uid, string key, + StatusEffectsComponent? status=null, + SharedAlertsComponent? alerts=null) + { + if (!Resolve(uid, ref status, false)) + return false; + if (!status.ActiveEffects.ContainsKey(key)) + return false; + if (!_prototypeManager.TryIndex(key, out var proto)) + return false; + + Resolve(uid, ref alerts, false); + + var state = status.ActiveEffects[key]; + if (state.RelevantComponent != null) + { + var type = _componentFactory.GetRegistration(state.RelevantComponent).Type; + EntityManager.RemoveComponent(uid, type); + } + + if (proto.Alert != null && alerts != null) + { + alerts.ClearAlert(proto.Alert.Value); + } + + status.ActiveEffects.Remove(key); + + status.Dirty(); + // event? + return true; + } + + /// + /// Tries to remove all status effects from a given entity. + /// + /// The entity to remove effects from. + /// The status effects component to change, if you already have it. + /// The alerts component to modify, if the status effect has an alert. + /// False if any status effects failed to be removed, true if they all did. + public bool TryRemoveAllStatusEffects(EntityUid uid, + StatusEffectsComponent? status = null, + SharedAlertsComponent? alerts = null) + { + if (!Resolve(uid, ref status, false)) + return false; + + Resolve(uid, ref alerts, false); + + bool failed = false; + foreach (var effect in status.ActiveEffects) + { + if(!TryRemoveStatusEffect(uid, effect.Key, status, alerts)) + failed = true; + } + + return failed; + } + + /// + /// Returns whether a given entity has the status effect active. + /// + /// The entity to check on. + /// The status effect ID to check for + /// The status effect component, should you already have it. + public bool HasStatusEffect(EntityUid uid, string key, + StatusEffectsComponent? status=null) + { + if (!Resolve(uid, ref status, false)) + return false; + if (!status.ActiveEffects.ContainsKey(key)) + return false; + + return true; + } + + /// + /// Returns whether a given entity can have a given effect applied to it. + /// + /// The entity to check on. + /// The status effect ID to check for + /// The status effect component, should you already have it. + public bool CanApplyEffect(EntityUid uid, string key, + StatusEffectsComponent? status = null) + { + // don't log since stuff calling this prolly doesn't care if we don't actually have it + if (!Resolve(uid, ref status, false)) + return false; + if (!_prototypeManager.TryIndex(key, out var proto)) + return false; + if (!status.AllowedEffects.Contains(key) && !proto.AlwaysAllowed) + return false; + + return true; + } + + /// + /// Tries to add to the timer of an already existing status effect. + /// + /// The entity to add time to. + /// The status effect to add time to. + /// The amount of time to add. + /// The status effect component, should you already have it. + public bool TryAddTime(EntityUid uid, string key, TimeSpan time, + StatusEffectsComponent? status = null) + { + if (!Resolve(uid, ref status, false)) + return false; + + if (!HasStatusEffect(uid, key, status)) + return false; + + var timer = status.ActiveEffects[key].Cooldown; + timer.Item2 += time; + + return true; + } + + /// + /// Tries to remove time from the timer of an already existing status effect. + /// + /// The entity to remove time from. + /// The status effect to remove time from. + /// The amount of time to add. + /// The status effect component, should you already have it. + public bool TryRemoveTime(EntityUid uid, string key, TimeSpan time, + StatusEffectsComponent? status = null) + { + if (!Resolve(uid, ref status, false)) + return false; + + if (!HasStatusEffect(uid, key, status)) + return false; + + var timer = status.ActiveEffects[key].Cooldown; + + // what on earth are you doing, Gordon? + if (time > timer.Item2) + return false; + + timer.Item2 -= time; + + return true; + } + + /// + /// Use if you want to set a cooldown directly. + /// + /// + /// Not used internally; just sets it itself. + /// + public bool TrySetTime(EntityUid uid, string key, TimeSpan time, + StatusEffectsComponent? status = null) + { + if (!Resolve(uid, ref status, false)) + return false; + + if (!HasStatusEffect(uid, key, status)) + return false; + + status.ActiveEffects[key].Cooldown = (_gameTiming.CurTime, _gameTiming.CurTime + time); + return true; + } + + /// + /// Gets the cooldown for a given status effect on an entity. + /// + /// The entity to check for status effects on. + /// The status effect to get time for. + /// Out var for the time, if it exists. + /// The status effects component to use, if any. + /// False if the status effect was not active, true otherwise. + public bool TryGetTime(EntityUid uid, string key, + [NotNullWhen(true)] out (TimeSpan, TimeSpan)? time, + StatusEffectsComponent? status = null) + { + if (!Resolve(uid, ref status, false) || !HasStatusEffect(uid, key, status)) + { + time = null; + return false; + } + + time = status.ActiveEffects[key].Cooldown; + return true; + } + } +} diff --git a/Content.Shared/Stunnable/KnockedDownComponent.cs b/Content.Shared/Stunnable/KnockedDownComponent.cs new file mode 100644 index 0000000000..d0d6c66322 --- /dev/null +++ b/Content.Shared/Stunnable/KnockedDownComponent.cs @@ -0,0 +1,41 @@ +using System; +using Content.Shared.Sound; +using Robust.Shared.Analyzers; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Content.Shared.Stunnable +{ + [RegisterComponent] + [NetworkedComponent] + [Friend(typeof(SharedStunSystem))] + public class KnockedDownComponent : Component + { + public override string Name => "KnockedDown"; + + [DataField("helpInterval")] + public float HelpInterval { get; set; } = 1f; + + [DataField("helpAttemptSound")] + public SoundSpecifier StunAttemptSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg"); + + [ViewVariables] + public float HelpTimer { get; set; } = 0f; + } + + [Serializable, NetSerializable] + public class KnockedDownComponentState : ComponentState + { + public float HelpInterval { get; set; } + public float HelpTimer { get; set; } + + public KnockedDownComponentState(float helpInterval, float helpTimer) + { + HelpInterval = helpInterval; + HelpTimer = helpTimer; + } + } +} diff --git a/Content.Shared/Stunnable/SharedStunSystem.cs b/Content.Shared/Stunnable/SharedStunSystem.cs index afa0a761da..3f04ead521 100644 --- a/Content.Shared/Stunnable/SharedStunSystem.cs +++ b/Content.Shared/Stunnable/SharedStunSystem.cs @@ -10,6 +10,7 @@ using Content.Shared.Movement; using Content.Shared.Movement.Components; using Content.Shared.Speech; using Content.Shared.Standing; +using Content.Shared.StatusEffect; using Content.Shared.Throwing; using JetBrains.Annotations; using Robust.Shared.Audio; @@ -25,59 +26,94 @@ namespace Content.Shared.Stunnable public abstract class SharedStunSystem : EntitySystem { [Dependency] private readonly StandingStateSystem _standingStateSystem = default!; + [Dependency] private readonly StatusEffectsSystem _statusEffectSystem = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; public override void Initialize() { - SubscribeLocalEvent(OnGetState); - SubscribeLocalEvent(OnHandleState); - SubscribeLocalEvent(OnInteractHand); + SubscribeLocalEvent(OnKnockInit); + SubscribeLocalEvent(OnKnockRemove); + + SubscribeLocalEvent(OnSlowInit); + SubscribeLocalEvent(OnSlowRemove); + + SubscribeLocalEvent(OnSlowGetState); + SubscribeLocalEvent(OnSlowHandleState); + + SubscribeLocalEvent(OnKnockGetState); + SubscribeLocalEvent(OnKnockHandleState); + + // helping people up if they're knocked down + SubscribeLocalEvent(OnInteractHand); // Attempt event subscriptions. - SubscribeLocalEvent(OnMoveAttempt); - SubscribeLocalEvent(OnInteractAttempt); - SubscribeLocalEvent(OnUseAttempt); - SubscribeLocalEvent(OnThrowAttempt); - SubscribeLocalEvent(OnDropAttempt); - SubscribeLocalEvent(OnPickupAttempt); - SubscribeLocalEvent(OnAttackAttempt); - SubscribeLocalEvent(OnEquipAttempt); - SubscribeLocalEvent(OnUnequipAttempt); - SubscribeLocalEvent(OnStandAttempt); + SubscribeLocalEvent(OnMoveAttempt); + SubscribeLocalEvent(OnInteractAttempt); + SubscribeLocalEvent(OnUseAttempt); + SubscribeLocalEvent(OnThrowAttempt); + SubscribeLocalEvent(OnDropAttempt); + SubscribeLocalEvent(OnPickupAttempt); + SubscribeLocalEvent(OnAttackAttempt); + SubscribeLocalEvent(OnEquipAttempt); + SubscribeLocalEvent(OnUnequipAttempt); } - private void OnGetState(EntityUid uid, StunnableComponent stunnable, ref ComponentGetState args) + private void OnSlowGetState(EntityUid uid, SlowedDownComponent component, ref ComponentGetState args) { - args.State = new StunnableComponentState(stunnable.StunnedTimer, stunnable.KnockdownTimer, stunnable.SlowdownTimer, stunnable.WalkSpeedMultiplier, stunnable.RunSpeedMultiplier); + args.State = new SlowedDownComponentState(component.SprintSpeedModifier, component.WalkSpeedModifier); } - private void OnHandleState(EntityUid uid, StunnableComponent stunnable, ref ComponentHandleState args) + private void OnSlowHandleState(EntityUid uid, SlowedDownComponent component, ref ComponentHandleState args) { - if (args.Current is not StunnableComponentState state) - return; - - stunnable.StunnedTimer = state.StunnedTimer; - stunnable.KnockdownTimer = state.KnockdownTimer; - stunnable.SlowdownTimer = state.SlowdownTimer; - - stunnable.WalkSpeedMultiplier = state.WalkSpeedMultiplier; - stunnable.RunSpeedMultiplier = state.RunSpeedMultiplier; - - if (EntityManager.TryGetComponent(uid, out MovementSpeedModifierComponent? movement)) - movement.RefreshMovementSpeedModifiers(); - } - - private TimeSpan AdjustTime(TimeSpan time, (TimeSpan Start, TimeSpan End)? timer, float cap) - { - if (timer != null) + if (args.Current is SlowedDownComponentState state) { - time = timer.Value.End - timer.Value.Start + time; + component.SprintSpeedModifier = state.SprintSpeedModifier; + component.WalkSpeedModifier = state.WalkSpeedModifier; } + } - if (time.TotalSeconds > cap) - time = TimeSpan.FromSeconds(cap); + private void OnKnockGetState(EntityUid uid, KnockedDownComponent component, ref ComponentGetState args) + { + args.State = new KnockedDownComponentState(component.HelpInterval, component.HelpTimer); + } - return time; + private void OnKnockHandleState(EntityUid uid, KnockedDownComponent component, ref ComponentHandleState args) + { + if (args.Current is KnockedDownComponentState state) + { + component.HelpInterval = state.HelpInterval; + component.HelpTimer = state.HelpTimer; + } + } + + private void OnKnockInit(EntityUid uid, KnockedDownComponent component, ComponentInit args) + { + _standingStateSystem.Down(uid); + } + + private void OnKnockRemove(EntityUid uid, KnockedDownComponent component, ComponentRemove args) + { + _standingStateSystem.Stand(uid); + } + + private void OnSlowInit(EntityUid uid, SlowedDownComponent component, ComponentInit args) + { + // needs to be done so the client can also refresh when the addition is replicated, + // if the initial status effect addition wasn't predicted + if (EntityManager.TryGetComponent(uid, out var move)) + { + move.RefreshMovementSpeedModifiers(); + } + } + + private void OnSlowRemove(EntityUid uid, SlowedDownComponent component, ComponentRemove args) + { + if (EntityManager.TryGetComponent(uid, out var move)) + { + component.SprintSpeedModifier = 1.0f; + component.WalkSpeedModifier = 1.0f; + move.RefreshMovementSpeedModifiers(); + } } // TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...) @@ -85,315 +121,141 @@ namespace Content.Shared.Stunnable /// /// Stuns the entity, disallowing it from doing many interactions temporarily. /// - public void Stun(EntityUid uid, TimeSpan time, - StunnableComponent? stunnable = null, + public bool TryStun(EntityUid uid, TimeSpan time, + StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null) { - if (!Resolve(uid, ref stunnable)) - return; - - time = AdjustTime(time, stunnable.StunnedTimer, stunnable.StunCap); - if (time <= TimeSpan.Zero) - return; + return false; - stunnable.StunnedTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time); + Resolve(uid, ref alerts, false); - SetAlert(uid, stunnable, alerts); - - stunnable.Dirty(); + return _statusEffectSystem.TryAddStatusEffect(uid, "Stun", time, alerts: alerts); } /// /// Knocks down the entity, making it fall to the ground. /// - public void Knockdown(EntityUid uid, TimeSpan time, - StunnableComponent? stunnable = null, - SharedAlertsComponent? alerts = null, - StandingStateComponent? standingState = null, - SharedAppearanceComponent? appearance = null) + public bool TryKnockdown(EntityUid uid, TimeSpan time, + StatusEffectsComponent? status = null, + SharedAlertsComponent? alerts = null) { - if (!Resolve(uid, ref stunnable)) - return; - - time = AdjustTime(time, stunnable.KnockdownTimer, stunnable.KnockdownCap); - if (time <= TimeSpan.Zero) - return; + return false; - // Check if we can actually knock down the mob. - if (!_standingStateSystem.Down(uid, standingState:standingState, appearance:appearance)) - return; + Resolve(uid, ref alerts, false); - stunnable.KnockdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time); - - SetAlert(uid, stunnable, alerts); - - stunnable.Dirty(); + return _statusEffectSystem.TryAddStatusEffect(uid, "KnockedDown", time, alerts: alerts); } + /// /// Applies knockdown and stun to the entity temporarily. /// - public void Paralyze(EntityUid uid, TimeSpan time, - StunnableComponent? stunnable = null, + public bool TryParalyze(EntityUid uid, TimeSpan time, + StatusEffectsComponent? status = null, SharedAlertsComponent? alerts = null) { - if (!Resolve(uid, ref stunnable)) - return; - // Optional component. Resolve(uid, ref alerts, false); - Knockdown(uid, time, stunnable, alerts); - Stun(uid, time, stunnable, alerts); + return TryKnockdown(uid, time, status, alerts) && TryStun(uid, time, status, alerts); } /// /// Slows down the mob's walking/running speed temporarily /// - public void Slowdown(EntityUid uid, TimeSpan time, float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f, - StunnableComponent? stunnable = null, + public bool TrySlowdown(EntityUid uid, TimeSpan time, + float walkSpeedMultiplier = 1f, float runSpeedMultiplier = 1f, + StatusEffectsComponent? status = null, MovementSpeedModifierComponent? speedModifier = null, SharedAlertsComponent? alerts = null) { - if (!Resolve(uid, ref stunnable)) - return; - // "Optional" component. Resolve(uid, ref speedModifier, false); - time = AdjustTime(time, stunnable.SlowdownTimer, stunnable.SlowdownCap); - if (time <= TimeSpan.Zero) - return; + return false; - // Doesn't make much sense to have the "Slowdown" method speed up entities now does it? - walkSpeedMultiplier = Math.Clamp(walkSpeedMultiplier, 0f, 1f); - runSpeedMultiplier = Math.Clamp(runSpeedMultiplier, 0f, 1f); - - stunnable.WalkSpeedMultiplier *= walkSpeedMultiplier; - stunnable.RunSpeedMultiplier *= runSpeedMultiplier; - - stunnable.SlowdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime + time); - - speedModifier?.RefreshMovementSpeedModifiers(); - - SetAlert(uid, stunnable, alerts); - stunnable.Dirty(); - } - - public void Reset(EntityUid uid, - StunnableComponent? stunnable = null, - MovementSpeedModifierComponent? speedModifier = null, - StandingStateComponent? standingState = null, - SharedAppearanceComponent? appearance = null) - { - if (!Resolve(uid, ref stunnable)) - return; - - // Optional component. - Resolve(uid, ref speedModifier, false); - - stunnable.StunnedTimer = null; - stunnable.SlowdownTimer = null; - stunnable.KnockdownTimer = null; - - speedModifier?.RefreshMovementSpeedModifiers(); - _standingStateSystem.Stand(uid, standingState, appearance); - - stunnable.Dirty(); - } - - private void SetAlert(EntityUid uid, - StunnableComponent? stunnable = null, - SharedAlertsComponent? alerts = null) - { - // This method is really just optional, doesn't matter if the entity doesn't support alerts. - if (!Resolve(uid, ref stunnable, ref alerts, false)) - return; - - if (GetTimers(uid, stunnable) is not {} timers) - return; - - alerts.ShowAlert(AlertType.Stun, cooldown:timers); - } - - private (TimeSpan, TimeSpan)? GetTimers(EntityUid uid, StunnableComponent? stunnable = null) - { - if (!Resolve(uid, ref stunnable)) - return null; - - // Don't do anything if no stuns are applied. - if (!stunnable.AnyStunActive) - return null; - - TimeSpan start = TimeSpan.MaxValue, end = TimeSpan.MinValue; - - if (stunnable.StunnedTimer != null) + if (_statusEffectSystem.TryAddStatusEffect(uid, "SlowedDown", time, status, alerts)) { - if (stunnable.StunnedTimer.Value.Start < start) - start = stunnable.StunnedTimer.Value.Start; + var slowed = EntityManager.GetComponent(uid); + // Doesn't make much sense to have the "TrySlowdown" method speed up entities now does it? + walkSpeedMultiplier = Math.Clamp(walkSpeedMultiplier, 0f, 1f); + runSpeedMultiplier = Math.Clamp(runSpeedMultiplier, 0f, 1f); - if (stunnable.StunnedTimer.Value.End > end) - end = stunnable.StunnedTimer.Value.End; + slowed.WalkSpeedModifier *= walkSpeedMultiplier; + slowed.SprintSpeedModifier *= runSpeedMultiplier; + + speedModifier?.RefreshMovementSpeedModifiers(); + + return true; } - if (stunnable.KnockdownTimer != null) - { - if (stunnable.KnockdownTimer.Value.Start < start) - start = stunnable.KnockdownTimer.Value.Start; - - if (stunnable.KnockdownTimer.Value.End > end) - end = stunnable.KnockdownTimer.Value.End; - } - - if (stunnable.SlowdownTimer != null) - { - if (stunnable.SlowdownTimer.Value.Start < start) - start = stunnable.SlowdownTimer.Value.Start; - - if (stunnable.SlowdownTimer.Value.End > end) - end = stunnable.SlowdownTimer.Value.End; - } - - return (start, end); + return false; } - private void OnInteractHand(EntityUid uid, StunnableComponent stunnable, InteractHandEvent args) + private void OnInteractHand(EntityUid uid, KnockedDownComponent knocked, InteractHandEvent args) { - if (args.Handled || stunnable.HelpTimer > 0f || !stunnable.KnockedDown) + if (args.Handled || knocked.HelpTimer > 0f) return; // Set it to half the help interval so helping is actually useful... - stunnable.HelpTimer = stunnable.HelpInterval/2f; + knocked.HelpTimer = knocked.HelpInterval/2f; - stunnable.KnockdownTimer = (stunnable.KnockdownTimer!.Value.Start, stunnable.KnockdownTimer.Value.End - TimeSpan.FromSeconds(stunnable.HelpInterval)); + _statusEffectSystem.TryRemoveTime(uid, "KnockedDown", TimeSpan.FromSeconds(knocked.HelpInterval)); - SoundSystem.Play(Filter.Pvs(uid), stunnable.StunAttemptSound.GetSound(), uid, AudioHelpers.WithVariation(0.05f)); + SoundSystem.Play(Filter.Pvs(uid), knocked.StunAttemptSound.GetSound(), uid, AudioHelpers.WithVariation(0.05f)); - SetAlert(uid, stunnable); - stunnable.Dirty(); + knocked.Dirty(); args.Handled = true; } - public override void Update(float frameTime) - { - base.Update(frameTime); - - var curTime = _gameTiming.CurTime; - - foreach (var stunnable in EntityManager.EntityQuery()) - { - var uid = stunnable.Owner.Uid; - - if(stunnable.HelpTimer > 0f) - // If it goes negative, that's okay. - stunnable.HelpTimer -= frameTime; - - if (stunnable.StunnedTimer != null) - { - if (stunnable.StunnedTimer.Value.End <= curTime) - { - stunnable.StunnedTimer = null; - stunnable.Dirty(); - } - } - - if (stunnable.KnockdownTimer != null) - { - if (stunnable.KnockdownTimer.Value.End <= curTime) - { - stunnable.KnockdownTimer = null; - - // Try to stand up the mob... - _standingStateSystem.Stand(uid); - - stunnable.Dirty(); - } - } - - if (stunnable.SlowdownTimer != null) - { - if (stunnable.SlowdownTimer.Value.End <= curTime) - { - if (EntityManager.TryGetComponent(uid, out MovementSpeedModifierComponent? movement)) - movement.RefreshMovementSpeedModifiers(); - - - stunnable.SlowdownTimer = null; - stunnable.Dirty(); - } - } - - if (stunnable.AnyStunActive || !EntityManager.TryGetComponent(uid, out SharedAlertsComponent? status) - || !status.IsShowingAlert(AlertType.Stun)) - continue; - - status.ClearAlert(AlertType.Stun); - } - } - #region Attempt Event Handling - private void OnMoveAttempt(EntityUid uid, StunnableComponent stunnable, MovementAttemptEvent args) + private void OnMoveAttempt(EntityUid uid, StunnedComponent stunned, MovementAttemptEvent args) { - if (stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnInteractAttempt(EntityUid uid, StunnableComponent stunnable, InteractionAttemptEvent args) + private void OnInteractAttempt(EntityUid uid, StunnedComponent stunned, InteractionAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnUseAttempt(EntityUid uid, StunnableComponent stunnable, UseAttemptEvent args) + private void OnUseAttempt(EntityUid uid, StunnedComponent stunned, UseAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnThrowAttempt(EntityUid uid, StunnableComponent stunnable, ThrowAttemptEvent args) + private void OnThrowAttempt(EntityUid uid, StunnedComponent stunned, ThrowAttemptEvent args) { - if (stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnDropAttempt(EntityUid uid, StunnableComponent stunnable, DropAttemptEvent args) + private void OnDropAttempt(EntityUid uid, StunnedComponent stunned, DropAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnPickupAttempt(EntityUid uid, StunnableComponent stunnable, PickupAttemptEvent args) + private void OnPickupAttempt(EntityUid uid, StunnedComponent stunned, PickupAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnAttackAttempt(EntityUid uid, StunnableComponent stunnable, AttackAttemptEvent args) + private void OnAttackAttempt(EntityUid uid, StunnedComponent stunned, AttackAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnEquipAttempt(EntityUid uid, StunnableComponent stunnable, EquipAttemptEvent args) + private void OnEquipAttempt(EntityUid uid, StunnedComponent stunned, EquipAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); + args.Cancel(); } - private void OnUnequipAttempt(EntityUid uid, StunnableComponent stunnable, UnequipAttemptEvent args) + private void OnUnequipAttempt(EntityUid uid, StunnedComponent stunned, UnequipAttemptEvent args) { - if(stunnable.Stunned) - args.Cancel(); - } - - private void OnStandAttempt(EntityUid uid, StunnableComponent stunnable, StandAttemptEvent args) - { - if(stunnable.KnockedDown) - args.Cancel(); + args.Cancel(); } #endregion diff --git a/Content.Shared/Stunnable/SlowedDownComponent.cs b/Content.Shared/Stunnable/SlowedDownComponent.cs new file mode 100644 index 0000000000..9aecedf718 --- /dev/null +++ b/Content.Shared/Stunnable/SlowedDownComponent.cs @@ -0,0 +1,33 @@ +using System; +using Content.Shared.Movement.Components; +using Robust.Shared.Analyzers; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; + +namespace Content.Shared.Stunnable +{ + [RegisterComponent] + [NetworkedComponent] + [Friend(typeof(SharedStunSystem))] + public class SlowedDownComponent : Component, IMoveSpeedModifier + { + public override string Name => "SlowedDown"; + + public float SprintSpeedModifier { get; set; } = 0.5f; + public float WalkSpeedModifier { get; set; } = 0.5f; + } + + [Serializable, NetSerializable] + public class SlowedDownComponentState : ComponentState + { + public float SprintSpeedModifier { get; set; } + public float WalkSpeedModifier { get; set; } + + public SlowedDownComponentState(float sprintSpeedModifier, float walkSpeedModifier) + { + SprintSpeedModifier = sprintSpeedModifier; + WalkSpeedModifier = walkSpeedModifier; + } + } +} diff --git a/Content.Shared/Stunnable/StunnableComponent.cs b/Content.Shared/Stunnable/StunnableComponent.cs deleted file mode 100644 index 392d111bba..0000000000 --- a/Content.Shared/Stunnable/StunnableComponent.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using Content.Shared.Movement.Components; -using Content.Shared.Sound; -using Robust.Shared.Analyzers; -using Robust.Shared.GameObjects; -using Robust.Shared.GameStates; -using Robust.Shared.Serialization; -using Robust.Shared.Serialization.Manager.Attributes; -using Robust.Shared.ViewVariables; - -namespace Content.Shared.Stunnable -{ - [Friend(typeof(SharedStunSystem))] - [RegisterComponent, NetworkedComponent] - public sealed class StunnableComponent : Component, IMoveSpeedModifier - { - public sealed override string Name => "Stunnable"; - - public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; set; } - public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; set; } - public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; set; } - - [ViewVariables] - public float StunnedSeconds => - StunnedTimer == null ? 0f : (float)(StunnedTimer.Value.End - StunnedTimer.Value.Start).TotalSeconds; - - [ViewVariables] - public float KnockdownSeconds => - KnockdownTimer == null ? 0f : (float)(KnockdownTimer.Value.End - KnockdownTimer.Value.Start).TotalSeconds; - - [ViewVariables] - public float SlowdownSeconds => - SlowdownTimer == null ? 0f : (float)(SlowdownTimer.Value.End - SlowdownTimer.Value.Start).TotalSeconds; - - [ViewVariables] - public bool AnyStunActive => Stunned || KnockedDown || SlowedDown; - - [ViewVariables] - public bool Stunned => StunnedTimer != null; - - [ViewVariables] - public bool KnockedDown => KnockdownTimer != null; - - [ViewVariables] - public bool SlowedDown => SlowdownTimer != null; - - [DataField("stunCap")] - public float StunCap { get; set; } = 20f; - - [DataField("knockdownCap")] - public float KnockdownCap { get; set; } = 20f; - - [DataField("slowdownCap")] - public float SlowdownCap { get; set; } = 20f; - - [DataField("helpInterval")] - public float HelpInterval { get; set; } = 1f; - - [DataField("stunAttemptSound")] - public SoundSpecifier StunAttemptSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg"); - - [ViewVariables] - public float HelpTimer { get; set; } = 0f; - - [ViewVariables] - public float WalkSpeedMultiplier { get; set; } = 0f; - [ViewVariables] - public float RunSpeedMultiplier { get; set; } = 0f; - - [ViewVariables] - public float WalkSpeedModifier => (SlowedDown ? (WalkSpeedMultiplier <= 0f ? 0.5f : WalkSpeedMultiplier) : 1f); - [ViewVariables] - public float SprintSpeedModifier => (SlowedDown ? (RunSpeedMultiplier <= 0f ? 0.5f : RunSpeedMultiplier) : 1f); - } - - [Serializable, NetSerializable] - public sealed class StunnableComponentState : ComponentState - { - public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; } - public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; } - public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; } - public float WalkSpeedMultiplier { get; } - public float RunSpeedMultiplier { get; } - - public StunnableComponentState( - (TimeSpan Start, TimeSpan End)? stunnedTimer, (TimeSpan Start, TimeSpan End)? knockdownTimer, - (TimeSpan Start, TimeSpan End)? slowdownTimer, float walkSpeedMultiplier, float runSpeedMultiplier) - { - StunnedTimer = stunnedTimer; - KnockdownTimer = knockdownTimer; - SlowdownTimer = slowdownTimer; - WalkSpeedMultiplier = walkSpeedMultiplier; - RunSpeedMultiplier = runSpeedMultiplier; - } - } -} diff --git a/Content.Shared/Stunnable/StunnedComponent.cs b/Content.Shared/Stunnable/StunnedComponent.cs new file mode 100644 index 0000000000..a18341f5fa --- /dev/null +++ b/Content.Shared/Stunnable/StunnedComponent.cs @@ -0,0 +1,19 @@ +using System; +using Content.Shared.Movement.Components; +using Content.Shared.Sound; +using Robust.Shared.Analyzers; +using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Serialization; +using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.ViewVariables; + +namespace Content.Shared.Stunnable +{ + [Friend(typeof(SharedStunSystem))] + [RegisterComponent, NetworkedComponent] + public sealed class StunnedComponent : Component + { + public sealed override string Name => "Stunned"; + } +} diff --git a/Content.Shared/Tabletop/SharedTabletopSystem.cs b/Content.Shared/Tabletop/SharedTabletopSystem.cs index a80051257a..9d34212581 100644 --- a/Content.Shared/Tabletop/SharedTabletopSystem.cs +++ b/Content.Shared/Tabletop/SharedTabletopSystem.cs @@ -51,8 +51,7 @@ namespace Content.Shared.Tabletop protected static bool StunnedOrNoHands(IEntity playerEntity) { - var stunned = playerEntity.TryGetComponent(out var stun) && - stun.Stunned; + var stunned = playerEntity.HasComponent(); var hasHand = playerEntity.TryGetComponent(out var handsComponent) && handsComponent.Hands.Count > 0; diff --git a/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml b/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml index 51235f6e12..7ea449a142 100644 --- a/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml +++ b/Resources/Prototypes/Entities/Mobs/NPCs/simplemob.yml @@ -105,10 +105,10 @@ CarbonDioxide: 0.00015190972 damage: types: - Asphyxiation: 1 + Asphyxiation: 1 damageRecovery: types: - Asphyxiation: -1 + Asphyxiation: -1 - type: MobState thresholds: 0: !type:NormalMobState {} @@ -117,7 +117,11 @@ - type: HeatResistance - type: CombatMode - type: Internals - - type: Stunnable + - type: StatusEffects + allowed: + - Stun + - KnockedDown + - SlowedDown - type: Examiner - type: UnarmedCombat range: 1.5 diff --git a/Resources/Prototypes/Entities/Mobs/Species/human.yml b/Resources/Prototypes/Entities/Mobs/Species/human.yml index b7b4e66d8a..1a686e2ac0 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/human.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/human.yml @@ -62,8 +62,11 @@ solution: bloodstream - type: Bloodstream max_volume: 100 - # StatusEffects - - type: Stunnable + - type: StatusEffects + allowed: + - Stun + - KnockedDown + - SlowedDown # Other - type: Inventory - type: Clickable diff --git a/Resources/Prototypes/status_effects.yml b/Resources/Prototypes/status_effects.yml new file mode 100644 index 0000000000..4cd110b1fd --- /dev/null +++ b/Resources/Prototypes/status_effects.yml @@ -0,0 +1,17 @@ +# Status effect prototypes. +# Holds no actual logic, just some basic data about the effect. + +- type: statusEffect + id: Stun + alert: Stun + +- type: statusEffect + id: KnockedDown + alert: Stun + +- type: statusEffect + id: SlowedDown + +- type: statusEffect + id: Jitter + alwaysAllowed: true