--Huge credit to Spyjack for the original code and his original Insurgent concept in Facility-7

--Also huge credit to Azakaela and AuthenticPeach from code inspiration from their existing mods. 

--Also credit to Hayley, she smells.

require('NPCs/MainCreationMethods');
require('OptionScreens/CharacterCreationProfession');
require('XpSystem/XpUpdate');
require"ISUI/ISPanel"
require"ISUI/ISButton"
require"ISUI/ISInventoryPane"
require"ISUI/ISResizeWidget"
require"ISUI/ISMouseDrag"
require"defines"
require "Insurgent/ProfessionExclusiveTrait"

local function InsurgentBeginGame(player)
    if player:getDescriptor():getProfession() ~= "insurgent" then
        return
    end

    local inv = player:getInventory();
	
    local ration = 1;
    if player:HasTrait("LoadoutExtraRations") then	
        ration = 2;
    elseif	player:HasTrait("LoadoutNoRations") then	
        ration = 0;
    end	

    inv:AddItems("Insurgent.DeployedParachute", 1)
    inv:AddItems("Base.WaterBottleFull", 1)
    inv:AddItems("Base.OatsRaw", 2 * ration)
    inv:AddItems("Radio.WalkieTalkie5", 1)
    inv:AddItems("Base.HuntingKnife", 1)
    inv:AddItems("Base.Screwdriver", 1)
    inv:AddItems("Base.AlcoholBandage", 3)
    inv:AddItems("Base.AlcoholWipes", 1)
    inv:AddItems("Susceptible.GasmaskFilter", 2)
    inv:AddItems("Base.SlingA", 1)
    inv:AddItems("Base.KnifeSheath", 1)

    if player:HasTrait("Smoker") then
        inv:AddItems("Base.Lighter", 1)
        inv:AddItems("Base.Cigarettes", 1)
    end	

    -- Pistoleer gives the player a different pistol loadout
    if not player:HasTrait("LoadoutPistoleer") and not player:HasTrait("LoadoutGunslinger") and not player:HasTrait("LoadoutOSP") then
        InsurgentWeaponUtil.addBasicPistol(player)
    end

    local parachuteSound = "parachuteopening"
    if player:HasTrait("RoughLanding") then
        parachuteSound = player:isFemale() and "parachuteopeningroughfemale" or "parachuteopeningrough"
    end
    getSoundManager():PlaySound(parachuteSound, false, 5):setVolume(2.0)
end

local function RegisterEvents()
    for _, trait in pairs(InsurgentTraitDefinitions.traits) do
        if trait.RegisterEvents then
            trait:RegisterEvents()
        end
    end
end

Events.OnGameBoot.Add(RegisterEvents);
Events.OnNewGame.Add(InsurgentBeginGame);