require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("SUB87", {
	["BumperFront"] = {
		partId = "SUB87BumperFront",
		itemToModel = {
			["Base.87chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.87chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.87chevySuburbanBullbarFrontA"] = "FrontBullbarA",
		},
		default = "trve_random",
		noPartChance = 15,
	},
	["BumperFrontCUCV"] = {
		partId = "SUB87BumperFront",
		itemToModel = {
			["Base.87chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.87chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.87chevySuburbanBullbarFrontA"] = "FrontBullbarA",
		},
		default = "87chevySuburbanBullbarFrontA",
	},
	["BumperRear"] = {
		partId = "SUB87BumperRear",
		itemToModel = {
			["Base.87chevySuburbanBumperRear0"] = "RearBumper0",
		},
		default = "trve_random",
		noPartChance = 5,
	},
	["WindowFrontLeftArmor"] = {
		partId = "SUB87WindowFrontLeftArmor",
		itemToModel = {
			["Base.87chevySuburbanFrontWindowArmor"] = "SUB87leftWindowa",
		},
	},
	["WindowFrontRightArmor"] = {
		partId = "SUB87WindowFrontRightArmor",
		itemToModel = {
			["Base.87chevySuburbanFrontWindowArmor"] = "SUB87rightWindowa",
		},
	},
	["WindowRearLeftArmor"] = {
		partId = "SUB87WindowRearLeftArmor",
		itemToModel = {
			["Base.87chevySuburbanRearWindowArmor"] = "SUB87leftWindowra",
		},
	},
	["WindowRearRightArmor"] = {
		partId = "SUB87WindowRearRightArmor",
		itemToModel = {
			["Base.87chevySuburbanRearWindowArmor"] = "SUB87rightWindowra",
		},
	},
	["WindowBackLeftArmor"] = {
		partId = "SUB87WindowBackLeftArmor",
		itemToModel = {
			["Base.87chevySuburbanBackWindowArmor"] = "SUB87leftWindowba",
		},
	},
	["WindowBackRightArmor"] = {
		partId = "SUB87WindowBackRightArmor",
		itemToModel = {
			["Base.87chevySuburbanBackWindowArmor"] = "SUB87rightWindowba",
		},
	},
	["WindshieldArmor"] = {
		partId = "SUB87WindshieldArmor",
		itemToModel = {
			["Base.87chevySuburbanWindshieldArmor"] = "SUB87winda",
		},
	},
	["WindshieldRearArmor"] = {
		partId = "SUB87WindshieldRearArmor",
		itemToModel = {
			["Base.87chevySuburbanWindshieldRearArmor"] = "SUB87windra",
		},
	},
	["SideSteps"] = {
		partId = "SUB87SideSteps",
		itemToModel = {
			["Base.87chevySuburbanSideSteps2"] = "SideSteps0",
		},
		default = "trve_random",
		noPartChance = 50,
	},
	["Roofrack"] = {
		partId = "SUB87Roofrack",
		itemToModel = {
			["Base.87chevySuburbanRoofrack2"] = "Roofrack0",
		},
		default = "trve_random",
		noPartChance = 75,
	},
	["RoofLights"] = {
		partId = "SUB87RoofLights",
		itemToModel = {
			["Base.87chevySuburbanRoofLights2"] = "SUB87RoofLights0",
		},
		default = "trve_random",
		noPartChance = 50,
	},
    ["TireFrontLeft"] = {
		partId = "TireFrontLeft",
		itemToModel = {
			["Base.87chevySuburbanTire2"] = "SUB87Tire0",
            ["Base.76chevyKseriesTire2"] = "SUB87Tire1",
            ["Base.80chevyCKseriesTire2"] = "SUB87Tire2",
            ["Base.80chevyCKseriesTire1"] = "SUB87Tire3",
            ["Base.90chevyCKseriesTire2"] = "SUB87Tire4",
            ["Base.90chevyCKseriesTire1"] = "SUB87Tire5",
		},
	},
	["TireFrontRight"] = {
		partId = "TireFrontRight",
		itemToModel = {
			["Base.87chevySuburbanTire2"] = "SUB87Tire0",
            ["Base.76chevyKseriesTire2"] = "SUB87Tire1",
            ["Base.80chevyCKseriesTire2"] = "SUB87Tire2",
            ["Base.80chevyCKseriesTire1"] = "SUB87Tire3",
            ["Base.90chevyCKseriesTire2"] = "SUB87Tire4",
            ["Base.90chevyCKseriesTire1"] = "SUB87Tire5",
		},
	},
	["TireRearLeft"] = {
		partId = "TireRearLeft",
		itemToModel = {
			["Base.87chevySuburbanTire2"] = "SUB87Tire0",
            ["Base.76chevyKseriesTire2"] = "SUB87Tire1",
            ["Base.80chevyCKseriesTire2"] = "SUB87Tire2",
            ["Base.80chevyCKseriesTire1"] = "SUB87Tire3",
            ["Base.90chevyCKseriesTire2"] = "SUB87Tire4",
            ["Base.90chevyCKseriesTire1"] = "SUB87Tire5",
		},
	},
	["TireRearRight"] = {
		partId = "TireRearRight",
		itemToModel = {
			["Base.87chevySuburbanTire2"] = "SUB87Tire0",
            ["Base.76chevyKseriesTire2"] = "SUB87Tire1",
            ["Base.80chevyCKseriesTire2"] = "SUB87Tire2",
            ["Base.80chevyCKseriesTire1"] = "SUB87Tire3",
            ["Base.90chevyCKseriesTire2"] = "SUB87Tire4",
            ["Base.90chevyCKseriesTire1"] = "SUB87Tire5",
		},
	},
});

function SUB87.ContainerAccess.Roofrack(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 SUB87.ContainerAccess.Trunk(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return seat >= 2;
	elseif chr:getVehicle() then
		return false
	else
		if not vehicle:isInArea(part:getArea(), chr) then return false end
		local doorPart = vehicle:getPartById("TrunkDoor")
		if doorPart and doorPart:getDoor() and not doorPart:getDoor():isOpen() then
			return false
		end
		return true
	end
end

function SUB87.ContainerAccess.Gunrack(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return seat == 1 or seat == 0;
	elseif chr:getVehicle() then
		return false
	else
		if not vehicle:isInArea(part:getArea(), chr) then return false end
		local doorPart = vehicle:getPartById("DoorFrontRight")
		if doorPart and doorPart:getDoor() and not doorPart:getDoor():isOpen() then
			return false
		end
		return true
	end
end

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