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
-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";
}
+
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);
}
}
_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}");
}
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.
base.Initialize();
SubscribeLocalEvent<StandingStateComponent, AttemptMobCollideEvent>(OnMobCollide);
SubscribeLocalEvent<StandingStateComponent, AttemptMobTargetCollideEvent>(OnMobTargetCollide);
- SubscribeLocalEvent<StandingStateComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
SubscribeLocalEvent<StandingStateComponent, RefreshFrictionModifiersEvent>(OnRefreshFrictionModifiers);
SubscribeLocalEvent<StandingStateComponent, TileFrictionEvent>(OnTileFriction);
}
}
}
- 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)
--- /dev/null
+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;
+}
/// 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;
+}
/// </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!;
private void InitializeKnockdown()
{
+ _crawlerQuery = GetEntityQuery<CrawlerComponent>();
+
SubscribeLocalEvent<KnockedDownComponent, RejuvenateEvent>(OnRejuvenate);
// Startup and Shutdown
// 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);
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;
/// <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);
{
entity.Comp.NextUpdate = time;
DirtyField(entity, entity.Comp, nameof(KnockedDownComponent.NextUpdate));
+ Alerts.ShowAlert(entity, KnockdownAlert, null, (GameTiming.CurTime, entity.Comp.NextUpdate));
}
/// <summary>
/// </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>
/// </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
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)
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.
/// <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);
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))
// 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 _))
#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
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!;
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
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...)
_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;
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
{
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)
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;
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)
/// 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;
}
/// 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
methods: [ Touch ]
effects:
- !type:WashCreamPieReaction
+ - type: Crawler
- type: SleepEmitSound
- type: SSDIndicator
- type: StandingState
+ - type: Crawler
- type: Dna
- type: MindContainer
showExamineInfo: true
- type: StatusEffectAlert
alert: Stun
- type: StunnedStatusEffect
-
-- type: entity
- parent: MobStandStatusEffectBase
- id: StatusEffectKnockdown
- name: knocked down
- components:
- - type: KnockdownStatusEffect