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

144 lines
4.1 KiB
C#
Raw Normal View History

using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects;
using Content.Server.Utility;
using Content.Shared.Alert;
2021-01-09 12:17:13 +01:00
using Content.Shared.Audio;
2020-05-13 16:53:01 +02:00
using Content.Shared.GameObjects.Components.Mobs;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.Interfaces;
using Robust.Server.GameObjects;
2020-05-13 16:53:01 +02:00
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Players;
using Robust.Shared.Random;
using Robust.Shared.Timing;
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))]
public class StunnableComponent : SharedStunnableComponent, IDisarmedAct
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;
Dirty();
}
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 ServerAlertsComponent 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
{
Owner.SpawnTimer(250, () => status.ClearAlert(AlertType.Stun), StatusRemoveCancellation.Token);
2020-07-23 01:40:31 +02:00
LastStun = null;
2020-05-14 18:03:08 +02:00
}
}
2021-01-09 12:17:13 +01:00
protected override void OnInteractHand()
{
EntitySystem.Get<AudioSystem>()
.PlayFromEntity("/Audio/Effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.05f));
}
public override ComponentState GetComponentState(ICommonSession player)
2020-06-24 02:21:20 +02:00
{
2020-07-23 01:40:31 +02:00
return new StunnableComponentState(StunnedTimer, KnockdownTimer, SlowdownTimer, WalkModifierOverride,
2020-06-24 02:21:20 +02:00
RunModifierOverride);
}
bool IDisarmedAct.Disarmed(DisarmedActEventArgs eventArgs)
{
if (!IoCManager.Resolve<IRobustRandom>().Prob(eventArgs.PushProbability))
return false;
Paralyze(4f);
var source = eventArgs.Source;
EntitySystem.Get<AudioSystem>().PlayFromEntity("/Audio/Effects/thudswoosh.ogg", source,
AudioHelpers.WithVariation(0.025f));
2021-01-09 21:38:29 +01:00
source.PopupMessageOtherClients(Loc.GetString("{0} pushes {1}!", source.Name, eventArgs.Target.Name));
source.PopupMessageCursor(Loc.GetString("You push {0}!", eventArgs.Target.Name));
return true;
}
2020-05-13 16:53:01 +02:00
}
}