Files
crystall-punk-14/Content.Server/GameObjects/Components/Mobs/StunnableComponent.cs

113 lines
2.9 KiB
C#
Raw Normal View History

2020-07-23 01:40:31 +02:00
using Content.Server.Mobs;
2020-05-13 16:53:01 +02:00
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
2020-05-13 16:53:01 +02:00
using Robust.Shared.GameObjects;
2020-05-14 17:26:08 +02:00
using Robust.Shared.Interfaces.Timing;
2020-05-13 16:53:01 +02:00
using Robust.Shared.IoC;
using Robust.Shared.Timers;
2020-05-13 16:53:01 +02:00
namespace Content.Server.GameObjects.Components.Mobs
{
[RegisterComponent]
2020-06-24 02:21:20 +02:00
[ComponentReference(typeof(SharedStunnableComponent))]
2020-07-23 01:40:31 +02:00
public class StunnableComponent : SharedStunnableComponent
2020-05-13 16:53:01 +02:00
{
2020-05-14 17:26:08 +02:00
#pragma warning disable 649
[Dependency] private IGameTiming _gameTiming;
#pragma warning restore 649
2020-05-13 16:53:01 +02:00
2020-07-23 01:40:31 +02:00
protected override void OnKnockdown()
2020-05-13 16:53:01 +02:00
{
2020-05-13 19:04:50 +02:00
StandingStateHelper.Down(Owner);
2020-05-13 22:35:23 +02:00
}
2020-05-13 19:04:50 +02:00
public void CancelAll()
2020-05-13 16:53:01 +02:00
{
2020-07-23 01:40:31 +02:00
KnockdownTimer = 0f;
StunnedTimer = 0f;
2020-06-24 02:21:20 +02:00
Dirty();
2020-06-12 16:22:36 +02:00
}
public void ResetStuns()
{
2020-07-23 01:40:31 +02:00
StunnedTimer = 0f;
SlowdownTimer = 0f;
if (KnockedDown)
2020-07-23 01:40:31 +02:00
{
StandingStateHelper.Standing(Owner);
2020-07-23 01:40:31 +02:00
}
2020-07-23 01:40:31 +02:00
KnockdownTimer = 0f;
}
2020-05-13 19:04:50 +02:00
public void Update(float delta)
2020-05-13 16:53:01 +02:00
{
2020-05-13 22:35:23 +02:00
if (Stunned)
{
2020-07-23 01:40:31 +02:00
StunnedTimer -= delta;
2020-05-13 22:35:23 +02:00
2020-07-23 01:40:31 +02:00
if (StunnedTimer <= 0)
2020-05-13 22:35:23 +02:00
{
2020-07-23 01:40:31 +02:00
StunnedTimer = 0f;
2020-06-24 02:21:20 +02:00
Dirty();
2020-05-13 22:35:23 +02:00
}
}
2020-05-13 22:13:22 +02:00
if (KnockedDown)
2020-05-13 19:04:50 +02:00
{
2020-07-23 01:40:31 +02:00
KnockdownTimer -= delta;
2020-05-13 19:04:50 +02:00
2020-07-23 01:40:31 +02:00
if (KnockdownTimer <= 0f)
2020-05-13 19:04:50 +02:00
{
StandingStateHelper.Standing(Owner);
2020-07-23 01:40:31 +02:00
KnockdownTimer = 0f;
2020-06-24 02:21:20 +02:00
Dirty();
2020-05-13 19:04:50 +02:00
}
}
2020-05-13 22:35:23 +02:00
if (SlowedDown)
2020-05-13 19:04:50 +02:00
{
2020-07-23 01:40:31 +02:00
SlowdownTimer -= delta;
2020-05-13 19:04:50 +02:00
2020-07-23 01:40:31 +02:00
if (SlowdownTimer <= 0f)
2020-05-13 19:04:50 +02:00
{
2020-07-23 01:40:31 +02:00
SlowdownTimer = 0f;
2020-05-13 22:35:23 +02:00
2020-06-24 02:21:20 +02:00
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
2020-07-23 01:40:31 +02:00
{
2020-05-13 22:35:23 +02:00
movement.RefreshMovementSpeedModifiers();
2020-07-23 01:40:31 +02:00
}
2020-06-24 02:21:20 +02:00
Dirty();
2020-05-13 19:04:50 +02:00
}
}
2020-05-14 17:26:08 +02:00
2020-06-24 02:21:20 +02:00
if (!StunStart.HasValue || !StunEnd.HasValue ||
!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
2020-07-23 01:40:31 +02:00
{
2020-05-14 17:26:08 +02:00
return;
2020-07-23 01:40:31 +02:00
}
2020-05-14 17:26:08 +02:00
2020-06-12 16:22:36 +02:00
var start = StunStart.Value;
2020-05-14 17:26:08 +02:00
var end = StunEnd.Value;
var length = (end - start).TotalSeconds;
var progress = (_gameTiming.CurTime - start).TotalSeconds;
2020-06-12 16:22:36 +02:00
if (progress >= length)
2020-05-14 17:26:08 +02:00
{
2020-07-23 01:40:31 +02:00
Timer.Spawn(250, () => status.RemoveStatusEffect(StatusEffect.Stun), StatusRemoveCancellation.Token);
LastStun = null;
2020-05-14 18:03:08 +02:00
}
}
2020-06-24 02:21:20 +02:00
public override ComponentState GetComponentState()
{
2020-07-23 01:40:31 +02:00
return new StunnableComponentState(StunnedTimer, KnockdownTimer, SlowdownTimer, WalkModifierOverride,
2020-06-24 02:21:20 +02:00
RunModifierOverride);
}
2020-05-13 16:53:01 +02:00
}
}