require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("CH76", {
	["BumperFront"] = {
		partId = "DAMNBumperFront",
		itemToModel = {
			["Base.3rdGenChevyCKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.93fordF350BullbarFrontD"] = {"FrontBullbarD1", "FrontBullbarD2"},
		},
		allowedForRandom = {
            "Base.3rdGenChevyCKseriesBumperFront0", "Base.76chevyKseriesBullbarFrontA", "Base.76chevyKseriesBullbarFrontB"
        },
        default = "trve_random",
		noPartChance = 5,
	},
    ["BumperFrontW"] = {
		partId = "DAMNBumperFront",
		itemToModel = {
			["Base.76chevyKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.76chevyCseriesBullbarFrontC"] = "FrontBullbarC",
		},
		default = "Base.76chevyCseriesBullbarFrontC",
		noPartChance = 5,
	},
    ["BumperFrontS"] = {
		partId = "DAMNBumperFront",
		itemToModel = {
			["Base.76chevyKseriesBumperFront0"] = "FrontBumper0",
			["Base.76chevyKseriesBullbarFrontA"] = "FrontBullbarA",
            ["Base.76chevyKseriesBullbarFrontB"] = "FrontBullbarB",
            ["Base.93fordF350BullbarFrontD"] = {"FrontBullbarD1", "FrontBullbarD2"},
		},
		default = "Base.93fordF350BullbarFrontD",
		noPartChance = 5,
	},
	["BumperRear"] = {
		partId = "DAMNBumperRear",
		itemToModel = {
			["Base.3rdGenChevyCKseriesBumperRear0"] = "RearBumper0",
			["Base.76chevyKseriesBumperRearA"] = "RearBumper1",
		},
		default = "trve_random",
		noPartChance = 5,
	},
	["WindowFrontLeftArmor"] = {
		partId = "DAMNFrontLeftArmor",
		itemToModel = {
			["Base.76chevyKseriesFrontWindowArmor"] = "CH76leftWindowa",
		},
	},
	["WindowFrontRightArmor"] = {
		partId = "DAMNFrontRightArmor",
		itemToModel = {
			["Base.76chevyKseriesFrontWindowArmor"] = "CH76rightWindowa",
		},
	},
    ["WindowRearLeftArmor"] = {
		partId = "DAMNRearLeftArmor",
		itemToModel = {
			["Base.76chevyKseriesRearWindowArmor"] = "CH76rleftWindowa",
		},
	},
	["WindowRearRightArmor"] = {
		partId = "DAMNRearRightArmor",
		itemToModel = {
			["Base.76chevyKseriesRearWindowArmor"] = "CH76rrightWindowa",
		},
	},
	["WindshieldArmor"] = {
		partId = "DAMNWindshieldArmor",
		itemToModel = {
			["Base.76chevyKseriesWindshieldArmor"] = "CH76winda",
		},
	},
    ["WindshieldRearArmor"] = {
		partId = "DAMNWindshieldRearArmor",
		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",
            ["damnCraft.SmallTire2"] = "CH76Tire5",
		},
	},
	["TireFrontRight"] = {
		partId = "TireFrontRight",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
            ["damnCraft.SmallTire2"] = "CH76Tire5",
		},
	},
	["TireRearLeft"] = {
		partId = "TireRearLeft",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
            ["damnCraft.SmallTire2"] = "CH76Tire5",
		},
	},
	["TireRearRight"] = {
		partId = "TireRearRight",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "CH76Tire0",
            ["Base.80chevyCKseriesTire2"] = "CH76Tire1",
            ["Base.80chevyCKseriesTire1"] = "CH76Tire2",
            ["Base.90chevyCKseriesTire2"] = "CH76Tire3",
            ["Base.90chevyCKseriesTire1"] = "CH76Tire4",
            ["damnCraft.SmallTire2"] = "CH76Tire5",
		},
	},
    ["SpareTireRoof"] = {
		partId = "DAMNSpareTireRoof",
		itemToModel = {
            ["Base.76chevyKseriesTire2"] = "SpareTire1",
            ["Base.80chevyCKseriesTire2"] = "SpareTire2",
            ["Base.80chevyCKseriesTire1"] = "SpareTire3",
            ["Base.90chevyCKseriesTire2"] = "SpareTire4",
            ["Base.90chevyCKseriesTire1"] = "SpareTire5",
            ["damnCraft.SmallTire2"] = "SpareTire6",
		},
	},
    ["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.PetrolCan"] = "gascan1",
		},
        default = "trve_random",
		noPartChance = 50,
	},
    ["GasCanTwo"] = {
		partId = "DAMNGasCanTwo",
		itemToModel = {
            ["Base.PetrolCan"] = "gascan2",
		},
        default = "trve_random",
		noPartChance = 50,
	},
    ["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.WaterCan0"] = "WaterCanOne",
		},
	},
	["GasCanTwoS"] = {
		partId = "DAMNGasCanTwo",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanTwo",
			["USMIL.WaterCan0"] = "WaterCanTwo",
		},
	},
	["GasCanThreeS"] = {
		partId = "DAMNGasCanThree",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanThree",
			["USMIL.WaterCan0"] = "WaterCanThree",
		},
	},
    ["GasCanFourS"] = {
		partId = "DAMNGasCanFour",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanFour",
			["USMIL.WaterCan0"] = "WaterCanFour",
		},
	},
});

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.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