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

116 lines
3.2 KiB
C#
Raw Normal View History

using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Chemistry;
2020-05-13 16:53:01 +02:00
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces.GameObjects.Components;
using NFluidsynth;
2020-05-13 16:53:01 +02:00
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
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;
using Logger = Robust.Shared.Log.Logger;
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
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
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
{
EntitySystem.Get<StandingStateSystem>().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
{
EntitySystem.Get<StandingStateSystem>().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
{
EntitySystem.Get<StandingStateSystem>().Standing(Owner);
2020-05-13 19:04:50 +02:00
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
}
}