]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Crawling Fixes 1: Dragons and Borgs can't do the worm. (#39084)
authorPrincess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
Sun, 10 Aug 2025 17:49:29 +0000 (10:49 -0700)
committerGitHub <noreply@github.com>
Sun, 10 Aug 2025 17:49:29 +0000 (10:49 -0700)
* Init Commit

* Remove unused code, fix stun visuals bug

* Update Content.Shared/Stunnable/SharedStunSystem.cs

* Some initial changes

* first batch of changes

* Commit

* One line cleanup

* KnockdownStatusEffect ain't worth it.

* Fix 2 bugs

* Fixes

* Remove that actually,

* Commit

* Better solution

* Alright final commit I think

* Add better remarks

* How the fuck did this not get pushed???

* Wait no why was my ryder trying to push that??? I didn't make that change! DON'T DO THAT!!!

* Review

* Don't log that

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
14 files changed:
Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs
Content.Server/Stunnable/Components/StunOnCollideComponent.cs
Content.Server/Stunnable/Systems/StunOnCollideSystem.cs
Content.Shared/Slippery/SlipperySystem.cs
Content.Shared/Standing/StandingStateComponent.cs
Content.Shared/Standing/StandingStateSystem.cs
Content.Shared/Stunnable/CrawlerComponent.cs [new file with mode: 0644]
Content.Shared/Stunnable/KnockdownStatusEffectComponent.cs
Content.Shared/Stunnable/SharedStunSystem.Knockdown.cs
Content.Shared/Stunnable/SharedStunSystem.cs
Content.Shared/Stunnable/StunnableEvents.cs
Resources/Prototypes/Entities/Mobs/NPCs/animals.yml
Resources/Prototypes/Entities/Mobs/Species/base.yml
Resources/Prototypes/Entities/StatusEffects/movement.yml

index e78a17e180513545ac6effb7e36391e1ba679b60..b5adeb04dbd5f473bcb45522cfe16faa8b8a9299 100644 (file)
@@ -249,7 +249,7 @@ public sealed partial class ShuttleSystem
 
             if (direction.LengthSquared() > minsq)
             {
-                _stuns.TryUpdateKnockdownDuration(uid, knockdownTime);
+                _stuns.TryCrawling(uid, knockdownTime);
                 _throwing.TryThrow(uid, direction, physics, Transform(uid), _projQuery, direction.Length(), playSound: false);
             }
             else
index 363fb78b750fd6e0a544000fadd867951194a7ae..cbf6b17af899817fbce482b795f01e9db2540fb4 100644 (file)
@@ -1,58 +1,66 @@
-namespace Content.Server.Stunnable.Components
+using Content.Server.Stunnable.Systems;
+
+namespace Content.Server.Stunnable.Components;
+
+/// <summary>
+/// Adds stun when it collides with an entity
+/// </summary>
+[RegisterComponent, Access(typeof(StunOnCollideSystem))]
+public sealed partial class StunOnCollideComponent : Component
 {
+    // TODO: Can probably predict this.
+
+    /// <summary>
+    /// How long we are stunned for
+    /// </summary>
+    [DataField]
+    public TimeSpan StunAmount;
+
+    /// <summary>
+    /// How long we are knocked down for
+    /// </summary>
+    [DataField]
+    public TimeSpan KnockdownAmount;
+
+    /// <summary>
+    /// How long we are slowed down for
+    /// </summary>
+    [DataField]
+    public TimeSpan SlowdownAmount;
+
+    /// <summary>
+    /// Multiplier for a mob's walking speed
+    /// </summary>
+    [DataField]
+    public float WalkSpeedModifier = 1f;
+
     /// <summary>
-    /// Adds stun when it collides with an entity
-    /// </summary>
-    [RegisterComponent, Access(typeof(StunOnCollideSystem))]
-    public sealed partial class StunOnCollideComponent : Component
-    {
-        // TODO: Can probably predict this.
-
-        /// <summary>
-        /// How long we are stunned for
-        /// </summary>
-        [DataField]
-        public TimeSpan StunAmount;
-
-        /// <summary>
-        /// How long we are knocked down for
-        /// </summary>
-        [DataField]
-        public TimeSpan KnockdownAmount;
-
-        /// <summary>
-        /// How long we are slowed down for
-        /// </summary>
-        [DataField]
-        public TimeSpan SlowdownAmount;
-
-        /// <summary>
-        /// Multiplier for a mob's walking speed
-        /// </summary>
-        [DataField]
-        public float WalkSpeedModifier = 1f;
-
-        /// <summary>
-        /// Multiplier for a mob's sprinting speed
-        /// </summary>
-        [DataField]
-        public float SprintSpeedModifier = 1f;
-
-        /// <summary>
-        /// Refresh Stun or Slowdown on hit
-        /// </summary>
-        [DataField]
-        public bool Refresh = true;
-
-        /// <summary>
-        /// Should the entity try and stand automatically after being knocked down?
-        /// </summary>
-        [DataField]
-        public bool AutoStand = true;
-
-        /// <summary>
-        /// Fixture we track for the collision.
-        /// </summary>
-        [DataField("fixture")] public string FixtureID = "projectile";
-    }
+    /// Multiplier for a mob's sprinting speed
+    /// </summary>
+    [DataField]
+    public float SprintSpeedModifier = 1f;
+
+    /// <summary>
+    /// Refresh Stun or Slowdown on hit
+    /// </summary>
+    [DataField]
+    public bool Refresh = true;
+
+    /// <summary>
+    /// Should the entity try and stand automatically after being knocked down?
+    /// </summary>
+    [DataField]
+    public bool AutoStand = true;
+
+    /// <summary>
+    /// Should the entity drop their items upon first being knocked down?
+    /// </summary>
+    [DataField]
+    public bool Drop = true;
+
+    /// <summary>
+    /// Fixture we track for the collision.
+    /// </summary>
+    [DataField("fixture")] public string FixtureID = "projectile";
 }
+
index 18c386d4ac05ccecf7d151e82b844e2edee0c826..2257812da198136e17af4aa8262b820fac59a307 100644 (file)
@@ -4,47 +4,60 @@ using JetBrains.Annotations;
 using Content.Shared.Throwing;
 using Robust.Shared.Physics.Events;
 
-namespace Content.Server.Stunnable
+namespace Content.Server.Stunnable.Systems;
+
+[UsedImplicitly]
+internal sealed class StunOnCollideSystem : EntitySystem
 {
-    [UsedImplicitly]
-    internal sealed class StunOnCollideSystem : EntitySystem
-    {
-        [Dependency] private readonly StunSystem _stunSystem = default!;
-        [Dependency] private readonly MovementModStatusSystem _movementMod = default!;
+    [Dependency] private readonly StunSystem _stunSystem = default!;
+    [Dependency] private readonly MovementModStatusSystem _movementMod = default!;
 
-        public override void Initialize()
-        {
-            base.Initialize();
-            SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide);
-            SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow);
-        }
+    public override void Initialize()
+    {
+        base.Initialize();
 
-        private void TryDoCollideStun(EntityUid uid, StunOnCollideComponent component, EntityUid target)
-        {
-            _stunSystem.TryUpdateStunDuration(target, component.StunAmount);
+        SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide);
+        SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow);
+    }
 
-            _stunSystem.TryKnockdown(target, component.KnockdownAmount, component.Refresh, component.AutoStand, force: true);
+    private void TryDoCollideStun(Entity<StunOnCollideComponent> ent, EntityUid target)
+    {
+        _stunSystem.TryKnockdown(target, ent.Comp.KnockdownAmount, ent.Comp.Refresh, ent.Comp.AutoStand, ent.Comp.Drop);
 
+        if (ent.Comp.Refresh)
+        {
+            _stunSystem.TryUpdateStunDuration(target, ent.Comp.StunAmount);
             _movementMod.TryUpdateMovementSpeedModDuration(
                 target,
                 MovementModStatusSystem.TaserSlowdown,
-                component.SlowdownAmount,
-                component.WalkSpeedModifier,
-                component.SprintSpeedModifier
+                ent.Comp.SlowdownAmount,
+                ent.Comp.WalkSpeedModifier,
+                ent.Comp.SprintSpeedModifier
             );
         }
-
-        private void HandleCollide(EntityUid uid, StunOnCollideComponent component, ref StartCollideEvent args)
+        else
         {
-            if (args.OurFixtureId != component.FixtureID)
-                return;
-
-            TryDoCollideStun(uid, component, args.OtherEntity);
+            _stunSystem.TryAddStunDuration(target, ent.Comp.StunAmount);
+            _movementMod.TryAddMovementSpeedModDuration(
+                target,
+                MovementModStatusSystem.TaserSlowdown,
+                ent.Comp.SlowdownAmount,
+                ent.Comp.WalkSpeedModifier,
+                ent.Comp.SprintSpeedModifier
+            );
         }
+    }
 
-        private void HandleThrow(EntityUid uid, StunOnCollideComponent component, ThrowDoHitEvent args)
-        {
-            TryDoCollideStun(uid, component, args.Target);
-        }
+    private void HandleCollide(Entity<StunOnCollideComponent> ent, ref StartCollideEvent args)
+    {
+        if (args.OurFixtureId != ent.Comp.FixtureID)
+            return;
+
+        TryDoCollideStun(ent, args.OtherEntity);
+    }
+
+    private void HandleThrow(Entity<StunOnCollideComponent> ent, ref ThrowDoHitEvent args)
+    {
+        TryDoCollideStun(ent, args.Target);
     }
 }
index 6a0e96888acfde25e53985ca37564fe635d66cbf..51bbd2bea0f39de18110f2544ccd5ae19e6e4095 100644 (file)
@@ -149,7 +149,8 @@ public sealed class SlipperySystem : EntitySystem
             _audio.PlayPredicted(component.SlipSound, other, other);
         }
 
-        _stun.TryKnockdown(other, component.SlipData.KnockdownTime, true, force: true);
+        // Slippery is so tied to knockdown that we really just need to force it here.
+        _stun.TryKnockdown(other, component.SlipData.KnockdownTime, force: true);
 
         _adminLogger.Add(LogType.Slip, LogImpact.Low, $"{ToPrettyString(other):mob} slipped on collision with {ToPrettyString(uid):entity}");
     }
index c6252d969af0f5356c8e2e28eb65d1636e61f1f1..8ed00ce23e2d23926d9bf351ab3ead86b7b620f7 100644 (file)
@@ -15,23 +15,10 @@ namespace Content.Shared.Standing
         public bool Standing { get; set; } = true;
 
         /// <summary>
-        /// Time it takes us to stand up
+        /// Friction modifier applied to an entity in the downed state.
         /// </summary>
         [DataField, AutoNetworkedField]
-        public TimeSpan StandTime = TimeSpan.FromSeconds(2);
-
-        /// <summary>
-        /// Default Friction modifier for knocked down players.
-        /// Makes them accelerate and deccelerate slower.
-        /// </summary>
-        [DataField, AutoNetworkedField]
-        public float FrictionModifier = 0.4f;
-
-        /// <summary>
-        /// Base modifier to the maximum movement speed of a knocked down mover.
-        /// </summary>
-        [DataField, AutoNetworkedField]
-        public float SpeedModifier = 0.3f;
+        public float DownFrictionMod = 0.4f;
 
         /// <summary>
         ///     List of fixtures that had their collision mask changed when the entity was downed.
index 717756816394d25948f562fec801777e8fb68f3f..f965e0ae7cfbafb32f58ef3beab41da82e62b7ba 100644 (file)
@@ -23,7 +23,6 @@ public sealed class StandingStateSystem : EntitySystem
         base.Initialize();
         SubscribeLocalEvent<StandingStateComponent, AttemptMobCollideEvent>(OnMobCollide);
         SubscribeLocalEvent<StandingStateComponent, AttemptMobTargetCollideEvent>(OnMobTargetCollide);
-        SubscribeLocalEvent<StandingStateComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
         SubscribeLocalEvent<StandingStateComponent, RefreshFrictionModifiersEvent>(OnRefreshFrictionModifiers);
         SubscribeLocalEvent<StandingStateComponent, TileFrictionEvent>(OnTileFriction);
     }
@@ -44,25 +43,19 @@ public sealed class StandingStateSystem : EntitySystem
         }
     }
 
-    private void OnRefreshMovementSpeedModifiers(Entity<StandingStateComponent> entity, ref RefreshMovementSpeedModifiersEvent args)
-    {
-        if (!entity.Comp.Standing)
-            args.ModifySpeed(entity.Comp.FrictionModifier);
-    }
-
     private void OnRefreshFrictionModifiers(Entity<StandingStateComponent> entity, ref RefreshFrictionModifiersEvent args)
     {
         if (entity.Comp.Standing)
             return;
 
-        args.ModifyFriction(entity.Comp.FrictionModifier);
-        args.ModifyAcceleration(entity.Comp.FrictionModifier);
+        args.ModifyFriction(entity.Comp.DownFrictionMod);
+        args.ModifyAcceleration(entity.Comp.DownFrictionMod);
     }
 
     private void OnTileFriction(Entity<StandingStateComponent> entity, ref TileFrictionEvent args)
     {
         if (!entity.Comp.Standing)
-            args.Modifier *= entity.Comp.FrictionModifier;
+            args.Modifier *= entity.Comp.DownFrictionMod;
     }
 
     public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)
diff --git a/Content.Shared/Stunnable/CrawlerComponent.cs b/Content.Shared/Stunnable/CrawlerComponent.cs
new file mode 100644 (file)
index 0000000..d969117
--- /dev/null
@@ -0,0 +1,40 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Stunnable;
+
+/// <summary>
+/// This is used to denote that an entity can crawl.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, Access(typeof(SharedStunSystem))]
+public sealed partial class CrawlerComponent : Component
+{
+    /// <summary>
+    /// Default time we will be knocked down for.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public TimeSpan DefaultKnockedDuration { get; set; } = TimeSpan.FromSeconds(0.5);
+
+    /// <summary>
+    /// Minimum damage taken to extend our knockdown timer by the default time.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float KnockdownDamageThreshold = 5f;
+
+    /// <summary>
+    /// Time it takes us to stand up
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public TimeSpan StandTime = TimeSpan.FromSeconds(2);
+
+    /// <summary>
+    /// Base modifier to the maximum movement speed of a knocked down mover.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float SpeedModifier = 0.4f;
+
+    /// <summary>
+    /// Friction modifier applied to an entity in the downed state.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public float FrictionModifier = 1f;
+}
index 79b2fb695b937fb23a032a1b6309a63aafcd268a..b4805511b2ddbca02d1ace5befb2ca058cb7b49a 100644 (file)
@@ -6,4 +6,22 @@ namespace Content.Shared.Stunnable;
 /// Knockdown as a status effect.
 /// </summary>
 [RegisterComponent, NetworkedComponent, Access(typeof(SharedStunSystem))]
-public sealed partial class KnockdownStatusEffectComponent : Component;
+public sealed partial class KnockdownStatusEffectComponent : Component
+{
+    /// <summary>
+    /// Should this knockdown only affect crawlers?
+    /// </summary>
+    /// <remarks>
+    /// If your status effect doesn't come paired with <see cref="StunnedStatusEffectComponent"/>
+    /// Or if your status effect doesn't whitelist itself to only those with <see cref="CrawlerComponent"/>
+    /// Then you need to set this to true.
+    /// </remarks>
+    [DataField]
+    public bool Crawl;
+
+    /// <summary>
+    /// Should we drop items when we fall?
+    /// </summary>
+    [DataField]
+    public bool Drop = true;
+}
index 26e8e47f033e87109d71bc3cfe2a5f242454c443..7917f10bd5876109127c06b1b5d4c175bca4b0bd 100644 (file)
@@ -25,13 +25,7 @@ namespace Content.Shared.Stunnable;
 /// </summary>
 public abstract partial class SharedStunSystem
 {
-    // TODO: Both of these constants need to be moved to a component somewhere, and need to be tweaked for balance...
-    // We don't always have standing state available when these are called so it can't go there
-    // Maybe I can pass the values to KnockedDownComponent from Standing state on Component init?
-    // Default knockdown timer
-    public static readonly TimeSpan DefaultKnockedDuration = TimeSpan.FromSeconds(0.5f);
-    // Minimum damage taken to refresh our knockdown timer to the default duration
-    public static readonly float KnockdownDamageThreshold = 5f;
+    private EntityQuery<CrawlerComponent> _crawlerQuery;
 
     [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
     [Dependency] private readonly SharedHandsSystem _hands = default!;
@@ -43,6 +37,8 @@ public abstract partial class SharedStunSystem
 
     private void InitializeKnockdown()
     {
+        _crawlerQuery = GetEntityQuery<CrawlerComponent>();
+
         SubscribeLocalEvent<KnockedDownComponent, RejuvenateEvent>(OnRejuvenate);
 
         // Startup and Shutdown
@@ -61,8 +57,9 @@ public abstract partial class SharedStunSystem
         // DoAfter event subscriptions
         SubscribeLocalEvent<KnockedDownComponent, TryStandDoAfterEvent>(OnStandDoAfter);
 
-        // Knockdown Extenders
-        SubscribeLocalEvent<KnockedDownComponent, DamageChangedEvent>(OnDamaged);
+        // Crawling
+        SubscribeLocalEvent<CrawlerComponent, KnockedDownRefreshEvent>(OnKnockdownRefresh);
+        SubscribeLocalEvent<CrawlerComponent, DamageChangedEvent>(OnDamaged);
 
         // Handling Alternative Inputs
         SubscribeAllEvent<ForceStandUpEvent>(OnForceStandup);
@@ -81,6 +78,7 @@ public abstract partial class SharedStunSystem
 
         while (query.MoveNext(out var uid, out var knockedDown))
         {
+            // If it's null then we don't want to stand up
             if (!knockedDown.AutoStand || knockedDown.DoAfterId.HasValue || knockedDown.NextUpdate > GameTiming.CurTime)
                 continue;
 
@@ -157,7 +155,7 @@ public abstract partial class SharedStunSystem
     /// <param name="entity">Entity who's knockdown time we're updating.</param>
     /// <param name="time">The time we're updating with.</param>
     /// <param name="refresh">Whether we're resetting the timer or adding to the current timer.</param>
-    public void UpdateKnockdownTime(Entity<KnockedDownComponent> entity, TimeSpan time, bool refresh = true)
+    public void UpdateKnockdownTime(Entity<KnockedDownComponent?> entity, TimeSpan time, bool refresh = true)
     {
         if (refresh)
             RefreshKnockdownTime(entity, time);
@@ -174,6 +172,7 @@ public abstract partial class SharedStunSystem
     {
         entity.Comp.NextUpdate = time;
         DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate));
+        Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, entity.Comp.NextUpdate));
     }
 
     /// <summary>
@@ -182,11 +181,14 @@ public abstract partial class SharedStunSystem
     /// </summary>
     /// <param name="entity">Entity whose timer we're updating</param>
     /// <param name="time">The time we want them to be knocked down for.</param>
-    public void RefreshKnockdownTime(Entity<KnockedDownComponent> entity, TimeSpan time)
+    public void RefreshKnockdownTime(Entity<KnockedDownComponent?> entity, TimeSpan time)
     {
+        if (!Resolve(entity, ref entity.Comp, false))
+            return;
+
         var knockedTime = GameTiming.CurTime + time;
         if (entity.Comp.NextUpdate < knockedTime)
-            SetKnockdownTime(entity, knockedTime);
+            SetKnockdownTime((entity, entity.Comp), knockedTime);
     }
 
     /// <summary>
@@ -194,35 +196,20 @@ public abstract partial class SharedStunSystem
     /// </summary>
     /// <param name="entity">Entity whose timer we're updating</param>
     /// <param name="time">The time we want to add to their knocked down timer.</param>
-    public void AddKnockdownTime(Entity<KnockedDownComponent> entity, TimeSpan time)
+    public void AddKnockdownTime(Entity<KnockedDownComponent?> entity, TimeSpan time)
     {
+        if (!Resolve(entity, ref entity.Comp, false))
+            return;
+
         if (entity.Comp.NextUpdate < GameTiming.CurTime)
         {
-            SetKnockdownTime(entity, GameTiming.CurTime + time);
+            SetKnockdownTime((entity, entity.Comp), GameTiming.CurTime + time);
             return;
         }
 
         entity.Comp.NextUpdate += time;
         DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate));
-    }
-
-    /// <summary>
-    /// Checks if an entity is able to stand, returns true if it can, returns false if it cannot.
-    /// </summary>
-    /// <param name="entity">Entity we're checking</param>
-    /// <returns>Returns whether the entity is able to stand</returns>
-    public bool CanStand(Entity<KnockedDownComponent> entity)
-    {
-        if (entity.Comp.NextUpdate > GameTiming.CurTime)
-            return false;
-
-        if (!Blocker.CanMove(entity))
-            return false;
-
-        var ev = new StandUpAttemptEvent();
-        RaiseLocalEvent(entity, ref ev);
-
-        return !ev.Cancelled;
+        Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, entity.Comp.NextUpdate));
     }
 
     #endregion
@@ -237,29 +224,55 @@ public abstract partial class SharedStunSystem
         if (playerSession.AttachedEntity is not { Valid: true } playerEnt || !Exists(playerEnt))
             return;
 
-        if (!TryComp<KnockedDownComponent>(playerEnt, out var component))
+        ToggleKnockdown(playerEnt);
+    }
+
+    /// <summary>
+    /// Handles an entity trying to make itself fall down.
+    /// </summary>
+    /// <param name="entity">Entity who is trying to fall down</param>
+    private void ToggleKnockdown(Entity<CrawlerComponent?, KnockedDownComponent?> entity)
+    {
+        // We resolve here instead of using TryCrawling to be extra sure someone without crawler can't stand up early.
+        if (!Resolve(entity, ref entity.Comp1, false))
+            return;
+
+        if (!Resolve(entity, ref entity.Comp2, false))
         {
-            TryKnockdown(playerEnt, DefaultKnockedDuration, true, false, false); // TODO: Unhardcode these numbers
+            TryKnockdown(entity.Owner, entity.Comp1.DefaultKnockedDuration, true, false, false);
             return;
         }
 
-        var stand = !component.DoAfterId.HasValue;
-        SetAutoStand(playerEnt, stand);
+        var stand = !entity.Comp2.DoAfterId.HasValue;
+        SetAutoStand((entity, entity.Comp2), stand);
 
-        if (!stand || !TryStanding(playerEnt))
-            CancelKnockdownDoAfter((playerEnt, component));
+        if (!stand || !TryStanding((entity, entity.Comp2)))
+            CancelKnockdownDoAfter((entity, entity.Comp2));
     }
 
-    public bool TryStanding(Entity<KnockedDownComponent?, StandingStateComponent?> entity)
+    public bool TryStanding(Entity<KnockedDownComponent?> entity)
     {
         // If we aren't knocked down or can't be knocked down, then we did technically succeed in standing up
-        if (!Resolve(entity, ref entity.Comp1, ref entity.Comp2, false))
+        if (!Resolve(entity, ref entity.Comp, false))
+            return true;
+
+        if (!KnockdownOver((entity, entity.Comp)))
+            return false;
+
+        if (!_crawlerQuery.TryComp(entity, out var crawler))
+        {
+            // If we can't crawl then just have us sit back up...
+            // In case you're wondering, the KnockdownOverCheck, returns if we're able to move, so if next update is null.
+            // An entity that can't crawl will stand up the next time they can move, which should prevent moving while knocked down.
+            RemComp<KnockedDownComponent>(entity);
+            _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(entity):user} has stood up from knockdown.");
             return true;
+        }
 
-        if (!TryStand((entity.Owner, entity.Comp1)))
+        if (!TryStand((entity, entity.Comp)))
             return false;
 
-        var ev = new GetStandUpTimeEvent(entity.Comp2.StandTime);
+        var ev = new GetStandUpTimeEvent(crawler.StandTime);
         RaiseLocalEvent(entity, ref ev);
 
         var doAfterArgs = new DoAfterArgs(EntityManager, entity, ev.DoAfterTime, new TryStandDoAfterEvent(), entity, entity)
@@ -275,11 +288,19 @@ public abstract partial class SharedStunSystem
         if (!DoAfter.TryStartDoAfter(doAfterArgs, out var doAfterId))
             return false;
 
-        entity.Comp1.DoAfterId = doAfterId.Value.Index;
-        DirtyField(entity, entity.Comp1, nameof(KnockedDownComponent.DoAfterId));
+        entity.Comp.DoAfterId = doAfterId.Value.Index;
+        DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.DoAfterId));
         return true;
     }
 
+    public bool KnockdownOver(Entity<KnockedDownComponent> entity)
+    {
+        if (entity.Comp.NextUpdate > GameTiming.CurTime)
+            return false;
+
+        return Blocker.CanMove(entity);
+    }
+
     /// <summary>
     /// A variant of <see cref="CanStand"/> used when we're actually trying to stand.
     /// Main difference is this one affects autostand datafields and also displays popups.
@@ -288,10 +309,7 @@ public abstract partial class SharedStunSystem
     /// <returns>Returns whether the entity is able to stand</returns>
     public bool TryStand(Entity<KnockedDownComponent> entity)
     {
-        if (entity.Comp.NextUpdate > GameTiming.CurTime)
-            return false;
-
-        if (!Blocker.CanMove(entity))
+        if (!KnockdownOver(entity))
             return false;
 
         var ev = new StandUpAttemptEvent(entity.Comp.AutoStand);
@@ -308,6 +326,22 @@ public abstract partial class SharedStunSystem
         return !ev.Cancelled;
     }
 
+    /// <summary>
+    /// Checks if an entity is able to stand, returns true if it can, returns false if it cannot.
+    /// </summary>
+    /// <param name="entity">Entity we're checking</param>
+    /// <returns>Returns whether the entity is able to stand</returns>
+    public bool CanStand(Entity<KnockedDownComponent> entity)
+    {
+        if (!KnockdownOver(entity))
+            return false;
+
+        var ev = new StandUpAttemptEvent();
+        RaiseLocalEvent(entity, ref ev);
+
+        return !ev.Cancelled;
+    }
+
     private bool StandingBlocked(Entity<KnockedDownComponent> entity)
     {
         if (!TryStand(entity))
@@ -338,7 +372,7 @@ public abstract partial class SharedStunSystem
         // That way if we fail to stand, the game will try to stand for us when we are able to
         SetAutoStand(entity, true);
 
-        if (!HasComp<StandingStateComponent>(entity) || StandingBlocked((entity, entity.Comp)))
+        if (StandingBlocked((entity, entity.Comp)))
             return;
 
         if (!_hands.TryGetEmptyHand(entity.Owner, out _))
@@ -436,16 +470,22 @@ public abstract partial class SharedStunSystem
 
     #endregion
 
-    #region Knockdown Extenders
+    #region Crawling
 
-    private void OnDamaged(Entity<KnockedDownComponent> entity, ref DamageChangedEvent args)
+    private void OnDamaged(Entity<CrawlerComponent> entity, ref DamageChangedEvent args)
     {
         // We only want to extend our knockdown timer if it would've prevented us from standing up
         if (!args.InterruptsDoAfters || !args.DamageIncreased || args.DamageDelta == null || GameTiming.ApplyingState)
             return;
 
-        if (args.DamageDelta.GetTotal() >= KnockdownDamageThreshold) // TODO: Unhardcode this
-            SetKnockdownTime(entity, GameTiming.CurTime + DefaultKnockedDuration);
+        if (args.DamageDelta.GetTotal() >= entity.Comp.KnockdownDamageThreshold)
+            RefreshKnockdownTime(entity.Owner, entity.Comp.DefaultKnockedDuration);
+    }
+
+    private void OnKnockdownRefresh(Entity<CrawlerComponent> entity, ref KnockedDownRefreshEvent args)
+    {
+        args.FrictionModifier *= entity.Comp.FrictionModifier;
+        args.SpeedModifier *= entity.Comp.SpeedModifier;
     }
 
     #endregion
index 199afcabf240485cc842cdc232caf67f73eb3b42..dcf9ee4f60816fc7b8ba5da175fd841ad4cc240e 100644 (file)
@@ -26,7 +26,6 @@ namespace Content.Shared.Stunnable;
 public abstract partial class SharedStunSystem : EntitySystem
 {
     public static readonly EntProtoId StunId = "StatusEffectStunned";
-    public static readonly EntProtoId KnockdownId = "StatusEffectKnockdown";
 
     [Dependency] protected readonly IGameTiming GameTiming = default!;
     [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
@@ -61,10 +60,11 @@ public abstract partial class SharedStunSystem : EntitySystem
         SubscribeLocalEvent<MobStateComponent, MobStateChangedEvent>(OnMobStateChanged);
 
         // New Status Effect subscriptions
-        SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectAppliedEvent>(OnStunEffectApplied);
+        SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectAppliedEvent>(OnStunStatusApplied);
         SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRemovedEvent>(OnStunStatusRemoved);
         SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRelayedEvent<StunEndAttemptEvent>>(OnStunEndAttempt);
 
+        SubscribeLocalEvent<KnockdownStatusEffectComponent, StatusEffectAppliedEvent>(OnKnockdownStatusApplied);
         SubscribeLocalEvent<KnockdownStatusEffectComponent, StatusEffectRelayedEvent<StandUpAttemptEvent>>(OnStandUpAttempt);
 
         // Stun Appearance Data
@@ -123,7 +123,7 @@ public abstract partial class SharedStunSystem : EntitySystem
             return;
 
         TryUpdateStunDuration(args.OtherEntity, ent.Comp.Duration);
-        TryKnockdown(args.OtherEntity, ent.Comp.Duration, true, force: true);
+        TryKnockdown(args.OtherEntity, ent.Comp.Duration, force: true);
     }
 
     // TODO STUN: Make events for different things. (Getting modifiers, attempt events, informative events...)
@@ -156,29 +156,54 @@ public abstract partial class SharedStunSystem : EntitySystem
         _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(uid):user} stunned for {timeForLogs} seconds");
     }
 
-    public bool TryAddKnockdownDuration(EntityUid uid, TimeSpan duration)
+    /// <summary>
+    ///     Tries to knock an entity to the ground, but will fail if they aren't able to crawl.
+    ///     Useful if you don't want to paralyze an entity that can't crawl, but still want to knockdown
+    ///     entities that can.
+    /// </summary>
+    /// <param name="entity">Entity we're trying to knockdown.</param>
+    /// <param name="time">Time of the knockdown.</param>
+    /// <param name="refresh">Do we refresh their timer, or add to it if one exists?</param>
+    /// <param name="autoStand">Whether we should automatically stand when knockdown ends.</param>
+    /// <param name="drop">Should we drop what we're holding?</param>
+    /// <param name="force">Should we force crawling? Even if something tried to block it?</param>
+    /// <returns>Returns true if the entity is able to crawl, and was able to be knocked down.</returns>
+    public bool TryCrawling(Entity<CrawlerComponent?> entity,
+        TimeSpan? time,
+        bool refresh = true,
+        bool autoStand = true,
+        bool drop = true,
+        bool force = false)
     {
-        if (!_status.TryAddStatusEffectDuration(uid, KnockdownId, duration))
+        if (!Resolve(entity, ref entity.Comp, false))
             return false;
 
-        TryKnockdown(uid, duration, true, force: true);
-
-        return true;
-
+        return TryKnockdown(entity, time, refresh, autoStand, drop, force);
     }
 
-    public bool TryUpdateKnockdownDuration(EntityUid uid, TimeSpan? duration)
+    /// <inheritdoc cref="TryCrawling(Entity{CrawlerComponent?},TimeSpan?,bool,bool,bool,bool)"/>
+    /// <summary>An overload of TryCrawling which uses the default crawling time from the CrawlerComponent as its timespan.</summary>
+    public bool TryCrawling(Entity<CrawlerComponent?> entity,
+        bool refresh = true,
+        bool autoStand = true,
+        bool drop = true,
+        bool force = false)
     {
-        if (!_status.TryUpdateStatusEffectDuration(uid, KnockdownId, duration))
+        if (!Resolve(entity, ref entity.Comp, false))
             return false;
 
-        return TryKnockdown(uid, duration, true, force: true);
+        return TryKnockdown(entity, entity.Comp.DefaultKnockedDuration, refresh, autoStand, drop, force);
     }
 
     /// <summary>
-    ///     Knocks down the entity, making it fall to the ground.
+    ///     Checks if we can knock down an entity to the ground...
     /// </summary>
-    public bool TryKnockdown(Entity<StandingStateComponent?> entity, TimeSpan? time, bool refresh, bool autoStand = true, bool drop = true, bool force = false)
+    /// <param name="entity">The entity we're trying to knock down</param>
+    /// <param name="time">The time of the knockdown</param>
+    /// <param name="autoStand">Whether we want to automatically stand when knockdown ends.</param>
+    /// <param name="drop">Whether we should drop items.</param>
+    /// <param name="force">Should we force the status effect?</param>
+    public bool CanKnockdown(Entity<StandingStateComponent?> entity, ref TimeSpan? time, ref bool autoStand, ref bool drop, bool force = false)
     {
         if (time <= TimeSpan.Zero)
             return false;
@@ -187,30 +212,53 @@ public abstract partial class SharedStunSystem : EntitySystem
         if (!Resolve(entity, ref entity.Comp, false))
             return false;
 
-        if (!force)
-        {
-            var evAttempt = new KnockDownAttemptEvent(autoStand, drop);
-            RaiseLocalEvent(entity, ref evAttempt);
+        var evAttempt = new KnockDownAttemptEvent(autoStand, drop, time);
+        RaiseLocalEvent(entity, ref evAttempt);
 
-            if (evAttempt.Cancelled)
-                return false;
+        autoStand = evAttempt.AutoStand;
+        drop = evAttempt.Drop;
 
-            autoStand = evAttempt.AutoStand;
-            drop = evAttempt.Drop;
-        }
+        return force || !evAttempt.Cancelled;
+    }
 
-        Knockdown(entity!, time, refresh, autoStand, drop);
+    /// <summary>
+    ///     Knocks down the entity, making it fall to the ground.
+    /// </summary>
+    /// <param name="entity">The entity we're trying to knock down</param>
+    /// <param name="time">The time of the knockdown</param>
+    /// <param name="refresh">Whether we should refresh a running timer or add to it, if one exists.</param>
+    /// <param name="autoStand">Whether we want to automatically stand when knockdown ends.</param>
+    /// <param name="drop">Whether we should drop items.</param>
+    /// <param name="force">Should we force the status effect?</param>
+    public bool TryKnockdown(Entity<CrawlerComponent?> entity, TimeSpan? time, bool refresh = true, bool autoStand = true, bool drop = true, bool force = false)
+    {
+        if (!CanKnockdown(entity.Owner, ref time, ref autoStand, ref drop, force))
+            return false;
 
+        // If the entity can't crawl they also need to be stunned, and therefore we should be using paralysis status effect.
+        // Also time shouldn't be null if we're and trying to add time but, we check just in case anyways.
+        if (!Resolve(entity, ref entity.Comp, false))
+            return refresh || time == null ? TryUpdateParalyzeDuration(entity, time) : TryAddParalyzeDuration(entity, time.Value);
+
+        Knockdown(entity, time, refresh, autoStand, drop);
         return true;
     }
 
-    private void Knockdown(Entity<StandingStateComponent> entity, TimeSpan? time, bool refresh, bool autoStand, bool drop)
+    private void Crawl(Entity<CrawlerComponent?> entity, TimeSpan? time, bool refresh, bool autoStand, bool drop)
+    {
+        if (!Resolve(entity, ref entity.Comp, false))
+            return;
+
+        Knockdown(entity, time, refresh, autoStand, drop);
+    }
+
+    private void Knockdown(EntityUid uid, TimeSpan? time, bool refresh, bool autoStand, bool drop)
     {
         // Initialize our component with the relevant data we need if we don't have it
-        if (EnsureComp<KnockedDownComponent>(entity, out var component))
+        if (EnsureComp<KnockedDownComponent>(uid, out var component))
         {
-            RefreshKnockedMovement((entity, component));
-            CancelKnockdownDoAfter((entity, component));
+            RefreshKnockedMovement((uid, component));
+            CancelKnockdownDoAfter((uid, component));
         }
         else
         {
@@ -218,41 +266,50 @@ public abstract partial class SharedStunSystem : EntitySystem
             if (drop)
             {
                 var ev = new DropHandItemsEvent();
-                RaiseLocalEvent(entity, ref ev);
+                RaiseLocalEvent(uid, ref ev);
             }
 
             // Only update Autostand value if it's our first time being knocked down...
-            SetAutoStand((entity, component), autoStand);
+            SetAutoStand((uid, component), autoStand);
         }
 
-        var knockedEv = new KnockedDownEvent(time);
-        RaiseLocalEvent(entity, ref knockedEv);
+        var knockedEv = new KnockedDownEvent();
+        RaiseLocalEvent(uid, ref knockedEv);
 
         if (time != null)
         {
-            UpdateKnockdownTime((entity, component), time.Value, refresh);
-            _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(entity):user} knocked down for {time.Value.Seconds} seconds");
+            UpdateKnockdownTime((uid, component), time.Value, refresh);
+            _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(uid):user} was knocked down for {time.Value.Seconds} seconds");
         }
         else
-            _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(entity):user} knocked down for an indefinite amount of time");
-
-        Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, component.NextUpdate));
+        {
+            Alerts.ShowAlert(uid, KnockdownAlert);
+            _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(uid):user} was knocked down");
+        }
     }
 
     public bool TryAddParalyzeDuration(EntityUid uid, TimeSpan duration)
     {
-        var knockdown = TryAddKnockdownDuration(uid, duration);
-        var stunned = TryAddStunDuration(uid, duration);
+        if (!_status.TryAddStatusEffectDuration(uid, StunId, duration))
+            return false;
+
+        // We can't exit knockdown when we're stunned, so this prevents knockdown lasting longer than the stun.
+        Knockdown(uid, null, false, true, true);
+        OnStunnedSuccessfully(uid, duration);
 
-        return knockdown || stunned;
+        return true;
     }
 
     public bool TryUpdateParalyzeDuration(EntityUid uid, TimeSpan? duration)
     {
-        var knockdown = TryUpdateKnockdownDuration(uid, duration);
-        var stunned = TryUpdateStunDuration(uid, duration);
+        if (!_status.TryUpdateStatusEffectDuration(uid, StunId, duration))
+            return false;
+
+        // We can't exit knockdown when we're stunned, so this prevents knockdown lasting longer than the stun.
+        Knockdown(uid, null, false, true, true);
+        OnStunnedSuccessfully(uid, duration);
 
-        return knockdown || stunned;
+        return true;
     }
 
     public bool TryUnstun(Entity<StunnedComponent?> entity)
@@ -266,7 +323,7 @@ public abstract partial class SharedStunSystem : EntitySystem
         return !ev.Cancelled && RemComp<StunnedComponent>(entity);
     }
 
-    private void OnStunEffectApplied(Entity<StunnedStatusEffectComponent> entity, ref StatusEffectAppliedEvent args)
+    private void OnStunStatusApplied(Entity<StunnedStatusEffectComponent> entity, ref StatusEffectAppliedEvent args)
     {
         if (GameTiming.ApplyingState)
             return;
@@ -289,6 +346,18 @@ public abstract partial class SharedStunSystem : EntitySystem
         args.Args = ev;
     }
 
+    private void OnKnockdownStatusApplied(Entity<KnockdownStatusEffectComponent> entity, ref StatusEffectAppliedEvent args)
+    {
+        if (GameTiming.ApplyingState)
+            return;
+
+        // If you make something that shouldn't crawl, crawl, that's your own fault.
+        if (entity.Comp.Crawl)
+            Crawl(args.Target, null, true, true, drop: entity.Comp.Drop);
+        else
+            Knockdown(args.Target, null, true, true, drop: entity.Comp.Drop);
+    }
+
     private void OnStandUpAttempt(Entity<KnockdownStatusEffectComponent> entity, ref StatusEffectRelayedEvent<StandUpAttemptEvent> args)
     {
         if (args.Args.Cancelled)
index f4a0191c92c1c2bbd6da45bd5be2db0d34cdf633..f0c08f61369b4f1be2b592157a4f97a386d17d99 100644 (file)
@@ -26,7 +26,7 @@ public record struct StunEndAttemptEvent(bool Cancelled);
 ///     knocked down arguments.
 /// </summary>
 [ByRefEvent]
-public record struct KnockDownAttemptEvent(bool AutoStand, bool Drop)
+public record struct KnockDownAttemptEvent(bool AutoStand, bool Drop, TimeSpan? Time)
 {
     public bool Cancelled;
 }
@@ -35,7 +35,7 @@ public record struct KnockDownAttemptEvent(bool AutoStand, bool Drop)
 ///     Raised directed on an entity when it is knocked down.
 /// </summary>
 [ByRefEvent]
-public record struct KnockedDownEvent(TimeSpan? Time);
+public record struct KnockedDownEvent;
 
 /// <summary>
 ///     Raised on an entity that needs to refresh its knockdown modifiers
index da68ee109be682557ae9339dfa81e37bfa42249d..d9b2b8399392efda60c4bdc03c7955545bef3e8f 100644 (file)
       methods: [ Touch ]
       effects:
       - !type:WashCreamPieReaction
+  - type: Crawler
 
 
 
index 8fcaef42b98b0449f42ee7bb30810ed16adc06b7..10c39ed7a082ca35f235176e9a688bcbd942d517 100644 (file)
   - type: SleepEmitSound
   - type: SSDIndicator
   - type: StandingState
+  - type: Crawler
   - type: Dna
   - type: MindContainer
     showExamineInfo: true
index a6cbd207246e2e1c852e7c725e84e5aff3475e46..71142af434c9dca6f05838dfa0dc3c1322c107bb 100644 (file)
   - type: StatusEffectAlert
     alert: Stun
   - type: StunnedStatusEffect
-
-- type: entity
-  parent: MobStandStatusEffectBase
-  id: StatusEffectKnockdown
-  name: knocked down
-  components:
-  - type: KnockdownStatusEffect