Crawling Fixes 1: Dragons and Borgs can't do the worm. (#39084)

* 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>
This commit is contained in:
Princess Cheeseballs
2025-08-10 10:49:29 -07:00
committed by GitHub
parent 4e29107c89
commit 55335cce0f
14 changed files with 376 additions and 212 deletions

View File

@@ -249,7 +249,7 @@ public sealed partial class ShuttleSystem
if (direction.LengthSquared() > minsq) if (direction.LengthSquared() > minsq)
{ {
_stuns.TryUpdateKnockdownDuration(uid, knockdownTime); _stuns.TryCrawling(uid, knockdownTime);
_throwing.TryThrow(uid, direction, physics, Transform(uid), _projQuery, direction.Length(), playSound: false); _throwing.TryThrow(uid, direction, physics, Transform(uid), _projQuery, direction.Length(), playSound: false);
} }
else else

View 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> /// <summary>
/// Adds stun when it collides with an entity /// How long we are stunned for
/// </summary> /// </summary>
[RegisterComponent, Access(typeof(StunOnCollideSystem))] [DataField]
public sealed partial class StunOnCollideComponent : Component public TimeSpan StunAmount;
{
// TODO: Can probably predict this.
/// <summary> /// <summary>
/// How long we are stunned for /// How long we are knocked down for
/// </summary> /// </summary>
[DataField] [DataField]
public TimeSpan StunAmount; public TimeSpan KnockdownAmount;
/// <summary> /// <summary>
/// How long we are knocked down for /// How long we are slowed down for
/// </summary> /// </summary>
[DataField] [DataField]
public TimeSpan KnockdownAmount; public TimeSpan SlowdownAmount;
/// <summary> /// <summary>
/// How long we are slowed down for /// Multiplier for a mob's walking speed
/// </summary> /// </summary>
[DataField] [DataField]
public TimeSpan SlowdownAmount; public float WalkSpeedModifier = 1f;
/// <summary> /// <summary>
/// Multiplier for a mob's walking speed /// Multiplier for a mob's sprinting speed
/// </summary> /// </summary>
[DataField] [DataField]
public float WalkSpeedModifier = 1f; public float SprintSpeedModifier = 1f;
/// <summary> /// <summary>
/// Multiplier for a mob's sprinting speed /// Refresh Stun or Slowdown on hit
/// </summary> /// </summary>
[DataField] [DataField]
public float SprintSpeedModifier = 1f; public bool Refresh = true;
/// <summary> /// <summary>
/// Refresh Stun or Slowdown on hit /// Should the entity try and stand automatically after being knocked down?
/// </summary> /// </summary>
[DataField] [DataField]
public bool Refresh = true; public bool AutoStand = true;
/// <summary> /// <summary>
/// Should the entity try and stand automatically after being knocked down? /// Should the entity drop their items upon first being knocked down?
/// </summary> /// </summary>
[DataField] [DataField]
public bool AutoStand = true; public bool Drop = true;
/// <summary> /// <summary>
/// Fixture we track for the collision. /// Fixture we track for the collision.
/// </summary> /// </summary>
[DataField("fixture")] public string FixtureID = "projectile"; [DataField("fixture")] public string FixtureID = "projectile";
}
} }

View File

@@ -4,47 +4,60 @@ using JetBrains.Annotations;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Robust.Shared.Physics.Events; using Robust.Shared.Physics.Events;
namespace Content.Server.Stunnable namespace Content.Server.Stunnable.Systems;
[UsedImplicitly]
internal sealed class StunOnCollideSystem : EntitySystem
{ {
[UsedImplicitly] [Dependency] private readonly StunSystem _stunSystem = default!;
internal sealed class StunOnCollideSystem : EntitySystem [Dependency] private readonly MovementModStatusSystem _movementMod = default!;
public override void Initialize()
{ {
[Dependency] private readonly StunSystem _stunSystem = default!; base.Initialize();
[Dependency] private readonly MovementModStatusSystem _movementMod = default!;
public override void Initialize() SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide);
SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow);
}
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)
{ {
base.Initialize(); _stunSystem.TryUpdateStunDuration(target, ent.Comp.StunAmount);
SubscribeLocalEvent<StunOnCollideComponent, StartCollideEvent>(HandleCollide);
SubscribeLocalEvent<StunOnCollideComponent, ThrowDoHitEvent>(HandleThrow);
}
private void TryDoCollideStun(EntityUid uid, StunOnCollideComponent component, EntityUid target)
{
_stunSystem.TryUpdateStunDuration(target, component.StunAmount);
_stunSystem.TryKnockdown(target, component.KnockdownAmount, component.Refresh, component.AutoStand, force: true);
_movementMod.TryUpdateMovementSpeedModDuration( _movementMod.TryUpdateMovementSpeedModDuration(
target, target,
MovementModStatusSystem.TaserSlowdown, MovementModStatusSystem.TaserSlowdown,
component.SlowdownAmount, ent.Comp.SlowdownAmount,
component.WalkSpeedModifier, ent.Comp.WalkSpeedModifier,
component.SprintSpeedModifier ent.Comp.SprintSpeedModifier
); );
} }
else
private void HandleCollide(EntityUid uid, StunOnCollideComponent component, ref StartCollideEvent args)
{ {
if (args.OurFixtureId != component.FixtureID) _stunSystem.TryAddStunDuration(target, ent.Comp.StunAmount);
return; _movementMod.TryAddMovementSpeedModDuration(
target,
TryDoCollideStun(uid, component, args.OtherEntity); MovementModStatusSystem.TaserSlowdown,
} ent.Comp.SlowdownAmount,
ent.Comp.WalkSpeedModifier,
private void HandleThrow(EntityUid uid, StunOnCollideComponent component, ThrowDoHitEvent args) ent.Comp.SprintSpeedModifier
{ );
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);
}
} }

View File

@@ -149,7 +149,8 @@ public sealed class SlipperySystem : EntitySystem
_audio.PlayPredicted(component.SlipSound, other, other); _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}"); _adminLogger.Add(LogType.Slip, LogImpact.Low, $"{ToPrettyString(other):mob} slipped on collision with {ToPrettyString(uid):entity}");
} }

View File

@@ -15,23 +15,10 @@ namespace Content.Shared.Standing
public bool Standing { get; set; } = true; public bool Standing { get; set; } = true;
/// <summary> /// <summary>
/// Time it takes us to stand up /// Friction modifier applied to an entity in the downed state.
/// </summary> /// </summary>
[DataField, AutoNetworkedField] [DataField, AutoNetworkedField]
public TimeSpan StandTime = TimeSpan.FromSeconds(2); public float DownFrictionMod = 0.4f;
/// <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;
/// <summary> /// <summary>
/// List of fixtures that had their collision mask changed when the entity was downed. /// List of fixtures that had their collision mask changed when the entity was downed.

View File

@@ -23,7 +23,6 @@ public sealed class StandingStateSystem : EntitySystem
base.Initialize(); base.Initialize();
SubscribeLocalEvent<StandingStateComponent, AttemptMobCollideEvent>(OnMobCollide); SubscribeLocalEvent<StandingStateComponent, AttemptMobCollideEvent>(OnMobCollide);
SubscribeLocalEvent<StandingStateComponent, AttemptMobTargetCollideEvent>(OnMobTargetCollide); SubscribeLocalEvent<StandingStateComponent, AttemptMobTargetCollideEvent>(OnMobTargetCollide);
SubscribeLocalEvent<StandingStateComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
SubscribeLocalEvent<StandingStateComponent, RefreshFrictionModifiersEvent>(OnRefreshFrictionModifiers); SubscribeLocalEvent<StandingStateComponent, RefreshFrictionModifiersEvent>(OnRefreshFrictionModifiers);
SubscribeLocalEvent<StandingStateComponent, TileFrictionEvent>(OnTileFriction); 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) private void OnRefreshFrictionModifiers(Entity<StandingStateComponent> entity, ref RefreshFrictionModifiersEvent args)
{ {
if (entity.Comp.Standing) if (entity.Comp.Standing)
return; return;
args.ModifyFriction(entity.Comp.FrictionModifier); args.ModifyFriction(entity.Comp.DownFrictionMod);
args.ModifyAcceleration(entity.Comp.FrictionModifier); args.ModifyAcceleration(entity.Comp.DownFrictionMod);
} }
private void OnTileFriction(Entity<StandingStateComponent> entity, ref TileFrictionEvent args) private void OnTileFriction(Entity<StandingStateComponent> entity, ref TileFrictionEvent args)
{ {
if (!entity.Comp.Standing) if (!entity.Comp.Standing)
args.Modifier *= entity.Comp.FrictionModifier; args.Modifier *= entity.Comp.DownFrictionMod;
} }
public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null) public bool IsDown(EntityUid uid, StandingStateComponent? standingState = null)

View File

@@ -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;
}

View File

@@ -6,4 +6,22 @@ namespace Content.Shared.Stunnable;
/// Knockdown as a status effect. /// Knockdown as a status effect.
/// </summary> /// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(SharedStunSystem))] [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;
}

View File

@@ -25,13 +25,7 @@ namespace Content.Shared.Stunnable;
/// </summary> /// </summary>
public abstract partial class SharedStunSystem 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... private EntityQuery<CrawlerComponent> _crawlerQuery;
// 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;
[Dependency] private readonly EntityLookupSystem _entityLookup = default!; [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
[Dependency] private readonly SharedHandsSystem _hands = default!; [Dependency] private readonly SharedHandsSystem _hands = default!;
@@ -43,6 +37,8 @@ public abstract partial class SharedStunSystem
private void InitializeKnockdown() private void InitializeKnockdown()
{ {
_crawlerQuery = GetEntityQuery<CrawlerComponent>();
SubscribeLocalEvent<KnockedDownComponent, RejuvenateEvent>(OnRejuvenate); SubscribeLocalEvent<KnockedDownComponent, RejuvenateEvent>(OnRejuvenate);
// Startup and Shutdown // Startup and Shutdown
@@ -61,8 +57,9 @@ public abstract partial class SharedStunSystem
// DoAfter event subscriptions // DoAfter event subscriptions
SubscribeLocalEvent<KnockedDownComponent, TryStandDoAfterEvent>(OnStandDoAfter); SubscribeLocalEvent<KnockedDownComponent, TryStandDoAfterEvent>(OnStandDoAfter);
// Knockdown Extenders // Crawling
SubscribeLocalEvent<KnockedDownComponent, DamageChangedEvent>(OnDamaged); SubscribeLocalEvent<CrawlerComponent, KnockedDownRefreshEvent>(OnKnockdownRefresh);
SubscribeLocalEvent<CrawlerComponent, DamageChangedEvent>(OnDamaged);
// Handling Alternative Inputs // Handling Alternative Inputs
SubscribeAllEvent<ForceStandUpEvent>(OnForceStandup); SubscribeAllEvent<ForceStandUpEvent>(OnForceStandup);
@@ -81,6 +78,7 @@ public abstract partial class SharedStunSystem
while (query.MoveNext(out var uid, out var knockedDown)) 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) if (!knockedDown.AutoStand || knockedDown.DoAfterId.HasValue || knockedDown.NextUpdate > GameTiming.CurTime)
continue; continue;
@@ -157,7 +155,7 @@ public abstract partial class SharedStunSystem
/// <param name="entity">Entity who's knockdown time we're updating.</param> /// <param name="entity">Entity who's knockdown time we're updating.</param>
/// <param name="time">The time we're updating with.</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> /// <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) if (refresh)
RefreshKnockdownTime(entity, time); RefreshKnockdownTime(entity, time);
@@ -174,6 +172,7 @@ public abstract partial class SharedStunSystem
{ {
entity.Comp.NextUpdate = time; entity.Comp.NextUpdate = time;
DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate)); DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate));
Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, entity.Comp.NextUpdate));
} }
/// <summary> /// <summary>
@@ -182,11 +181,14 @@ public abstract partial class SharedStunSystem
/// </summary> /// </summary>
/// <param name="entity">Entity whose timer we're updating</param> /// <param name="entity">Entity whose timer we're updating</param>
/// <param name="time">The time we want them to be knocked down for.</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; var knockedTime = GameTiming.CurTime + time;
if (entity.Comp.NextUpdate < knockedTime) if (entity.Comp.NextUpdate < knockedTime)
SetKnockdownTime(entity, knockedTime); SetKnockdownTime((entity, entity.Comp), knockedTime);
} }
/// <summary> /// <summary>
@@ -194,35 +196,20 @@ public abstract partial class SharedStunSystem
/// </summary> /// </summary>
/// <param name="entity">Entity whose timer we're updating</param> /// <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> /// <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) if (entity.Comp.NextUpdate < GameTiming.CurTime)
{ {
SetKnockdownTime(entity, GameTiming.CurTime + time); SetKnockdownTime((entity, entity.Comp), GameTiming.CurTime + time);
return; return;
} }
entity.Comp.NextUpdate += time; entity.Comp.NextUpdate += time;
DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate)); DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate));
} Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, entity.Comp.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;
} }
#endregion #endregion
@@ -237,29 +224,55 @@ public abstract partial class SharedStunSystem
if (playerSession.AttachedEntity is not { Valid: true } playerEnt || !Exists(playerEnt)) if (playerSession.AttachedEntity is not { Valid: true } playerEnt || !Exists(playerEnt))
return; 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; return;
} }
var stand = !component.DoAfterId.HasValue; var stand = !entity.Comp2.DoAfterId.HasValue;
SetAutoStand(playerEnt, stand); SetAutoStand((entity, entity.Comp2), stand);
if (!stand || !TryStanding(playerEnt)) if (!stand || !TryStanding((entity, entity.Comp2)))
CancelKnockdownDoAfter((playerEnt, component)); 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 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; return true;
if (!TryStand((entity.Owner, entity.Comp1))) if (!KnockdownOver((entity, entity.Comp)))
return false; return false;
var ev = new GetStandUpTimeEvent(entity.Comp2.StandTime); 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, entity.Comp)))
return false;
var ev = new GetStandUpTimeEvent(crawler.StandTime);
RaiseLocalEvent(entity, ref ev); RaiseLocalEvent(entity, ref ev);
var doAfterArgs = new DoAfterArgs(EntityManager, entity, ev.DoAfterTime, new TryStandDoAfterEvent(), entity, entity) 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)) if (!DoAfter.TryStartDoAfter(doAfterArgs, out var doAfterId))
return false; return false;
entity.Comp1.DoAfterId = doAfterId.Value.Index; entity.Comp.DoAfterId = doAfterId.Value.Index;
DirtyField(entity, entity.Comp1, nameof(KnockedDownComponent.DoAfterId)); DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.DoAfterId));
return true; return true;
} }
public bool KnockdownOver(Entity<KnockedDownComponent> entity)
{
if (entity.Comp.NextUpdate > GameTiming.CurTime)
return false;
return Blocker.CanMove(entity);
}
/// <summary> /// <summary>
/// A variant of <see cref="CanStand"/> used when we're actually trying to stand. /// 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. /// 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> /// <returns>Returns whether the entity is able to stand</returns>
public bool TryStand(Entity<KnockedDownComponent> entity) public bool TryStand(Entity<KnockedDownComponent> entity)
{ {
if (entity.Comp.NextUpdate > GameTiming.CurTime) if (!KnockdownOver(entity))
return false;
if (!Blocker.CanMove(entity))
return false; return false;
var ev = new StandUpAttemptEvent(entity.Comp.AutoStand); var ev = new StandUpAttemptEvent(entity.Comp.AutoStand);
@@ -308,6 +326,22 @@ public abstract partial class SharedStunSystem
return !ev.Cancelled; 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) private bool StandingBlocked(Entity<KnockedDownComponent> entity)
{ {
if (!TryStand(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 // That way if we fail to stand, the game will try to stand for us when we are able to
SetAutoStand(entity, true); SetAutoStand(entity, true);
if (!HasComp<StandingStateComponent>(entity) || StandingBlocked((entity, entity.Comp))) if (StandingBlocked((entity, entity.Comp)))
return; return;
if (!_hands.TryGetEmptyHand(entity.Owner, out _)) if (!_hands.TryGetEmptyHand(entity.Owner, out _))
@@ -436,16 +470,22 @@ public abstract partial class SharedStunSystem
#endregion #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 // 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) if (!args.InterruptsDoAfters || !args.DamageIncreased || args.DamageDelta == null || GameTiming.ApplyingState)
return; return;
if (args.DamageDelta.GetTotal() >= KnockdownDamageThreshold) // TODO: Unhardcode this if (args.DamageDelta.GetTotal() >= entity.Comp.KnockdownDamageThreshold)
SetKnockdownTime(entity, GameTiming.CurTime + DefaultKnockedDuration); 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 #endregion

View File

@@ -26,7 +26,6 @@ namespace Content.Shared.Stunnable;
public abstract partial class SharedStunSystem : EntitySystem public abstract partial class SharedStunSystem : EntitySystem
{ {
public static readonly EntProtoId StunId = "StatusEffectStunned"; public static readonly EntProtoId StunId = "StatusEffectStunned";
public static readonly EntProtoId KnockdownId = "StatusEffectKnockdown";
[Dependency] protected readonly IGameTiming GameTiming = default!; [Dependency] protected readonly IGameTiming GameTiming = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
@@ -61,10 +60,11 @@ public abstract partial class SharedStunSystem : EntitySystem
SubscribeLocalEvent<MobStateComponent, MobStateChangedEvent>(OnMobStateChanged); SubscribeLocalEvent<MobStateComponent, MobStateChangedEvent>(OnMobStateChanged);
// New Status Effect subscriptions // New Status Effect subscriptions
SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectAppliedEvent>(OnStunEffectApplied); SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectAppliedEvent>(OnStunStatusApplied);
SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRemovedEvent>(OnStunStatusRemoved); SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRemovedEvent>(OnStunStatusRemoved);
SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRelayedEvent<StunEndAttemptEvent>>(OnStunEndAttempt); SubscribeLocalEvent<StunnedStatusEffectComponent, StatusEffectRelayedEvent<StunEndAttemptEvent>>(OnStunEndAttempt);
SubscribeLocalEvent<KnockdownStatusEffectComponent, StatusEffectAppliedEvent>(OnKnockdownStatusApplied);
SubscribeLocalEvent<KnockdownStatusEffectComponent, StatusEffectRelayedEvent<StandUpAttemptEvent>>(OnStandUpAttempt); SubscribeLocalEvent<KnockdownStatusEffectComponent, StatusEffectRelayedEvent<StandUpAttemptEvent>>(OnStandUpAttempt);
// Stun Appearance Data // Stun Appearance Data
@@ -123,7 +123,7 @@ public abstract partial class SharedStunSystem : EntitySystem
return; return;
TryUpdateStunDuration(args.OtherEntity, ent.Comp.Duration); 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...) // 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"); _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; return false;
TryKnockdown(uid, duration, true, force: true); return TryKnockdown(entity, time, refresh, autoStand, drop, force);
return true;
} }
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 false;
return TryKnockdown(uid, duration, true, force: true); return TryKnockdown(entity, entity.Comp.DefaultKnockedDuration, refresh, autoStand, drop, force);
} }
/// <summary> /// <summary>
/// Knocks down the entity, making it fall to the ground. /// Checks if we can knock down an entity to the ground...
/// </summary> /// </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) if (time <= TimeSpan.Zero)
return false; return false;
@@ -187,30 +212,53 @@ public abstract partial class SharedStunSystem : EntitySystem
if (!Resolve(entity, ref entity.Comp, false)) if (!Resolve(entity, ref entity.Comp, false))
return false; return false;
if (!force) var evAttempt = new KnockDownAttemptEvent(autoStand, drop, time);
{ RaiseLocalEvent(entity, ref evAttempt);
var evAttempt = new KnockDownAttemptEvent(autoStand, drop);
RaiseLocalEvent(entity, ref evAttempt);
if (evAttempt.Cancelled) autoStand = evAttempt.AutoStand;
return false; drop = evAttempt.Drop;
autoStand = evAttempt.AutoStand; return force || !evAttempt.Cancelled;
drop = evAttempt.Drop; }
}
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; 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 // 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)); RefreshKnockedMovement((uid, component));
CancelKnockdownDoAfter((entity, component)); CancelKnockdownDoAfter((uid, component));
} }
else else
{ {
@@ -218,41 +266,50 @@ public abstract partial class SharedStunSystem : EntitySystem
if (drop) if (drop)
{ {
var ev = new DropHandItemsEvent(); 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... // 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); var knockedEv = new KnockedDownEvent();
RaiseLocalEvent(entity, ref knockedEv); RaiseLocalEvent(uid, ref knockedEv);
if (time != null) if (time != null)
{ {
UpdateKnockdownTime((entity, component), time.Value, refresh); UpdateKnockdownTime((uid, component), time.Value, refresh);
_adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(entity):user} knocked down for {time.Value.Seconds} seconds"); _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(uid):user} was knocked down for {time.Value.Seconds} seconds");
} }
else else
_adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(entity):user} knocked down for an indefinite amount of time"); {
Alerts.ShowAlert(uid, KnockdownAlert);
Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, component.NextUpdate)); _adminLogger.Add(LogType.Stamina, LogImpact.Medium, $"{ToPrettyString(uid):user} was knocked down");
}
} }
public bool TryAddParalyzeDuration(EntityUid uid, TimeSpan duration) public bool TryAddParalyzeDuration(EntityUid uid, TimeSpan duration)
{ {
var knockdown = TryAddKnockdownDuration(uid, duration); if (!_status.TryAddStatusEffectDuration(uid, StunId, duration))
var stunned = TryAddStunDuration(uid, duration); return false;
return knockdown || stunned; // 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 true;
} }
public bool TryUpdateParalyzeDuration(EntityUid uid, TimeSpan? duration) public bool TryUpdateParalyzeDuration(EntityUid uid, TimeSpan? duration)
{ {
var knockdown = TryUpdateKnockdownDuration(uid, duration); if (!_status.TryUpdateStatusEffectDuration(uid, StunId, duration))
var stunned = TryUpdateStunDuration(uid, duration); return false;
return knockdown || stunned; // 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 true;
} }
public bool TryUnstun(Entity<StunnedComponent?> entity) public bool TryUnstun(Entity<StunnedComponent?> entity)
@@ -266,7 +323,7 @@ public abstract partial class SharedStunSystem : EntitySystem
return !ev.Cancelled && RemComp<StunnedComponent>(entity); 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) if (GameTiming.ApplyingState)
return; return;
@@ -289,6 +346,18 @@ public abstract partial class SharedStunSystem : EntitySystem
args.Args = ev; 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) private void OnStandUpAttempt(Entity<KnockdownStatusEffectComponent> entity, ref StatusEffectRelayedEvent<StandUpAttemptEvent> args)
{ {
if (args.Args.Cancelled) if (args.Args.Cancelled)

View File

@@ -26,7 +26,7 @@ public record struct StunEndAttemptEvent(bool Cancelled);
/// knocked down arguments. /// knocked down arguments.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]
public record struct KnockDownAttemptEvent(bool AutoStand, bool Drop) public record struct KnockDownAttemptEvent(bool AutoStand, bool Drop, TimeSpan? Time)
{ {
public bool Cancelled; 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. /// Raised directed on an entity when it is knocked down.
/// </summary> /// </summary>
[ByRefEvent] [ByRefEvent]
public record struct KnockedDownEvent(TimeSpan? Time); public record struct KnockedDownEvent;
/// <summary> /// <summary>
/// Raised on an entity that needs to refresh its knockdown modifiers /// Raised on an entity that needs to refresh its knockdown modifiers

View File

@@ -1433,6 +1433,7 @@
methods: [ Touch ] methods: [ Touch ]
effects: effects:
- !type:WashCreamPieReaction - !type:WashCreamPieReaction
- type: Crawler

View File

@@ -163,6 +163,7 @@
- type: SleepEmitSound - type: SleepEmitSound
- type: SSDIndicator - type: SSDIndicator
- type: StandingState - type: StandingState
- type: Crawler
- type: Dna - type: Dna
- type: MindContainer - type: MindContainer
showExamineInfo: true showExamineInfo: true

View File

@@ -58,10 +58,3 @@
- type: StatusEffectAlert - type: StatusEffectAlert
alert: Stun alert: Stun
- type: StunnedStatusEffect - type: StunnedStatusEffect
- type: entity
parent: MobStandStatusEffectBase
id: StatusEffectKnockdown
name: knocked down
components:
- type: KnockdownStatusEffect