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

init()
{
    level.juggsettings = [];
    level.juggsettings["juggernaut"] = spawnstruct();
    level.juggsettings["juggernaut"].splashusedname = "used_juggernaut";
    level.juggsettings["juggernaut_recon"] = spawnstruct();
    level.juggsettings["juggernaut_recon"].splashusedname = "used_juggernaut_recon";
    level.juggsettings["juggernaut_maniac"] = spawnstruct();
    level.juggsettings["juggernaut_maniac"].splashusedname = "used_juggernaut_maniac";
    level thread watchjugghostmigrationfinishedinit();
}

givejuggernaut( var_0 )
{
    self endon( "death" );
    self endon( "disconnect" );
    wait 0.05;

    if ( isdefined( self.lightarmorhp ) )
        maps\mp\perks\_perkfunctions::unsetlightarmor();

    maps\mp\gametypes\_weapons::disableplantedequipmentuse();

    if ( maps\mp\_utility::_hasperk( "specialty_explosivebullets" ) )
        maps\mp\_utility::_unsetperk( "specialty_explosivebullets" );

    self.health = self.maxhealth;
    var_1 = 1;

    switch ( var_0 )
    {
        case "juggernaut":
            self.isjuggernaut = 1;
            self.juggmovespeedscaler = 0.8;
            maps\mp\gametypes\_class::giveloadout( self.pers["team"], var_0, 0 );
            self.movespeedscaler = 0.8;
            maps\mp\_utility::giveperk( "specialty_scavenger", 0 );
            maps\mp\_utility::giveperk( "specialty_quickdraw", 0 );
            maps\mp\_utility::giveperk( "specialty_detectexplosive", 0 );
            maps\mp\_utility::giveperk( "specialty_sharp_focus", 0 );
            maps\mp\_utility::giveperk( "specialty_radarjuggernaut", 0 );
            break;
        case "juggernaut_recon":
            self.isjuggernautrecon = 1;
            self.juggmovespeedscaler = 0.8;
            maps\mp\gametypes\_class::giveloadout( self.pers["team"], var_0, 0 );
            self.movespeedscaler = 0.8;
            maps\mp\_utility::giveperk( "specialty_scavenger", 0 );
            maps\mp\_utility::giveperk( "specialty_coldblooded", 0 );
            maps\mp\_utility::giveperk( "specialty_noscopeoutline", 0 );
            maps\mp\_utility::giveperk( "specialty_detectexplosive", 0 );
            maps\mp\_utility::giveperk( "specialty_sharp_focus", 0 );
            maps\mp\_utility::giveperk( "specialty_radarjuggernaut", 0 );

            if ( !isagent( self ) )
            {
                self makeportableradar( self );
                maps\mp\gametypes\_missions::processchallenge( "ch_airdrop_juggernaut_recon" );
            }

            break;
        case "juggernaut_maniac":
            self.isjuggernautmaniac = 1;
            self.juggmovespeedscaler = 1.15;
            maps\mp\gametypes\_class::giveloadout( self.pers["team"], var_0, 0 );
            maps\mp\_utility::giveperk( "specialty_blindeye", 0 );
            maps\mp\_utility::giveperk( "specialty_coldblooded", 0 );
            maps\mp\_utility::giveperk( "specialty_noscopeoutline", 0 );
            maps\mp\_utility::giveperk( "specialty_detectexplosive", 0 );
            maps\mp\_utility::giveperk( "specialty_marathon", 0 );
            maps\mp\_utility::giveperk( "specialty_falldamage", 0 );
            self.movespeedscaler = 1.15;
            break;
        default:
            var_1 = self [[ level.mapcustomjuggfunc ]]( var_0 );
            break;
    }

    if ( perkcheck( "specialty_hardline" ) )
        maps\mp\_utility::giveperk( "specialty_hardline", 0 );

    maps\mp\gametypes\_weapons::updatemovespeedscale();
    self disableweaponpickup();

    if ( !isagent( self ) )
    {
        if ( var_1 )
        {
            self setclientomnvar( "ui_juggernaut", 1 );
            thread maps\mp\_utility::teamplayercardsplash( level.juggsettings[var_0].splashusedname, self );
            thread juggernautsounds();
            thread watchdisablejuggernaut();
            thread watchenablejuggernaut();
        }
    }

    if ( self.streaktype == "specialist" )
        thread maps\mp\killstreaks\_killstreaks::clearkillstreaks();
    else
        thread maps\mp\killstreaks\_killstreaks::updatekillstreaks( 1 );

    thread juggremover();

    if ( isdefined( self.carryflag ) )
    {
        wait 0.05;
        self attach( self.carryflag, "J_spine4", 1 );
    }

    level notify( "juggernaut_equipped", self );
    maps\mp\_matchdata::logkillstreakevent( var_0, self.origin );
}

perkcheck( var_0 )
{
    var_1 = self.pers["loadoutPerks"];

    foreach ( var_3 in var_1 )
    {
        if ( var_3 == var_0 )
            return 1;
    }

    return 0;
}

juggernautsounds()
{
    level endon( "game_ended" );
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "jugg_removed" );

    for (;;)
    {
        wait 3.0;
        maps\mp\_utility::playplayerandnpcsounds( self, "juggernaut_breathing_player", "juggernaut_breathing_sound" );
    }
}

watchjugghostmigrationfinishedinit()
{
    level endon( "game_ended" );

    for (;;)
    {
        level waittill( "host_migration_end" );

        foreach ( var_1 in level.players )
        {
            if ( isai( var_1 ) )
                continue;
            else
            {
                if ( var_1 maps\mp\_utility::isjuggernaut() && !( isdefined( var_1.isjuggernautlevelcustom ) && var_1.isjuggernautlevelcustom ) )
                {
                    var_1 setclientomnvar( "ui_juggernaut", 1 );
                    continue;
                }

                var_1 setclientomnvar( "ui_juggernaut", 0 );
            }
        }
    }
}

juggremover()
{
    level endon( "game_ended" );
    self endon( "disconnect" );
    self endon( "jugg_removed" );
    thread juggremoveongameended();
    common_scripts\utility::waittill_any( "death", "joined_team", "joined_spectators", "lost_juggernaut" );
    self enableweaponpickup();
    self.isjuggernaut = 0;
    self.isjuggernautdef = 0;
    self.isjuggernautgl = 0;
    self.isjuggernautrecon = 0;
    self.isjuggernautmaniac = 0;
    self.isjuggernautlevelcustom = 0;

    if ( isplayer( self ) )
        self setclientomnvar( "ui_juggernaut", 0 );

    self unsetperk( "specialty_radarjuggernaut", 1 );
    self notify( "jugg_removed" );
}

juggremoveongameended()
{
    self endon( "disconnect" );
    self endon( "jugg_removed" );
    level waittill( "game_ended" );

    if ( isplayer( self ) )
        self setclientomnvar( "ui_juggernaut", 0 );
}

setjugg()
{
    if ( isdefined( self.headmodel ) )
    {
        self detach( self.headmodel, "" );
        self.headmodel = undefined;
    }

    self setmodel( "mp_fullbody_juggernaut_heavy_black" );
    self setviewmodel( "viewhands_juggernaut_ally" );
    self setclothtype( "vestheavy" );
}

setjuggmaniac()
{
    if ( isdefined( self.headmodel ) )
    {
        self detach( self.headmodel, "" );
        self.headmodel = undefined;
    }

    self setmodel( "mp_body_juggernaut_light_black" );
    self setviewmodel( "viewhands_juggernaut_ally" );
    self attach( "head_juggernaut_light_black", "", 1 );
    self.headmodel = "head_juggernaut_light_black";
    self setclothtype( "nylon" );
}

disablejuggernaut()
{
    if ( maps\mp\_utility::isjuggernaut() )
    {
        self.juggernaut_disabled = 1;
        self setclientomnvar( "ui_juggernaut", 0 );
    }
}

enablejuggernaut()
{
    if ( maps\mp\_utility::isjuggernaut() )
    {
        self.juggernaut_disabled = undefined;
        self setclientomnvar( "ui_juggernaut", 1 );
    }
}

watchdisablejuggernaut()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "jugg_removed" );
    level endon( "game_ended" );

    for (;;)
    {
        if ( !isdefined( self.juggernaut_disabled ) && maps\mp\_utility::isusingremote() )
        {
            self waittill( "black_out_done" );
            disablejuggernaut();
        }

        wait 0.05;
    }
}

watchenablejuggernaut()
{
    self endon( "death" );
    self endon( "disconnect" );
    self endon( "jugg_removed" );
    level endon( "game_ended" );

    for (;;)
    {
        if ( isdefined( self.juggernaut_disabled ) && !maps\mp\_utility::isusingremote() )
            enablejuggernaut();

        wait 0.05;
    }
}

initlevelcustomjuggernaut( var_0, var_1, var_2, var_3 )
{
    level.mapcustomjuggfunc = var_0;
    level.mapcustomjuggsetclass = var_1;
    level.mapcustomjuggkilledsplash = var_3;
    game["allies_model"]["JUGGERNAUT_CUSTOM"] = var_2;
    game["axis_model"]["JUGGERNAUT_CUSTOM"] = var_2;
}
