require "DAMN_Parts";
require "DAMN_Spawns";

--***********************************************************
--**                   KI5 / bikinihorst                   **
--***********************************************************

DAMN.Parts:processConfigV2("CH76", {
	["BumperFront"] = {
		partId = "CH76BumperFront",
		itemToModel = {
			["Base.76chevyKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.93fordF350BullbarFrontD"] = {"FrontBullbarD1", "FrontBullbarD2"},
		},
		allowedForRandom = {
            "Base.76chevyKseriesBumperFront0", "Base.76chevyKseriesBullbarFrontA", "Base.76chevyKseriesBullbarFrontB"
        },
        default = "trve_random",
		noPartChance = 5,
	},
    ["BumperFrontW"] = {
		partId = "CH76BumperFront",
		itemToModel = {
			["Base.76chevyKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.76chevyCseriesBullbarFrontC"] = "FrontBullbarC",
		},
		default = "Base.76chevyCseriesBullbarFrontC",
		noPartChance = 5,
	},
    ["BumperFrontS"] = {
		partId = "CH76BumperFront",
		itemToModel = {
			["Base.76chevyKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.93fordF350BullbarFrontD"] = {"FrontBullbarD1", "FrontBullbarD2"},
		},
		default = "Base.93fordF350BullbarFrontD",
		noPartChance = 5,
	},
	["BumperRear"] = {
		partId = "CH76BumperRear",
		itemToModel = {
			["Base.76chevyKseriesBumperRear0"] = "RearBumper0",
			["Base.76chevyKseriesBumperRearA"] = "RearBumper1",
		},
		default = "trve_random",
		noPartChance = 5,
	},
	["WindowFrontLeftArmor"] = {
		partId = "CH76WindowFrontLeftArmor",
		itemToModel = {
			["Base.76chevyKseriesFrontWindowArmor"] = "CH76leftWindowa",
		},
	},
	["WindowFrontRightArmor"] = {
		partId = "CH76WindowFrontRightArmor",
		itemToModel = {
			["Base.76chevyKseriesFrontWindowArmor"] = "CH76rightWindowa",
		},
	},
    ["WindowRearLeftArmor"] = {
		partId = "CH76WindowRearLeftArmor",
		itemToModel = {
			["Base.76chevyKseriesRearWindowArmor"] = "CH76rleftWindowa",
		},
	},
	["WindowRearRightArmor"] = {
		partId = "CH76WindowRearRightArmor",
		itemToModel = {
			["Base.76chevyKseriesRearWindowArmor"] = "CH76rrightWindowa",
		},
	},
	["WindshieldArmor"] = {
		partId = "CH76WindshieldArmor",
		itemToModel = {
			["Base.76chevyKseriesWindshieldArmor"] = "CH76winda",
		},
	},
    ["WindshieldRearArmor"] = {
		partId = "CH76WindshieldRearArmor",
		itemToModel = {
			["Base.utilityBoxWindshieldRearArmor"] = "CH76windra",
		},
	},
	["Roofrack"] = {
		partId = "CH76Roofrack",
		itemToModel = {
			["Base.76chevyKseriesRoofrack2"] = "CH76Roofrack0",
		},
	},
    ["RoofrackW"] = {
		partId = "CH76Roofrack",
		itemToModel = {
			["Base.76chevyCseriesRoofrack2"] = "CH76Roofrack1",
		},
        default = "trve_random",
		noPartChance = 75,
	},
	["BedExtras20"] = {
		partId = "CH76TruckBedExtras",
		itemToModel = {
			["Base.76chevyKseriesRollbar2"] = "CH76Rollbar",
			["Base.76chevyKseriesToolbox2"] = "CH76Toolbox",
            ["Base.76chevyKseriesRollbarSpec2"] = {"CH76Rollbar2", "CH76RollbarLights2"},
		},
		default = "trve_random",
		noPartChance = 25,
	},
	["BedExtras10"] = {
		partId = "CH76TruckBedExtras",
		itemToModel = {
			["Base.76chevyKseriesRollbar2"] = "CH76Rollbar",
			["Base.76chevyKseriesToolbox2"] = "CH76Toolbox",
            ["Base.76chevyKseriesRollbarSpec2"] = {"CH76Rollbar2", "CH76RollbarLights2"},
		},
		default = "trve_random",
		noPartChance = 25,
	},
    ["TruckBedCover10"] = {
		partId = "CH76TruckBedCover",
		itemToModel = {
            ["Base.76chevyK10BedCap2"] = "CH76Cap",
            ["Base.76chevyK10OpenBedCap2"] = "CH76OpenCap",
		},
	},
    ["TruckBedCover20"] = {
		partId = "CH76TruckBedCover",
		itemToModel = {
			["Base.76chevyK20BedCap2"] = "CH76Cap",
			["Base.76chevyK20OpenBedCap2"] = "CH76OpenCap",
		},
	},
    ["TireFrontLeft"] = {
		partId = "TireFrontLeft",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
		},
	},
	["TireFrontRight"] = {
		partId = "TireFrontRight",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
		},
	},
	["TireRearLeft"] = {
		partId = "TireRearLeft",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
		},
	},
	["TireRearRight"] = {
		partId = "TireRearRight",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
		},
	},
    ["SpareTireRoof"] = {
		partId = "CH76SpareTireRoof",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "SpareTire1",
            ["Base.80chevyCKseriesTire2"] = "SpareTire2",
            ["Base.80chevyCKseriesTire1"] = "SpareTire3",
            ["Base.90chevyCKseriesTire2"] = "SpareTire4",
            ["Base.90chevyCKseriesTire1"] = "SpareTire5",
		},
	},
    ["Sidesteps"] = {
		partId = "DAMNSideSteps",
		itemToModel = {
			["Base.76chevyCseriesSidesteps0"] = "SideSteps0",
		},
        default = "trve_random",
		noPartChance = 55,
	},
    ["SidestepsL"] = {
		partId = "DAMNSideSteps",
		itemToModel = {
			["Base.76chevyCseriesSidesteps1"] = "SideSteps1",
		},
        default = "trve_random",
		noPartChance = 45,
	},
    ["SpareTireW"] = {
		partId = "DAMNSpareTire",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "wreckerspare",
		},
        default = "trve_random",
		noPartChance = 35,
	},
    ["GasCanOne"] = {
		partId = "DAMNGasCanOne",
		itemToModel = {
            ["Base.EmptyPetrolCan"] = "gascan1e",
            ["Base.PetrolCan"] = "gascan1",
		},
        default = "trve_random",
		noPartChance = 33,
	},
    ["GasCanTwo"] = {
		partId = "DAMNGasCanTwo",
		itemToModel = {
            ["Base.EmptyPetrolCan"] = "gascan2e",
            ["Base.PetrolCan"] = "gascan2",
		},
        default = "trve_random",
		noPartChance = 33,
	},
    ["PropaneTankOne"] = {
		partId = "DAMNPropaneTankOne",
		itemToModel = {
            ["Base.PropaneTank"] = "prop1",
		},
        default = "trve_random",
		noPartChance = 50,
	},
    ["PropaneTankTwo"] = {
		partId = "DAMNPropaneTankTwo",
		itemToModel = {
            ["Base.PropaneTank"] = "prop2",
		},
        default = "trve_random",
		noPartChance = 50,
	},
    ["Visor"] = {
		partId = "DAMNSunVisor",
		itemToModel = {
			["Base.76chevyCseriesVisor"] = "SunVisor0",
		},
        default = "trve_random",
		noPartChance = 25,
	},
    ["GasCanOneS"] = {
		partId = "DAMNGasCanOne",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanOne",
			["USMIL.emptyGasCan0"] = "GasCanOneE",
			["USMIL.WaterCan0"] = "WaterCanOne",
			["USMIL.emptyWaterCan0"] = "WaterCanOneE",
		},
	},
	["GasCanTwoS"] = {
		partId = "DAMNGasCanTwo",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanTwo",
			["USMIL.emptyGasCan0"] = "GasCanTwoE",
			["USMIL.WaterCan0"] = "WaterCanTwo",
			["USMIL.emptyWaterCan0"] = "WaterCanTwoE",
		},
	},
	["GasCanThreeS"] = {
		partId = "DAMNGasCanThree",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanThree",
			["USMIL.emptyGasCan0"] = "GasCanThreeE",
			["USMIL.WaterCan0"] = "WaterCanThree",
			["USMIL.emptyWaterCan0"] = "WaterCanThreeE",
		},
	},
    ["GasCanFourS"] = {
		partId = "DAMNGasCanFour",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanFour",
			["USMIL.emptyGasCan0"] = "GasCanFourE",
			["USMIL.WaterCan0"] = "WaterCanFour",
			["USMIL.emptyWaterCan0"] = "WaterCanFourE",
		},
	},
});

DAMN.Spawns:add("Base.76chevyC30SCwrecker", 12282, 1578, {
    direction = IsoDirections.S, 
    chance = 90,
    skinIndex = 0,
    sandboxVar = "AllowWreckyMcChevySpawns",
});

DAMN.Spawns:add("Base.76chevyC30CCwrecker", 5444, 5968, {
    direction = IsoDirections.N, 
    chance = 90,
    skinIndex = 0,
    sandboxVar = "AllowWreckyMcChevySpawns",
});


function CH76.ContainerAccess.Toolbox(vehicle, part, chr)
	if chr:getVehicle() then return false end
	if not vehicle:isInArea(part:getArea(), chr) then return false end
	return true
end

function CH76.Dismantle2Tires(items, result, player, selectedItem)

    local addType = "Base.76chevyKseriesTire2"
    local tireCond = selectedItem:getCondition();

    player:getInventory():AddItem(addType):setCondition(tireCond);
    player:getInventory():AddItem(addType):setCondition(tireCond);
    player:getXp():AddXP(Perks.Mechanics, 4);

end

function CH76.ContainerAccess.StorageLeft(vehicle, part, chr)
	if chr:getVehicle() then return false end
	if not vehicle:isInArea(part:getArea(), chr) then return false end
	local TrunkLeft = vehicle:getPartById("CH76TrunkDoorLeft")
	if TrunkLeft and TrunkLeft:getDoor() then
		if not TrunkLeft:getInventoryItem() then return true end
		if not TrunkLeft:getDoor():isOpen() then return false end
	end
	--
	return true
end

function CH76.ContainerAccess.StorageRight(vehicle, part, chr)
	if chr:getVehicle() then return false end
	if not vehicle:isInArea(part:getArea(), chr) then return false end
	local TrunkRight = vehicle:getPartById("CH76TrunkDoorRight")
	if TrunkRight and TrunkRight:getDoor() then
		if not TrunkRight:getInventoryItem() then return true end
		if not TrunkRight:getDoor():isOpen() then return false end
	end
	--
	return true
end