// IW6 GSC SOURCE
// Generated by https://github.com/xensik/gsc-tool

shouldplayerbeaffectedbyemp()
{
    return !maps\mp\_utility::_hasperk( "specialty_empimmune" ) && maps\mp\_utility::isemped();
}

applyglobalempeffects()
{
    visionsetnaked( "coup_sunblind", 0.05 );
    wait 0.05;
    visionsetnaked( "coup_sunblind", 0 );
    visionsetnaked( "", 0.5 );
}

applyperplayerempeffects_ondetonate()
{
    self playlocalsound( "emp_activate" );
}

applyperplayerempeffects()
{
    self setempjammed( 1 );

    if ( maps\mp\_utility::_hasperk( "specialty_localjammer" ) )
        self clearscrambler();

    thread startempjamsequence();
}

removeperplayerempeffects()
{
    self setempjammed( 0 );

    if ( maps\mp\_utility::_hasperk( "specialty_localjammer" ) )
        self makescrambler();

    thread stopempjamsequence();
}

startempjamsequence()
{
    level endon( "game_ended" );
    self endon( "emp_stop_effect" );
    self endon( "disconnect" );
    self.bisplayingjameffects = 1;
    thread doempartifactloop();
    wait 1.0;
    self setclientomnvar( "ui_hud_static", 2 );
    wait 0.5;
    self notify( "emp_stop_artifact" );
    self setclientomnvar( "ui_hud_emp_artifact", 0 );

    for (;;)
    {
        self setclientomnvar( "ui_hud_static", 3 );
        var_0 = randomfloatrange( 0.25, 1.25 );
        wait( var_0 );
        self setclientomnvar( "ui_hud_static", 2 );
        wait 0.5;
    }
}

stopempjamsequence()
{
    level endon( "game_ended" );
    self notify( "emp_stop_effect" );
    self endon( "disconnect" );

    if ( isdefined( self.bisplayingjameffects ) )
    {
        self.bisplayingjameffects = undefined;
        self setclientomnvar( "ui_hud_static", 0 );

        for ( var_0 = 0; var_0 < 3; var_0++ )
        {
            self setclientomnvar( "ui_hud_emp_artifact", 1 );
            wait 0.5;
        }

        self setclientomnvar( "ui_hud_emp_artifact", 0 );
        self.player_static_value = 0;
    }
}

stopempjamsequenceimmediate()
{
    self notify( "emp_stop_effect" );

    if ( isdefined( self.bisplayingjameffects ) || isdefined( self.player_static_value ) )
    {
        self.bisplayingjameffects = undefined;
        self.player_static_value = 0;
        self setclientomnvar( "ui_hud_static", 0 );
        self setclientomnvar( "ui_hud_emp_artifact", 0 );
    }
}

doempartifactloop()
{
    self notify( "emp_stop_artifact" );
    level endon( "game_ended" );
    self endon( "emp_stop_effect" );
    self endon( "emp_stop_artifact" );
    self endon( "disconnect" );
    self endon( "joined_spectators" );

    for (;;)
    {
        self setclientomnvar( "ui_hud_emp_artifact", 1 );
        var_0 = randomfloatrange( 0.375, 0.5 );
        wait( var_0 );
    }
}

doempstaticloop( var_0 )
{
    self notify( "emp_stop_static" );
    level endon( "game_ended" );
    self endon( "emp_stop_effect" );
    self endon( "emp_stop_static" );
    self endon( "disconnect" );
    self endon( "joined_spectators" );
    var_1 = 1.0;
    var_2 = 2.0;

    if ( var_0 == 2 )
    {
        var_1 = 0.5;
        var_2 = 0.75;
    }

    for (;;)
    {
        self setclientomnvar( "ui_hud_static", 2 );
        var_3 = randomfloatrange( var_1, var_2 );
        wait( var_3 );
    }
}

staticfieldinit()
{
    self.player_static_value = 0;
}

staticfieldsetstrength( var_0 )
{
    if ( self.player_static_value != var_0 && isalive( self ) && !maps\mp\_utility::isemped() )
    {
        self.player_static_value = var_0;

        switch ( var_0 )
        {
            case 0:
                stopempjamsequence();
                break;
            case 1:
                self.bisplayingjameffects = 1;
                self notify( "emp_stop_static" );
                thread doempartifactloop();
                thread doempstaticloop( 1 );
                break;
            case 2:
                self.bisplayingjameffects = 1;
                self notify( "emp_stop_static" );
                self notify( "emp_stop_artifact" );
                thread doempstaticloop( 2 );
                break;
        }
    }
}

staticfieldgetstrength()
{
    return self.player_static_value;
}
