StunnableComponent cleanup, proper prediction for stuns and slips. (#3552)

This commit is contained in:
Vera Aguilera Puerto
2021-03-08 05:00:50 +01:00
committed by GitHub
parent 0ad70d62ec
commit 6c77801d90
13 changed files with 243 additions and 226 deletions

View File

@@ -3,8 +3,10 @@ using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Client.GameObjects.Components.Clothing; using Content.Client.GameObjects.Components.Clothing;
using Content.Client.GameObjects.Components.Items;
using Content.Shared.GameObjects.Components.Inventory; using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Content.Shared.Preferences.Appearance; using Content.Shared.Preferences.Appearance;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -20,7 +22,7 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedInventoryComponent))] [ComponentReference(typeof(SharedInventoryComponent))]
public class ClientInventoryComponent : SharedInventoryComponent public class ClientInventoryComponent : SharedInventoryComponent, IEffectBlocker
{ {
private readonly Dictionary<Slots, IEntity> _slots = new(); private readonly Dictionary<Slots, IEntity> _slots = new();
@@ -286,5 +288,10 @@ namespace Content.Client.GameObjects.Components.HUD.Inventory
return false; return false;
} }
bool IEffectBlocker.CanSlip()
{
return !TryGetSlot(Slots.SHOES, out var shoes) || shoes == null || EffectBlockerSystem.CanSlip(shoes);
}
} }
} }

View File

@@ -14,11 +14,11 @@ namespace Content.Client.GameObjects.Components.Movement
if (curState is not SlipperyComponentState state) return; if (curState is not SlipperyComponentState state) return;
Slippery = state.Slippery; _slippery = state.Slippery;
IntersectPercentage = state.IntersectPercentage; _intersectPercentage = state.IntersectPercentage;
ParalyzeTime = state.ParalyzeTime; _paralyzeTime = state.ParalyzeTime;
RequiredSlipSpeed = state.RequiredSlipSpeed; _requiredSlipSpeed = state.RequiredSlipSpeed;
LaunchForwardsMultiplier = state.LaunchForwardsMultiplier; _launchForwardsMultiplier = state.LaunchForwardsMultiplier;
} }
} }
} }

View File

@@ -114,7 +114,6 @@ namespace Content.Client
"EmitSoundOnThrow", "EmitSoundOnThrow",
"Flash", "Flash",
"DamageOnToolInteract", "DamageOnToolInteract",
"NoSlip",
"TrashSpawner", "TrashSpawner",
"Pill", "Pill",
"RCD", "RCD",

View File

@@ -32,7 +32,7 @@ namespace Content.Server.GameObjects.Components.GUI
{ {
[RegisterComponent] [RegisterComponent]
[ComponentReference(typeof(SharedInventoryComponent))] [ComponentReference(typeof(SharedInventoryComponent))]
public class InventoryComponent : SharedInventoryComponent, IExAct, IEffectBlocker, IPressureProtection public class InventoryComponent : SharedInventoryComponent, IExAct, IPressureProtection, IEffectBlocker
{ {
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
@@ -145,14 +145,7 @@ namespace Content.Server.GameObjects.Components.GUI
bool IEffectBlocker.CanSlip() bool IEffectBlocker.CanSlip()
{ {
if (Owner.TryGetComponent(out InventoryComponent inventoryComponent) && return !TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes) || EffectBlockerSystem.CanSlip(shoes.Owner);
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes)
)
{
return EffectBlockerSystem.CanSlip(shoes.Owner);
}
return true;
} }
public override void OnRemove() public override void OnRemove()

View File

@@ -7,6 +7,8 @@ using Content.Shared.Audio;
using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Mobs.State; using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
@@ -29,17 +31,23 @@ namespace Content.Server.GameObjects.Components.Mobs
EntitySystem.Get<StandingStateSystem>().Down(Owner); EntitySystem.Get<StandingStateSystem>().Down(Owner);
} }
protected override void OnKnockdownEnd()
{
if(Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
}
public void CancelAll() public void CancelAll()
{ {
KnockdownTimer = 0f; KnockdownTimer = null;
StunnedTimer = 0f; StunnedTimer = null;
Dirty(); Dirty();
} }
public void ResetStuns() public void ResetStuns()
{ {
StunnedTimer = 0f; StunnedTimer = null;
SlowdownTimer = 0f; SlowdownTimer = null;
if (KnockedDown && if (KnockedDown &&
Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated()) Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
@@ -47,85 +55,16 @@ namespace Content.Server.GameObjects.Components.Mobs
EntitySystem.Get<StandingStateSystem>().Standing(Owner); EntitySystem.Get<StandingStateSystem>().Standing(Owner);
} }
KnockdownTimer = 0f; KnockdownTimer = null;
Dirty(); Dirty();
} }
public void Update(float delta)
{
if (Stunned)
{
StunnedTimer -= delta;
if (StunnedTimer <= 0)
{
StunnedTimer = 0f;
Dirty();
}
}
if (KnockedDown)
{
KnockdownTimer -= delta;
if (KnockdownTimer <= 0f
&& Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
{
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
KnockdownTimer = 0f;
Dirty();
}
}
if (SlowedDown)
{
SlowdownTimer -= delta;
if (SlowdownTimer <= 0f)
{
SlowdownTimer = 0f;
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement))
{
movement.RefreshMovementSpeedModifiers();
}
Dirty();
}
}
if (!StunStart.HasValue || !StunEnd.HasValue ||
!Owner.TryGetComponent(out ServerAlertsComponent? status))
{
return;
}
var start = StunStart.Value;
var end = StunEnd.Value;
var length = (end - start).TotalSeconds;
var progress = (_gameTiming.CurTime - start).TotalSeconds;
if (progress >= length)
{
Owner.SpawnTimer(250, () => status.ClearAlert(AlertType.Stun), StatusRemoveCancellation.Token);
LastStun = null;
}
}
protected override void OnInteractHand() protected override void OnInteractHand()
{ {
EntitySystem.Get<AudioSystem>() EntitySystem.Get<AudioSystem>()
.PlayFromEntity("/Audio/Effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.05f)); .PlayFromEntity("/Audio/Effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.05f));
} }
public override ComponentState GetComponentState(ICommonSession player)
{
return new StunnableComponentState(StunnedTimer, KnockdownTimer, SlowdownTimer, WalkModifierOverride,
RunModifierOverride);
}
bool IDisarmedAct.Disarmed(DisarmedActEventArgs eventArgs) bool IDisarmedAct.Disarmed(DisarmedActEventArgs eventArgs)
{ {
if (!IoCManager.Resolve<IRobustRandom>().Prob(eventArgs.PushProbability)) if (!IoCManager.Resolve<IRobustRandom>().Prob(eventArgs.PushProbability))

View File

@@ -12,81 +12,12 @@ namespace Content.Server.GameObjects.Components.Movement
[ComponentReference(typeof(SharedSlipperyComponent))] [ComponentReference(typeof(SharedSlipperyComponent))]
public class SlipperyComponent : SharedSlipperyComponent public class SlipperyComponent : SharedSlipperyComponent
{ {
private float _paralyzeTime = 2f;
private float _intersectPercentage = 0.3f;
private float _requiredSlipSpeed = 0f;
private bool _slippery;
private float _launchForwardsMultiplier = 1f;
/// <summary> /// <summary>
/// Path to the sound to be played when a mob slips. /// Path to the sound to be played when a mob slips.
/// </summary> /// </summary>
[ViewVariables] [ViewVariables]
[DataField("slipSound")] [DataField("slipSound")]
private string SlipSound { get; set; } = "/Audio/Effects/slip.ogg"; public string SlipSound { get; set; } = "/Audio/Effects/slip.ogg";
/// <summary>
/// How many seconds the mob will be paralyzed for.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float ParalyzeTime
{
get => _paralyzeTime;
set
{
_paralyzeTime = value;
Dirty();
}
}
/// <summary>
/// Percentage of shape intersection for a slip to occur.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float IntersectPercentage
{
get => _intersectPercentage;
set
{
_intersectPercentage = value;
Dirty();
}
}
/// <summary>
/// Entities will only be slipped if their speed exceeds this limit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override float RequiredSlipSpeed
{
get => _requiredSlipSpeed;
set
{
_requiredSlipSpeed = value;
Dirty();
}
}
/// <summary>
/// Whether or not this component will try to slip entities.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public override bool Slippery
{
get => _slippery;
set
{
_slippery = value;
Dirty();
}
}
[ViewVariables(VVAccess.ReadWrite)]
public override float LaunchForwardsMultiplier
{
get => _launchForwardsMultiplier;
set => _launchForwardsMultiplier = value;
}
protected override void OnSlip() protected override void OnSlip()
{ {
@@ -99,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Movement
public override ComponentState GetComponentState(ICommonSession player) public override ComponentState GetComponentState(ICommonSession player)
{ {
return new SlipperyComponentState(_paralyzeTime, _intersectPercentage, _requiredSlipSpeed, _launchForwardsMultiplier, _slippery); return new SlipperyComponentState(ParalyzeTime, IntersectPercentage, RequiredSlipSpeed, LaunchForwardsMultiplier, Slippery);
} }
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Reflection; using Robust.Shared.Reflection;

View File

@@ -1,12 +1,15 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using Content.Shared.Alert; using Content.Shared.Alert;
using Content.Shared.GameObjects.Components.Mobs.State;
using Content.Shared.GameObjects.Components.Movement; using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems.ActionBlocker; using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Players;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -22,17 +25,21 @@ namespace Content.Shared.GameObjects.Components.Mobs
public sealed override string Name => "Stunnable"; public sealed override string Name => "Stunnable";
public override uint? NetID => ContentNetIDs.STUNNABLE; public override uint? NetID => ContentNetIDs.STUNNABLE;
protected TimeSpan? LastStun; public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; protected set; }
public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; protected set; }
public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; protected set; }
[ViewVariables] protected TimeSpan? StunStart => LastStun; [ViewVariables] public float StunnedSeconds =>
StunnedTimer == null ? 0f : (float)(StunnedTimer.Value.End - StunnedTimer.Value.Start).TotalSeconds;
[ViewVariables] public float KnockdownSeconds =>
KnockdownTimer == null ? 0f : (float)(KnockdownTimer.Value.End - KnockdownTimer.Value.Start).TotalSeconds;
[ViewVariables] public float SlowdownSeconds =>
SlowdownTimer == null ? 0f : (float)(SlowdownTimer.Value.End - SlowdownTimer.Value.Start).TotalSeconds;
[ViewVariables] [ViewVariables] public bool AnyStunActive => Stunned || KnockedDown || SlowedDown;
protected TimeSpan? StunEnd => LastStun == null [ViewVariables] public bool Stunned => StunnedTimer != null;
? (TimeSpan?) null [ViewVariables] public bool KnockedDown => KnockdownTimer != null;
: _gameTiming.CurTime + [ViewVariables] public bool SlowedDown => SlowdownTimer != null;
(TimeSpan.FromSeconds(Math.Max(StunnedTimer, Math.Max(KnockdownTimer, SlowdownTimer))));
private bool _canHelp = true;
[DataField("stunCap")] [DataField("stunCap")]
protected float _stunCap = 20f; protected float _stunCap = 20f;
@@ -48,21 +55,15 @@ namespace Content.Shared.GameObjects.Components.Mobs
[DataField("helpInterval")] [DataField("helpInterval")]
private float _helpInterval = 1f; private float _helpInterval = 1f;
protected float StunnedTimer;
protected float KnockdownTimer;
protected float SlowdownTimer;
[DataField("stunAlertId")] private string _stunAlertId = "stun"; [DataField("stunAlertId")] private string _stunAlertId = "stun";
private bool _canHelp = true;
protected CancellationTokenSource StatusRemoveCancellation = new(); protected CancellationTokenSource StatusRemoveCancellation = new();
[ViewVariables] protected float WalkModifierOverride = 0f; [ViewVariables] protected float WalkModifierOverride = 0f;
[ViewVariables] protected float RunModifierOverride = 0f; [ViewVariables] protected float RunModifierOverride = 0f;
[ViewVariables] public bool Stunned => StunnedTimer > 0f;
[ViewVariables] public bool KnockedDown => KnockdownTimer > 0f;
[ViewVariables] public bool SlowedDown => SlowdownTimer > 0f;
private float StunTimeModifier private float StunTimeModifier
{ {
get get
@@ -118,15 +119,14 @@ namespace Content.Shared.GameObjects.Components.Mobs
/// <returns>Whether or not the owner was stunned.</returns> /// <returns>Whether or not the owner was stunned.</returns>
public bool Stun(float seconds) public bool Stun(float seconds)
{ {
seconds = MathF.Min(StunnedTimer + (seconds * StunTimeModifier), _stunCap); seconds = MathF.Min(StunnedSeconds + (seconds * StunTimeModifier), _stunCap);
if (seconds <= 0f) if (seconds <= 0f)
{ {
return false; return false;
} }
StunnedTimer = seconds; StunnedTimer = (_gameTiming.CurTime, _gameTiming.CurTime.Add(TimeSpan.FromSeconds(seconds)));
LastStun = _gameTiming.CurTime;
SetAlert(); SetAlert();
OnStun(); OnStun();
@@ -145,15 +145,14 @@ namespace Content.Shared.GameObjects.Components.Mobs
/// <returns>Whether or not the owner was knocked down.</returns> /// <returns>Whether or not the owner was knocked down.</returns>
public bool Knockdown(float seconds) public bool Knockdown(float seconds)
{ {
seconds = MathF.Min(KnockdownTimer + (seconds * KnockdownTimeModifier), _knockdownCap); seconds = MathF.Min(KnockdownSeconds + (seconds * KnockdownTimeModifier), _knockdownCap);
if (seconds <= 0f) if (seconds <= 0f)
{ {
return false; return false;
} }
KnockdownTimer = seconds; KnockdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime.Add(TimeSpan.FromSeconds(seconds)));;
LastStun = _gameTiming.CurTime;
SetAlert(); SetAlert();
OnKnockdown(); OnKnockdown();
@@ -183,7 +182,7 @@ namespace Content.Shared.GameObjects.Components.Mobs
/// <param name="runModifierOverride">Run speed modifier. Set to 0 or negative for default value. (0.5f)</param> /// <param name="runModifierOverride">Run speed modifier. Set to 0 or negative for default value. (0.5f)</param>
public void Slowdown(float seconds, float walkModifierOverride = 0f, float runModifierOverride = 0f) public void Slowdown(float seconds, float walkModifierOverride = 0f, float runModifierOverride = 0f)
{ {
seconds = MathF.Min(SlowdownTimer + (seconds * SlowdownTimeModifier), _slowdownCap); seconds = MathF.Min(SlowdownSeconds + (seconds * SlowdownTimeModifier), _slowdownCap);
if (seconds <= 0f) if (seconds <= 0f)
return; return;
@@ -191,8 +190,7 @@ namespace Content.Shared.GameObjects.Components.Mobs
WalkModifierOverride = walkModifierOverride; WalkModifierOverride = walkModifierOverride;
RunModifierOverride = runModifierOverride; RunModifierOverride = runModifierOverride;
SlowdownTimer = seconds; SlowdownTimer = (_gameTiming.CurTime, _gameTiming.CurTime.Add(TimeSpan.FromSeconds(seconds)));
LastStun = _gameTiming.CurTime;
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement)) if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement))
movement.RefreshMovementSpeedModifiers(); movement.RefreshMovementSpeedModifiers();
@@ -201,6 +199,44 @@ namespace Content.Shared.GameObjects.Components.Mobs
Dirty(); Dirty();
} }
private (TimeSpan, TimeSpan)? GetTimers()
{
// Don't do anything if no stuns are applied.
if (!AnyStunActive)
return null;
TimeSpan start = TimeSpan.MaxValue, end = TimeSpan.MinValue;
if (StunnedTimer != null)
{
if (StunnedTimer.Value.Start < start)
start = StunnedTimer.Value.Start;
if (StunnedTimer.Value.End > end)
end = StunnedTimer.Value.End;
}
if (KnockdownTimer != null)
{
if (KnockdownTimer.Value.Start < start)
start = KnockdownTimer.Value.Start;
if (KnockdownTimer.Value.End > end)
end = KnockdownTimer.Value.End;
}
if (SlowdownTimer != null)
{
if (SlowdownTimer.Value.Start < start)
start = SlowdownTimer.Value.Start;
if (SlowdownTimer.Value.End > end)
end = SlowdownTimer.Value.End;
}
return (start, end);
}
private void SetAlert() private void SetAlert()
{ {
if (!Owner.TryGetComponent(out SharedAlertsComponent? status)) if (!Owner.TryGetComponent(out SharedAlertsComponent? status))
@@ -208,8 +244,12 @@ namespace Content.Shared.GameObjects.Components.Mobs
return; return;
} }
status.ShowAlert(AlertType.Stun, cooldown: var timers = GetTimers();
(StunStart == null || StunEnd == null) ? default : (StunStart.Value, StunEnd.Value));
if (timers == null)
return;
status.ShowAlert(AlertType.Stun, cooldown:timers);
StatusRemoveCancellation.Cancel(); StatusRemoveCancellation.Cancel();
StatusRemoveCancellation = new CancellationTokenSource(); StatusRemoveCancellation = new CancellationTokenSource();
} }
@@ -226,7 +266,7 @@ namespace Content.Shared.GameObjects.Components.Mobs
_canHelp = false; _canHelp = false;
Owner.SpawnTimer((int) _helpInterval * 1000, () => _canHelp = true); Owner.SpawnTimer((int) _helpInterval * 1000, () => _canHelp = true);
KnockdownTimer -= _helpKnockdownRemove; KnockdownTimer = (KnockdownTimer!.Value.Start, KnockdownTimer.Value.End.Subtract(TimeSpan.FromSeconds(_helpInterval)));
OnInteractHand(); OnInteractHand();
@@ -236,6 +276,59 @@ namespace Content.Shared.GameObjects.Components.Mobs
return true; return true;
} }
public override ComponentState GetComponentState(ICommonSession player)
{
return new StunnableComponentState(StunnedTimer, KnockdownTimer, SlowdownTimer, WalkModifierOverride, RunModifierOverride);
}
protected virtual void OnKnockdownEnd()
{
}
public void Update(float delta)
{
var curTime = _gameTiming.CurTime;
if (StunnedTimer != null)
{
if (StunnedTimer.Value.End <= curTime)
{
StunnedTimer = null;
Dirty();
}
}
if (KnockdownTimer != null)
{
if (KnockdownTimer.Value.End <= curTime)
{
OnKnockdownEnd();
KnockdownTimer = null;
Dirty();
}
}
if (SlowdownTimer != null)
{
if (SlowdownTimer.Value.End <= curTime)
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? movement))
{
movement.RefreshMovementSpeedModifiers();
}
SlowdownTimer = null;
Dirty();
}
}
if (AnyStunActive || !Owner.TryGetComponent(out SharedAlertsComponent? status) || !status.IsShowingAlert(AlertType.Stun))
return;
status.ClearAlert(AlertType.Stun);
}
#region ActionBlockers #region ActionBlockers
public bool CanMove() => (!Stunned); public bool CanMove() => (!Stunned);
@@ -273,13 +366,15 @@ namespace Content.Shared.GameObjects.Components.Mobs
[Serializable, NetSerializable] [Serializable, NetSerializable]
protected sealed class StunnableComponentState : ComponentState protected sealed class StunnableComponentState : ComponentState
{ {
public float StunnedTimer { get; } public (TimeSpan Start, TimeSpan End)? StunnedTimer { get; }
public float KnockdownTimer { get; } public (TimeSpan Start, TimeSpan End)? KnockdownTimer { get; }
public float SlowdownTimer { get; } public (TimeSpan Start, TimeSpan End)? SlowdownTimer { get; }
public float WalkModifierOverride { get; } public float WalkModifierOverride { get; }
public float RunModifierOverride { get; } public float RunModifierOverride { get; }
public StunnableComponentState(float stunnedTimer, float knockdownTimer, float slowdownTimer, float walkModifierOverride, float runModifierOverride) : base(ContentNetIDs.STUNNABLE) public StunnableComponentState(
(TimeSpan Start, TimeSpan End)? stunnedTimer, (TimeSpan Start, TimeSpan End)? knockdownTimer,
(TimeSpan Start, TimeSpan End)? slowdownTimer, float walkModifierOverride, float runModifierOverride) : base(ContentNetIDs.STUNNABLE)
{ {
StunnedTimer = stunnedTimer; StunnedTimer = stunnedTimer;
KnockdownTimer = knockdownTimer; KnockdownTimer = knockdownTimer;

View File

@@ -1,7 +1,7 @@
using Content.Shared.GameObjects.EntitySystems.EffectBlocker; using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Movement namespace Content.Shared.GameObjects.Components.Movement
{ {
[RegisterComponent] [RegisterComponent]
public class NoSlipComponent : Component, IEffectBlocker public class NoSlipComponent : Component, IEffectBlocker

View File

@@ -7,6 +7,7 @@ using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
using Content.Shared.Physics; using Content.Shared.Physics;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Physics.Collision; using Robust.Shared.Physics.Collision;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -19,6 +20,12 @@ namespace Content.Shared.GameObjects.Components.Movement
{ {
public sealed override string Name => "Slippery"; public sealed override string Name => "Slippery";
protected float _paralyzeTime = 3f;
protected float _intersectPercentage = 0.3f;
protected float _requiredSlipSpeed = 0.1f;
protected float _launchForwardsMultiplier = 1f;
protected bool _slippery = true;
/// <summary> /// <summary>
/// The list of entities that have been slipped by this component, /// The list of entities that have been slipped by this component,
/// and which have not stopped colliding with its owner yet. /// and which have not stopped colliding with its owner yet.
@@ -30,35 +37,85 @@ namespace Content.Shared.GameObjects.Components.Movement
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("paralyzeTime")] [DataField("paralyzeTime")]
public virtual float ParalyzeTime { get; set; } = 3f; public float ParalyzeTime
{
get => _paralyzeTime;
set
{
if (MathHelper.CloseTo(_paralyzeTime, value)) return;
_paralyzeTime = value;
Dirty();
}
}
/// <summary> /// <summary>
/// Percentage of shape intersection for a slip to occur. /// Percentage of shape intersection for a slip to occur.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("intersectPercentage")] [DataField("intersectPercentage")]
public virtual float IntersectPercentage { get; set; } = 0.3f; public float IntersectPercentage
{
get => _intersectPercentage;
set
{
if (MathHelper.CloseTo(_intersectPercentage, value)) return;
_intersectPercentage = value;
Dirty();
}
}
/// <summary> /// <summary>
/// Entities will only be slipped if their speed exceeds this limit. /// Entities will only be slipped if their speed exceeds this limit.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("requiredSlipSpeed")] [DataField("requiredSlipSpeed")]
public virtual float RequiredSlipSpeed { get; set; } = 0.1f; public float RequiredSlipSpeed
{
get => _requiredSlipSpeed;
set
{
if (MathHelper.CloseTo(_requiredSlipSpeed, value)) return;
_requiredSlipSpeed = value;
Dirty();
}
}
/// <summary> /// <summary>
/// The entity's speed will be multiplied by this to slip it forwards. /// The entity's speed will be multiplied by this to slip it forwards.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("launchForwardsMultiplier")] [DataField("launchForwardsMultiplier")]
public virtual float LaunchForwardsMultiplier { get; set; } = 1f; public float LaunchForwardsMultiplier
{
get => _launchForwardsMultiplier;
set
{
if (MathHelper.CloseTo(_launchForwardsMultiplier, value)) return;
_launchForwardsMultiplier = value;
Dirty();
}
}
/// <summary> /// <summary>
/// Whether or not this component will try to slip entities. /// Whether or not this component will try to slip entities.
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
[DataField("slippery")] [DataField("slippery")]
public virtual bool Slippery { get; set; } = true; public bool Slippery
{
get => _slippery;
set
{
if (_slippery == value) return;
_slippery = value;
Dirty();
}
}
private bool TrySlip(IPhysBody ourBody, IPhysBody otherBody) private bool TrySlip(IPhysBody ourBody, IPhysBody otherBody)
{ {
@@ -106,6 +163,9 @@ namespace Content.Shared.GameObjects.Components.Movement
public void Update() public void Update()
{ {
if (!Slippery)
return;
foreach (var uid in _slipped.ToArray()) foreach (var uid in _slipped.ToArray())
{ {
if (!uid.IsValid() || !Owner.EntityManager.EntityExists(uid)) if (!uid.IsValid() || !Owner.EntityManager.EntityExists(uid))
@@ -124,23 +184,6 @@ namespace Content.Shared.GameObjects.Components.Movement
} }
} }
} }
public override void Initialize()
{
base.Initialize();
var physics = Owner.EnsureComponent<PhysicsComponent>();
physics.Hard = false;
var fixtures = physics.Fixtures.FirstOrDefault();
if (fixtures != null)
{
fixtures.CollisionLayer |= (int) CollisionGroup.SmallImpassable;
fixtures.CollisionMask = (int) CollisionGroup.None;
}
}
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -1,8 +1,8 @@
using Content.Server.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Mobs;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.EntitySystems namespace Content.Shared.GameObjects.EntitySystems
{ {
[UsedImplicitly] [UsedImplicitly]
internal sealed class StunSystem : EntitySystem internal sealed class StunSystem : EntitySystem
@@ -11,7 +11,7 @@ namespace Content.Server.GameObjects.EntitySystems
{ {
base.Update(frameTime); base.Update(frameTime);
foreach (var component in ComponentManager.EntityQuery<StunnableComponent>(true)) foreach (var component in ComponentManager.EntityQuery<SharedStunnableComponent>(true))
{ {
component.Update(frameTime); component.Update(frameTime);
} }

View File

@@ -106,12 +106,18 @@
- type: Slippery - type: Slippery
paralyzeTime: 2.5 paralyzeTime: 2.5
- type: Physics - type: Physics
bodyType: Dynamic
mass: 5
fixtures: fixtures:
- shape: - shape:
!type:PhysShapeAabb !type:PhysShapeAabb
bounds: "-0.3,-0.4,0.3,0.4" bounds: "-0.3,-0.4,0.3,0.4"
layer: layer:
- SmallImpassable
mask:
- SmallImpassable
- MobImpassable - MobImpassable
hard: false
- type: entity - type: entity
name: soap name: soap

View File

@@ -20,9 +20,12 @@
- shape: - shape:
!type:PhysShapeAabb !type:PhysShapeAabb
bounds: "-0.4,-0.4,0.4,0.4" bounds: "-0.4,-0.4,0.4,0.4"
hard: false
layer: layer:
- SmallImpassable
mask:
- SmallImpassable
- MobImpassable - MobImpassable
hard: false
- type: entity - type: entity
name: puddle name: puddle