StunnableComponent cleanup, proper prediction for stuns and slips. (#3552)
This commit is contained in:
committed by
GitHub
parent
0ad70d62ec
commit
6c77801d90
@@ -32,7 +32,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedInventoryComponent))]
|
||||
public class InventoryComponent : SharedInventoryComponent, IExAct, IEffectBlocker, IPressureProtection
|
||||
public class InventoryComponent : SharedInventoryComponent, IExAct, IPressureProtection, IEffectBlocker
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
|
||||
@@ -145,14 +145,7 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
|
||||
bool IEffectBlocker.CanSlip()
|
||||
{
|
||||
if (Owner.TryGetComponent(out InventoryComponent inventoryComponent) &&
|
||||
inventoryComponent.TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes)
|
||||
)
|
||||
{
|
||||
return EffectBlockerSystem.CanSlip(shoes.Owner);
|
||||
}
|
||||
|
||||
return true;
|
||||
return !TryGetSlotItem(EquipmentSlotDefines.Slots.SHOES, out ItemComponent shoes) || EffectBlockerSystem.CanSlip(shoes.Owner);
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
|
||||
@@ -7,6 +7,8 @@ using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -29,17 +31,23 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
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()
|
||||
{
|
||||
KnockdownTimer = 0f;
|
||||
StunnedTimer = 0f;
|
||||
KnockdownTimer = null;
|
||||
StunnedTimer = null;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public void ResetStuns()
|
||||
{
|
||||
StunnedTimer = 0f;
|
||||
SlowdownTimer = 0f;
|
||||
StunnedTimer = null;
|
||||
SlowdownTimer = null;
|
||||
|
||||
if (KnockedDown &&
|
||||
Owner.TryGetComponent(out IMobStateComponent? mobState) && !mobState.IsIncapacitated())
|
||||
@@ -47,85 +55,16 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
|
||||
}
|
||||
|
||||
KnockdownTimer = 0f;
|
||||
KnockdownTimer = null;
|
||||
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()
|
||||
{
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.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)
|
||||
{
|
||||
if (!IoCManager.Resolve<IRobustRandom>().Prob(eventArgs.PushProbability))
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
using Content.Shared.GameObjects.EntitySystems.EffectBlocker;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Movement
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class NoSlipComponent : Component, IEffectBlocker
|
||||
{
|
||||
public override string Name => "NoSlip";
|
||||
|
||||
bool IEffectBlocker.CanSlip() => false;
|
||||
}
|
||||
}
|
||||
@@ -12,81 +12,12 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[ComponentReference(typeof(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>
|
||||
/// Path to the sound to be played when a mob slips.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("slipSound")]
|
||||
private 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;
|
||||
}
|
||||
public string SlipSound { get; set; } = "/Audio/Effects/slip.ogg";
|
||||
|
||||
protected override void OnSlip()
|
||||
{
|
||||
@@ -99,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new SlipperyComponentState(_paralyzeTime, _intersectPercentage, _requiredSlipSpeed, _launchForwardsMultiplier, _slippery);
|
||||
return new SlipperyComponentState(ParalyzeTime, IntersectPercentage, RequiredSlipSpeed, LaunchForwardsMultiplier, Slippery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user