require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("SUB93", {
	["BumperFront"] = {
		partId = "SUB93BumperFront",
		itemToModel = {
			["Base.93chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.93chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.93chevySuburbanBullbarFrontA"] = "FrontBullbarA",
			["Base.93chevySuburbanBullbarFrontB"] = "FrontBullbarB",
            ["Base.93chevySuburbanBullbarFrontB2"] = "FrontBullbarB2",
			["Base.93chevySuburbanBullbarFrontC"] = "FrontBullbarC",
		},
		allowedForRandom = {
            "Base.93chevySuburbanBumperFront0", "Base.93chevySuburbanBumperFront1"
        },
		default = "trve_random",
		noPartChance = 5,
	},
    ["BumperFrontP"] = {
		partId = "SUB93BumperFront",
		itemToModel = {
			["Base.93chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.93chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.93chevySuburbanBullbarFrontA"] = "FrontBullbarA",
			["Base.93chevySuburbanBullbarFrontB"] = "FrontBullbarB",
            ["Base.93chevySuburbanBullbarFrontB2"] = "FrontBullbarB2",
			["Base.93chevySuburbanBullbarFrontC"] = "FrontBullbarC",
            ["Base.93chevySilveradoPlowFrame"] = "FrontBullbarP",
		},
		allowedForRandom = {
            "Base.93chevySuburbanBumperFront0", "Base.93chevySuburbanBumperFront1"
        },
		default = "trve_random",
		noPartChance = 5,
	},
	["BumperFrontPD"] = {
		partId = "SUB93BumperFront",
		itemToModel = {
			["Base.93chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.93chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.93chevySuburbanBullbarFrontA"] = "FrontBullbarA",
			["Base.93chevySuburbanBullbarFrontB"] = "FrontBullbarB",
            ["Base.93chevySuburbanBullbarFrontB2"] = "FrontBullbarB2",
			["Base.93chevySuburbanBullbarFrontC"] = "FrontBullbarC",
		},
		default = "93chevySuburbanBullbarFrontA",
	},
	["BumperFrontFD"] = {
		partId = "SUB93BumperFront",
		itemToModel = {
			["Base.93chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.93chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.93chevySuburbanBullbarFrontA"] = "FrontBullbarA",
			["Base.93chevySuburbanBullbarFrontB"] = "FrontBullbarB",
            ["Base.93chevySuburbanBullbarFrontB2"] = "FrontBullbarB2",
			["Base.93chevySuburbanBullbarFrontC"] = "FrontBullbarC",
		},
		default = "93chevySuburbanBullbarFrontC",
	},
    ["BumperFrontW"] = {
		partId = "SUB93BumperFront",
		itemToModel = {
			["Base.93chevySuburbanBumperFront0"] = "FrontBumper0",
			["Base.93chevySuburbanBumperFront1"] = "FrontBumper1",
			["Base.93chevySuburbanBullbarFrontA"] = "FrontBullbarA",
			["Base.93chevySuburbanBullbarFrontB"] = "FrontBullbarB",
            ["Base.93chevySuburbanBullbarFrontB2"] = "FrontBullbarB2",
			["Base.93chevySuburbanBullbarFrontC"] = "FrontBullbarC",
            ["Base.93chevySuburbanBullbarFrontD"] = "FrontBullbarD",
		},
		default = "93chevySuburbanBullbarFrontD",
	},
	["BumperRear"] = {
		partId = "SUB93BumperRear",
		itemToModel = {
			["Base.93chevySuburbanBumperRear0"] = "RearBumper0",
		},
		default = "trve_random",
		noPartChance = 5,
	},
	["WindshieldArmor"] = {
		partId = "SUB93WindshieldArmor",
		itemToModel = {
			["Base.93chevySuburbanWindshieldArmor"] = "SUB93winda",
		},
	},
	["WindshieldRearArmor"] = {
		partId = "SUB93WindshieldRearArmor",
		itemToModel = {
			["Base.93chevySuburbanWindshieldRearArmor"] = "SUB93windrb",
		},
	},
	["WindowFrontLeftArmor"] = {
		partId = "SUB93WindowFrontLeftArmor",
		itemToModel = {
			["Base.93chevySuburbanFrontWindowArmor"] = "SUB93leftWindowa",
		},
	},
	["WindowFrontRightArmor"] = {
		partId = "SUB93WindowFrontRightArmor",
		itemToModel = {
			["Base.93chevySuburbanFrontWindowArmor"] = "SUB93rightWindowa",
		},
	},
	["WindowRearLeftArmor"] = {
		partId = "SUB93WindowRearLeftArmor",
		itemToModel = {
			["Base.93chevySuburbanRearWindowArmor"] = "SUB93leftWindowra",
		},
	},
	["WindowRearRightArmor"] = {
		partId = "SUB93WindowRearRightArmor",
		itemToModel = {
			["Base.93chevySuburbanRearWindowArmor"] = "SUB93rightWindowra",
		},
	},
	["WindowBackLeftArmor"] = {
		partId = "SUB93WindowBackLeftArmor",
		itemToModel = {
			["Base.93chevySuburbanBackWindowArmor"] = "SUB93leftWindowba",
		},
	},
	["WindowBackRightArmor"] = {
		partId = "SUB93WindowBackRightArmor",
		itemToModel = {
			["Base.93chevySuburbanBackWindowArmor"] = "SUB93rightWindowba",
		},
	},
	["Roofrack"] = {
		partId = "SUB93Roofrack",
		itemToModel = {
			["Base.93chevySuburbanRoofrack2"] = "SUB93Roofrack0",
		},
		default = "trve_random",
		noPartChance = 85,
	},
	["SideSteps"] = {
		partId = "SUB93SideSteps",
		itemToModel = {
			["Base.93chevySuburbanSideSteps2"] = "SUB93SideSteps0",
            ["Base.93chevySuburbanSideStepsMetal2"] = "SUB93SideSteps1",
            ["Base.93chevySuburbanSideStepsPipes2"] = "SUB93SideSteps2",
		},
		default = "trve_random",
		noPartChance = 25,
	},
    ["SideStepsS"] = {
		partId = "SUB93SideSteps",
		itemToModel = {
            ["Base.93chevySuburbanSideStepsMetal2"] = "SUB93SideSteps1",
            ["Base.93chevySuburbanSideStepsPipes2"] = "SUB93SideSteps2",
		},
		default = "trve_random",
		noPartChance = 33,
	},
    ["SideStepsNA"] = {
		partId = "SUB93SideSteps",
		itemToModel = {
			["Base.93chevySuburbanSideSteps2"] = "SUB93SideSteps0",
            ["Base.93chevySuburbanSideStepsMetal2"] = "SUB93SideSteps1",
            ["Base.93chevySuburbanSideStepsPipes2"] = "SUB93SideSteps2",
		},
	},
	["BugGuard"] = {
		partId = "SUB93BugGuard",
		itemToModel = {
			["Base.93chevySuburbanBugGuard2"] = "SUB93BugGuard0",
		},
		default = "trve_random",
		noPartChance = 85,
	},
	["TireFrontLeft"] = {
		partId = "TireFrontLeft",
		itemToModel = {
			["Base.93chevySuburbanTire1"] = "SUB93Tire0",
			["Base.93chevySuburbanTire2"] = "SUB93Tire1",
            ["Base.76chevyKseriesTire2"] = "SUB93Tire2",
            ["Base.80chevyCKseriesTire2"] = "SUB93Tire3",
            ["Base.80chevyCKseriesTire1"] = "SUB93Tire4",
            ["Base.90chevyCKseriesTire2"] = "SUB93Tire5",
            ["Base.90chevyCKseriesTire1"] = "SUB93Tire6",
            ["Base.90gmcOEMTire1"] = "SUB93Tire7",
		},
	},
	["TireFrontRight"] = {
		partId = "TireFrontRight",
		itemToModel = {
			["Base.93chevySuburbanTire1"] = "SUB93Tire0",
			["Base.93chevySuburbanTire2"] = "SUB93Tire1",
            ["Base.76chevyKseriesTire2"] = "SUB93Tire2",
            ["Base.80chevyCKseriesTire2"] = "SUB93Tire3",
            ["Base.80chevyCKseriesTire1"] = "SUB93Tire4",
            ["Base.90chevyCKseriesTire2"] = "SUB93Tire5",
            ["Base.90chevyCKseriesTire1"] = "SUB93Tire6",
            ["Base.90gmcOEMTire1"] = "SUB93Tire7",
		},
	},
	["TireRearLeft"] = {
		partId = "TireRearLeft",
		itemToModel = {
			["Base.93chevySuburbanTire1"] = "SUB93Tire0",
			["Base.93chevySuburbanTire2"] = "SUB93Tire1",
            ["Base.76chevyKseriesTire2"] = "SUB93Tire2",
            ["Base.80chevyCKseriesTire2"] = "SUB93Tire3",
            ["Base.80chevyCKseriesTire1"] = "SUB93Tire4",
            ["Base.90chevyCKseriesTire2"] = "SUB93Tire5",
            ["Base.90chevyCKseriesTire1"] = "SUB93Tire6",
            ["Base.90gmcOEMTire1"] = "SUB93Tire7",
		},
	},
	["TireRearRight"] = {
		partId = "TireRearRight",
		itemToModel = {
			["Base.93chevySuburbanTire1"] = "SUB93Tire0",
			["Base.93chevySuburbanTire2"] = "SUB93Tire1",
            ["Base.76chevyKseriesTire2"] = "SUB93Tire2",
            ["Base.80chevyCKseriesTire2"] = "SUB93Tire3",
            ["Base.80chevyCKseriesTire1"] = "SUB93Tire4",
            ["Base.90chevyCKseriesTire2"] = "SUB93Tire5",
            ["Base.90chevyCKseriesTire1"] = "SUB93Tire6",
            ["Base.90gmcOEMTire1"] = "SUB93Tire7",
		},
	},
    ["GasCanOne"] = {
		partId = "SUB93GasCanOne",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanOne",
			["USMIL.emptyGasCan0"] = "GasCanOneE",
			["USMIL.WaterCan0"] = "WaterCanOne",
			["USMIL.emptyWaterCan0"] = "WaterCanOneE",
		},
	},
	["GasCanTwo"] = {
		partId = "SUB93GasCanTwo",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanTwo",
			["USMIL.emptyGasCan0"] = "GasCanTwoE",
			["USMIL.WaterCan0"] = "WaterCanTwo",
			["USMIL.emptyWaterCan0"] = "WaterCanTwoE",
		},
	},
	["GasCanThree"] = {
		partId = "SUB93GasCanThree",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCanThree",
			["USMIL.emptyGasCan0"] = "GasCanThreeE",
			["USMIL.WaterCan0"] = "WaterCanThree",
			["USMIL.emptyWaterCan0"] = "WaterCanThreeE",
		},
	},
    ["Mudflaps"] = {
		partId = "DAMNMudflaps",
		itemToModel = {
			["Base.93chevyK3500mudflaps2"] = "Mudflaps0",
		},
		default = "trve_random",
		noPartChance = 25,
	},
    ["BedTarp"] = {
		partId = "SIL93Tarp",
		itemToModel = {
			["Base.93chevySilveradoBedTarp2"] = "bedTarp0",
		},
	},
    ["BedStakes"] = {
		partId = "SIL93BedStakes",
		itemToModel = {
			["Base.93chevySilveradoStakes2"] = "bedStakes0",
		},
	},
    ["BedStakesR"] = {
		partId = "SIL93BedStakes",
		itemToModel = {
			["Base.93chevySilveradoStakes2"] = "bedStakes0",
		},
		default = "trve_random",
		noPartChance = 5,
	},
    ["RollbarToolbox"] = {
		partId = "SUB93RollbarToolbox",
		itemToModel = {
			["Base.93chevySilverdoRollbar2"] = {"93chevySilveradoLight", "93chevySilveradoRoll"},
            ["Base.93chevyK3500toolbox2"] = "93chevySilveradoToolbox",
		},
	},
    ["RollbarToolboxR"] = {
		partId = "SUB93RollbarToolbox",
		itemToModel = {
			["Base.93chevySilverdoRollbar2"] = {"93chevySilveradoLight", "93chevySilveradoRoll"},
            ["Base.93chevyK3500toolbox2"] = "93chevySilveradoToolbox",
		},
		default = "trve_random",
		noPartChance = 33,
	},
    ["RollbarToolbox2"] = {
		partId = "SUB93RollbarToolbox",
		itemToModel = {
			["Base.93chevySilverdoRollbar2"] = {"93chevySilveradoLight", "93chevySilveradoRoll"},
            ["Base.93chevyK3500toolbox2"] = "93chevySilveradoToolbox",
		},
		default = "Base.93chevyK3500toolbox2",
	},
    ["TailgatePanel"] = {
		partId = "SUB93TailgatePanel",
		itemToModel = {
			["Base.93chevyTailgatePanel2"] = "panel112435548",
		},
		default = "trve_random",
		noPartChance = 50,
	},
});


function SUB93.ContainerAccess.Trunk(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return seat == 5 or seat == 4 or seat == 3 or 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 SUB93.ContainerAccess.TrunkPD(vehicle, part, chr)
	if chr:getVehicle() then return false end
	if not vehicle:isInArea(part:getArea(), chr) then return false end
	local doorPart = vehicle:getPartById("TrunkDoor")
	if doorPart and doorPart:getDoor() then
		if not doorPart:getInventoryItem() then return true end
		if not doorPart:getDoor():isOpen() then return false end
	end
	return true
end

function SUB93.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 SUB93.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 SUB93.Dismantle2Tires(items, result, player, selectedItem)

    local addType = "Base.93chevyK3500Tire2"
    local tireCond = selectedItem:getCondition();

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

end