-- some custom debug options I implemented for testing the mod
--
--
-- by razab




local manageBody = require("ManageBodyShared/RasBodyModManageBodyIG")

local Regs = RasBodyModRegistries




local growthTable = {}

growthTable.Female = {}
growthTable.Female["RasPubicHair"] = { full = "RasBodyMod.FemalePubicNatural", int = "RasBodyMod.FemalePubicNatural_Int" }
growthTable.Female["RasArmpitHair"] = { full = "RasBodyMod.FemaleArmpit", int = "RasBodyMod.FemaleArmpit_Int" }
growthTable.Female["RasLegHair"] = { full = "RasBodyMod.FemaleLeg", int = "RasBodyMod.FemaleLeg_Int" }

growthTable.Male = {}
growthTable.Male["RasPubicHair"] = { full = "RasBodyMod.MalePubicNatural", int = "RasBodyMod.MalePubicNatural_Int" }
growthTable.Male["RasArmpitHair"] = { full = "RasBodyMod.MaleArmpit", int = "RasBodyMod.MaleArmpit_Int" }
growthTable.Male["RasLegHair"] = { full = "RasBodyMod.MaleLeg", int = "RasBodyMod.MaleLeg_Int" }
growthTable.Male["RasChestHair"] = { full = "RasBodyMod.MaleChest", int = "RasBodyMod.MaleChest_Int" }



-- when armpit hair should grow
local function onGrowArmpits(worldobjects, player)

    local data = player:getModData().RasBodyMod
    
    local gender = "Male"
    if player:isFemale() then
        gender = "Female"
    end
    
    if data["RasArmpitHair"] ~= growthTable[gender]["RasArmpitHair"]["full"] then -- only grow smth when body hair is not yet full
        if data["RasArmpitHair"] == growthTable[gender]["RasArmpitHair"]["int"] then
            data["RasArmpitHair"] = growthTable[gender]["RasArmpitHair"]["full"]
        else
            data["RasArmpitHair"] = growthTable[gender]["RasArmpitHair"]["int"]
        end
    end 
    data.DaysTilGrow.RasArmpitHair = 4 + ZombRand(2) -- reset counter

    local queue = {
        {functionName = "EquipBodyHair", args = {bodyLocation = Regs.ArmpitHair}}
    }
    manageBody.executeQueue(player, queue, true) -- parameter true means we update the in-game avatar after equipping the items
end


-- when chest hair should grow
local function onGrowChest(worldobjects, player)

    local data = player:getModData().RasBodyMod

    local gender = "Male"
    if player:isFemale() then
        gender = "Female"
    end

    if data["RasChestHair"] ~= growthTable[gender]["RasChestHair"]["full"] then -- only grow smth when body hair is not yet full
        if data["RasChestHair"] == growthTable[gender]["RasChestHair"]["int"] then
            data["RasChestHair"] = growthTable[gender]["RasChestHair"]["full"]
        else
            data["RasChestHair"] = growthTable[gender]["RasChestHair"]["int"]
        end
    end 
    data.DaysTilGrow.RasArmpitHair = 4 + ZombRand(2) -- reset counter

    local queue = {
        {functionName = "EquipBodyHair", args = {bodyLocation = Regs.ChestHair}}
    }
    manageBody.executeQueue(player, queue, true)
end



local function onGrowLegs(worldobjects, player)

    local data = player:getModData().RasBodyMod

    local gender = "Male"
    if player:isFemale() then
        gender = "Female"
    end

    if data["RasLegHair"] ~= growthTable[gender]["RasLegHair"]["full"] then -- only grow smth when body hair is not yet full
        if data["RasLegHair"] == growthTable[gender]["RasLegHair"]["int"] then
            data["RasLegHair"] = growthTable[gender]["RasLegHair"]["full"]
        else
            data["RasLegHair"] = growthTable[gender]["RasLegHair"]["int"]
        end
    end 
    data.DaysTilGrow.RasArmpitHair = 4 + ZombRand(2) -- reset counter


    local queue = {
        {functionName = "EquipBodyHair", args = {bodyLocation = Regs.LegHair}}
    }
    manageBody.executeQueue(player, queue, true)
end



-- when pubic hair should grow
local function onGrowPubic(worldobjects, player)

    local data = player:getModData().RasBodyMod

    local gender = "Male"
    if player:isFemale() then
        gender = "Female"
    end

    if gender == "Female" then
        if data["RasPubicHair"] ~= growthTable[gender]["RasPubicHair"]["full"] then -- only grow smth when body hair is not yet full
            if data["RasPubicHair"] == growthTable[gender]["RasPubicHair"]["int"] then
                data["RasPubicHair"] = growthTable[gender]["RasPubicHair"]["full"]
            else
                data["RasPubicHair"] = growthTable[gender]["RasPubicHair"]["int"]
            end
        end
    else
        if data["RasPubicHair"] ~= growthTable[gender]["RasPubicHair"]["full"] then -- only grow smth when body hair is not yet full
            if data["RasPubicHair"] == growthTable[gender]["RasPubicHair"]["int"] or data[loc] == "RasBodyMod.MalePubicStrip_Int" then -- men also have an "int" state for strips
                data["RasPubicHair"] = growthTable[gender]["RasPubicHair"]["full"]
            elseif data["RasPubicHair"] == "RasBodyMod.MalePubicStrip" then
                data["RasPubicHair"] = "RasBodyMod.MalePubicStrip_Int"
            else
                data["RasPubicHair"] = growthTable[gender]["RasPubicHair"]["int"]
            end 
        end
    end
 
    data.DaysTilGrow.RasArmpitHair = 4 + ZombRand(2) -- reset counter

    local queue = {
        {functionName = "EquipBodyHair", args = {bodyLocation = Regs.PubicHair}},
        {functionName = "ManageMalePrivatePart", args = {checkForExceptionalClothes = true}} -- when growing pubic hair, we may have to equip a differen male private model
    }
    manageBody.executeQueue(player, queue, true)

end



local function onAddBloodVest(worldobjects, player)

    local vest = player:getWornItem(ItemBodyLocation.TORSO_EXTRA_VEST_BULLET)

    if vest then
        sendClientCommand(player, "rasBodyMod", "addBloodVest", {})        
    end
end


local function onAddBloodSkin(worldobjects, player)

    local skin = player:getWornItem(Regs.Skin)

    if skin then
        sendClientCommand(player, "rasBodyMod", "addBloodSkin", {})        
    end
end


local function onAddBloodTorso(worldobjects, player)

    local skin = player:getWornItem(Regs.Skin)

    if skin then
        sendClientCommand(player, "rasBodyMod", "addBloodTorso", {})        
    end
end


-- add new options to the right click menu (just right click somewhere in the game world)
local vanilla_ISWorldObjectContextMenu_createMenu = ISWorldObjectContextMenu.createMenu
function ISWorldObjectContextMenu.createMenu(player, worldobjects, x, y, test, ...)

    local context = vanilla_ISWorldObjectContextMenu_createMenu(player, worldobjects, x, y, test, ...) -- execute vanilla code
    if test == true then return true; end

    if isDebugEnabled() then
       
        local playerObj = getSpecificPlayer(player)

        context:addOption("RasBodyMod_GrowArmpits", worldobjects, onGrowArmpits, playerObj)
        if not playerObj:isFemale() then
         context:addOption("RasBodyMod_GrowChest", worldobjects, onGrowChest, playerObj)
        end
        context:addOption("RasBodyMod_GrowPubic", worldobjects, onGrowPubic, playerObj)
        context:addOption("RasBodyMod_GrowLegs", worldobjects, onGrowLegs, playerObj)

        context:addOption("RasBodyMod_AddBloodToVest", worldobjects, onAddBloodVest, playerObj)
        context:addOption("RasBodyMod_AddBloodToSkin", worldobjects, onAddBloodSkin, playerObj) 
        context:addOption("RasBodyMod_AddBloodToTorso", worldobjects, onAddBloodTorso, playerObj) 
    end

    return context
end





