2021-10-10 12:47:26 +02:00
using System ;
using Content.Server.Act ;
2021-11-24 16:52:31 -06:00
using Content.Server.Administration.Logs ;
2021-10-10 12:47:26 +02:00
using Content.Server.Popups ;
2021-11-24 16:52:31 -06:00
using Content.Shared.Administration.Logs ;
2021-10-10 12:47:26 +02:00
using Content.Shared.Audio ;
2021-11-28 14:56:53 +01:00
using Content.Shared.Database ;
2021-10-10 12:47:26 +02:00
using Content.Shared.Popups ;
2021-10-15 14:45:04 -07:00
using Content.Shared.StatusEffect ;
2021-10-10 12:47:26 +02:00
using Content.Shared.Stunnable ;
using Robust.Shared.Audio ;
using Robust.Shared.GameObjects ;
using Robust.Shared.IoC ;
using Robust.Shared.Localization ;
using Robust.Shared.Player ;
using Robust.Shared.Random ;
namespace Content.Server.Stunnable
{
public sealed class StunSystem : SharedStunSystem
{
[Dependency] private readonly IRobustRandom _random = default ! ;
2021-11-24 16:52:31 -06:00
[Dependency] private readonly AdminLogSystem _adminLogSystem = default ! ;
2021-10-10 12:47:26 +02:00
public override void Initialize ( )
{
base . Initialize ( ) ;
2022-02-26 18:24:08 +13:00
SubscribeLocalEvent < StatusEffectsComponent , DisarmedEvent > ( OnDisarmed ) ;
2021-10-10 12:47:26 +02:00
}
2022-02-26 18:24:08 +13:00
private void OnDisarmed ( EntityUid uid , StatusEffectsComponent status , DisarmedEvent args )
2021-10-10 12:47:26 +02:00
{
if ( args . Handled | | ! _random . Prob ( args . PushProbability ) )
return ;
2021-12-07 09:18:07 +03:00
if ( ! TryParalyze ( uid , TimeSpan . FromSeconds ( 4f ) , true , status ) )
2021-10-15 14:45:04 -07:00
return ;
2021-10-10 12:47:26 +02:00
var source = args . Source ;
var target = args . Target ;
2021-12-26 15:32:45 +13:00
var knock = EntityManager . GetComponent < KnockedDownComponent > ( uid ) ;
SoundSystem . Play ( Filter . Pvs ( source ) , knock . StunAttemptSound . GetSound ( ) , source , AudioHelpers . WithVariation ( 0.025f ) ) ;
// TODO: Use PopupSystem
source . PopupMessageOtherClients ( Loc . GetString ( "stunned-component-disarm-success-others" , ( "source" , Name ( source ) ) , ( "target" , Name ( target ) ) ) ) ;
source . PopupMessageCursor ( Loc . GetString ( "stunned-component-disarm-success" , ( "target" , Name ( target ) ) ) ) ;
2021-10-10 12:47:26 +02:00
2021-12-14 00:22:58 +13:00
_adminLogSystem . Add ( LogType . DisarmedKnockdown , LogImpact . Medium , $"{ToPrettyString(args.Source):user} knocked down {ToPrettyString(args.Target):target}" ) ;
2021-11-24 16:52:31 -06:00
2021-10-10 12:47:26 +02:00
args . Handled = true ;
}
}
}