----------------------------------------------------------------------------
----------------------------- KATTAJ1 - TTAJ1bl4 - WAYNE ---------------------------
----------------------------------------------------------------------------

require "Items/ProceduralDistributions"


function USMP_insertItemSetsIntoDistributions(itemSets, suffixes, spawnChances, distributionNames)
    local currentIndex = 1 

    for _, distributionName in ipairs(distributionNames) do
        local distribution = ProceduralDistributions.list[distributionName]

        for i, itemSet in ipairs(itemSets) do
            local baseItem = itemSet.baseItem
            local continuation = itemSet.continuation or ""

            for _, suffix in ipairs(suffixes) do
                local fullItem = "Base." .. baseItem .. suffix .. continuation

                local currentSpawnChance = spawnChances[currentIndex]
                currentIndex = (currentIndex % #spawnChances) + 1

                table.insert(distribution.items, fullItem)
                table.insert(distribution.items, currentSpawnChance)
            end
        end
    end
end



function USMP_initializeItemDistributionsSandboxOptions()

    -- Sandbox affected
    local spawnChancesCommon = {0.015}
    local spawnChancesCommonBackpack = {0.025}
    local spawnChancesUncommonBackpack = {0.0125}
    local spawnChancesRareBackpack = {0.0025}
    local spawnChancesUCP = {0.045}
    local spawnChancesOCP = {0.005}

    -- Non affected
    local emptySuffixes = {""} 
    

    local distributionNames = {"ArmySurplusOutfit", "LockerArmyBedroom", "ArmyStorageOutfit", "GunStoreCounter"} 
    local policePlusArmyDistributions = {"ArmySurplusOutfit", "LockerArmyBedroom", "ArmyStorageOutfit","PoliceStorageOutfit", "PoliceLockers", "PoliceStorageGuns", "GunStoreCounter"} 
    --local policeDistributions = {"PoliceStorageOutfit", "PoliceLockers", "PoliceStorageGuns"} 
    --local storesDistributions = {"ClothingStorageAllShirts", "ClothingStorageLegwear", "ClothingStoresJeans"}

    -- COMMON GEARS
    local itemSetsCommon = {
        -- Boots
        { baseItem = "USMP_Shoes_CombatBoots_TAN" },
        { baseItem = "USMP_Shoes_TacticalBoots_TAN"},

        -- Gloves
        { baseItem = "USMP_Gloves_Grips_TAN" },
        { baseItem = "USMP_Gloves_GripFingerless_TAN" },
    }
    USMP_insertItemSetsIntoDistributions(itemSetsCommon, emptySuffixes, spawnChancesCommon, policePlusArmyDistributions)

    -- COMMON BACKPACK
    local itemSetsCommonBackpack = {
        { baseItem = "USMP_Backpack_Strategist_Medium_UCP" },
    }
    USMP_insertItemSetsIntoDistributions(itemSetsCommonBackpack, emptySuffixes, spawnChancesCommonBackpack, policePlusArmyDistributions)

    -- UNCOMMON BACKPACK
    local itemSetsUncommonBackpack = {
        { baseItem = "USMP_Backpack_Echo_Radio_UCP" },
        { baseItem = "USMP_Backpack_Ranger_Large_UCP" },
    }
    USMP_insertItemSetsIntoDistributions(itemSetsUncommonBackpack, emptySuffixes, spawnChancesUncommonBackpack, policePlusArmyDistributions)

    -- RARE BACKPACK
    local itemSetsRareBackpack = {
        { baseItem = "USMP_Backpack_Colossus_VeryLarge_UCP" },
        { baseItem = "USMP_Backpack_Colossus_VeryLarge_OCP" },
    }
    USMP_insertItemSetsIntoDistributions(itemSetsRareBackpack, emptySuffixes, spawnChancesRareBackpack, policePlusArmyDistributions)

    -- UCP GEARS
    local itemSetsUCP = { 
    -- Helmets 
        { baseItem = "USMP_Helmet_PASGT_UCP" },

    -- Hats 
        { baseItem = "USMP_Hat_BaseballCapM_UCP" },
        
    -- Vests 
        { baseItem = "USMP_BulletproofVest_Medium_UCP" },
        { baseItem = "USMP_BulletproofVest_Patriot_Light_UCP" },

    -- Legs Protection Lower 
        { baseItem = "USMP_LegsProtectionLower_Patriot_Light_UCP" }, 

    -- Holster
        { baseItem = "USMP_Holster_Defender_UCP_BeltRight" },

    -- Jacket
        { baseItem = "USMP_Jacket_Classic_UCP" },
        { baseItem = "USMP_Jacket_Lightweight_UCP" }, 
        { baseItem = "USMP_Jacket_WinterHood_UCP_DOWN" },

    -- Bag Front
        { baseItem = "USMP_BagFront_ChestPouches_Medium_UCP" },
        { baseItem = "USMP_BagFront_ChestPouches_Large_UCP" },

    -- Bag Leg
        { baseItem = "USMP_BagLeg_MagSecure_Small_UCP_Right" },
        { baseItem = "USMP_BagLeg_Utility_Medium_UCP_Right" },

    -- Bag Back
        { baseItem = "USMP_BagBack_StormPack_Small_UCP" },
        { baseItem = "USMP_BagBack_StormPack_Medium_UCP" },

    -- Pants
        { baseItem = "USMP_Pants_Cargo_UCP" },

    } 
    USMP_insertItemSetsIntoDistributions(itemSetsUCP, emptySuffixes, spawnChancesUCP, policePlusArmyDistributions)

    -- OCP GEARS
    local itemSetsOCP = { 
    -- Helmets 
        { baseItem = "USMP_Helmet_Defender_OCP" },

    -- Hats 
        { baseItem = "USMP_Hat_BaseballCapM_OCP" },
        
    -- Vests 
        { baseItem = "USMP_BulletproofVest_Patriot_Light_OCP" },

    -- Legs Protection Lower 
        { baseItem = "USMP_LegsProtectionLower_Patriot_Light_OCP" }, 

    -- Holster
        { baseItem = "USMP_Holster_Defender_OCP_BeltRight" },

    -- Jacket
        { baseItem = "USMP_Jacket_Classic_OCP" },
        { baseItem = "USMP_Jacket_Lightweight_OCP" }, 
        { baseItem = "USMP_Jacket_WinterHood_OCP_DOWN" },

    -- Bag Front
        { baseItem = "USMP_BagFront_ChestPouches_Medium_OCP" },
        { baseItem = "USMP_BagFront_ChestPouches_Large_OCP" },

    -- Bag Leg
        { baseItem = "USMP_BagLeg_MagSecure_Small_OCP_Right" },
        { baseItem = "USMP_BagLeg_Utility_Medium_OCP_Right" },

    -- Bag Back
        { baseItem = "USMP_BagBack_StormPack_Small_OCP" },
        { baseItem = "USMP_BagBack_StormPack_Medium_OCP" },

    -- Pants
        { baseItem = "USMP_Pants_Cargo_OCP" },

    -- Bagpack
        { baseItem = "USMP_Backpack_Strategist_Medium_OCP" },
        { baseItem = "USMP_Backpack_Echo_Radio_OCP" },
        { baseItem = "USMP_Backpack_Ranger_Large_OCP" },

    } 
    USMP_insertItemSetsIntoDistributions(itemSetsOCP, emptySuffixes, spawnChancesOCP, policePlusArmyDistributions)

    ItemPickerJava.Parse()
end

Events.OnInitGlobalModData.Add(USMP_initializeItemDistributionsSandboxOptions)