require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("W460", {
	["BumperFront"] = {
		partId = "W460BumperFront",
		itemToModel = {
			["Base.W460Bumper1_Item"] = "Bumper1",
			["Base.W460Bullbar2_Item"] = "Bullbar2",
			["Base.W460Bullbar3_Item"] = "Bullbar3",
            ["Base.W460BullbarM_Item"] = "BullbarM",
		},
		default = "first",
	},
    ["BumperFrontM"] = {
		partId = "W460BumperFront",
		itemToModel = {
            ["Base.W460BullbarM_Item"] = "BullbarM",
			["Base.W460Bumper1_Item"] = "Bumper1",
			["Base.W460Bullbar2_Item"] = "Bullbar2",
			["Base.W460Bullbar3_Item"] = "Bullbar3",
		},
		default = "first",
	},
    ["BumperRear"] = {
		partId = "W460BumperRear",
		itemToModel = {
			["Base.W460BumperRear1_Item"] = "BumperRear1",
		},
		default = "first",
	},
    ["DoorFrontLeftArmor"] = {
		partId = "W460DoorFrontLeftArmor",
		itemToModel = {
			["Base.W460CarFrontDoorArmor1_Item"] = "W460leftdoora",
		},
	},
	["DoorFrontRightArmor"] = {
		partId = "W460DoorFrontRightArmor",
		itemToModel = {
			["Base.W460CarFrontDoorArmor1_Item"] = "W460rightdoora",
		},
	},
	["DoorRearLeftArmor"] = {
		partId = "W460DoorRearLeftArmor",
		itemToModel = {
			["Base.W460CarRearDoorArmor1_Item"] = "W460leftdoorra",
		},
	},
	["DoorRearRightArmor"] = {
		partId = "W460DoorRearRightArmor",
		itemToModel = {
			["Base.W460CarRearDoorArmor1_Item"] = "W460rightdoorra",
		},
	},
	["WindowBackLeftArmor"] = {
		partId = "W460WindowBackLeftArmor",
		itemToModel = {
			["Base.W460CarBackWindowArmor1_Item"] = "W460winbla",
		},
	},
	["WindowBackRightArmor"] = {
		partId = "W460WindowBackRightArmor",
		itemToModel = {
			["Base.W460CarBackWindowArmor1_Item"] = "W460winbra",
		},
	},
	["WindshieldArmor"] = {
		partId = "W460WindshieldArmor",
		itemToModel = {
			["Base.W460WindshieldArmor1_Item"] = "W460winda",
		},
	},
	["WindshieldRearArmor"] = {
		partId = "W460WindshieldRearArmor",
		itemToModel = {
			["Base.W460WindshieldRearArmor1_Item"] = "W460windra",
		},
	},
    ["WindshieldRearSplitArmor"] = {
		partId = "W460WindshieldRearArmor",
		itemToModel = {
			["Base.W460WindshieldRearArmorM_Item"] = "W460windra",
		},
	},
    ["Mudflaps"] = {
		partId = "W460Mudflaps",
		itemToModel = {
			["Base.W460Mudflaps1_Item"] = "Mudflaps1",
		},
		default = "trve_random",
		noPartChance = 50,
	},
    ["Roofrack"] = {
		partId = "W460Roofrack",
		itemToModel = {
			["Base.W460Roofrack1_Item"] = "Roofrack1",
            ["Base.W460RoofrackM_Item"] = "RoofrackM",
		},
		default = "trve_random",
		noPartChance = 97,
	},
    ["Bodykit"] = {
		partId = "W460Bodykit",
		itemToModel = {
			["Base.W460Bodykit1_Item"] = "Bodykit1",
		},
		default = "trve_random",
		noPartChance = 50,
	},
    ["BodykitM"] = {
		partId = "W460Bodykit",
		itemToModel = {
            ["Base.W460BodykitM_Item"] = "BodykitM",
            ["Base.W460Bodykit1_Item"] = "Bodykit1",
		},
		default = "first",
	},
    ["Snorkel"] = {
		partId = "W460Snorkel",
		itemToModel = {
			["Base.W460SnorkelM_Item"] = "SnorkelM",
		},
		default = "trve_random",
		noPartChance = 90,
	},
    ["SnorkelM"] = {
		partId = "W460Snorkel",
		itemToModel = {
            ["Base.W460SnorkelM_Item"] = "SnorkelM",
		},
		default = "first",
	},
    ["Guards"] = {
		partId = "W460Guards",
		itemToModel = {
			["Base.W460Guards_Item"] = "GuardsM",
		},
		default = "trve_random",
		noPartChance = 90,
	},
    ["GuardsM"] = {
		partId = "W460Guards",
		itemToModel = {
            ["Base.W460Guards_Item"] = "GuardsM",
		},
		default = "first",
	},
    ["GasCan"] = {
		partId = "W460GasCan",
		itemToModel = {
			["USMIL.GasCan0"] = "GasCan",
			["USMIL.emptyGasCan0"] = "GasCanE",
			["USMIL.WaterCan0"] = "WaterCan",
			["USMIL.emptyWaterCan0"] = "WaterCanE",
		},
		default = "trve_random",
		noPartChance = 25,
	},
    ["SpareTire"] = {
		partId = "W460SpareTire",
		itemToModel = {
			["Base.W460NormalTire2"] = "SpareTire1",
            ["Base.W460WideTire2"] = "SpareTire2",
            ["Base.W460ModernTire2"] = "SpareTire3",
		},
		default = "trve_random",
		noPartChance = 25,
	},
    ["SpareTireM"] = {
		partId = "W460SpareTire",
		itemToModel = {
			["Base.W460MilitaryTire2"] = "SpareTireM",
		},
		default = "trve_random",
		noPartChance = 50,
	},
	["TireFrontLeft"] = {
		partId = "TireFrontLeft",
		itemToModel = {
			["Base.W460NormalTire2"] = "W460Tire0",
			["Base.W460WideTire2"] = "W460Tire1",
            ["Base.W460ModernTire2"] = "W460Tire2",
		},
	},
	["TireFrontRight"] = {
		partId = "TireFrontRight",
		itemToModel = {
			["Base.W460NormalTire2"] = "W460Tire0",
			["Base.W460WideTire2"] = "W460Tire1",
            ["Base.W460ModernTire2"] = "W460Tire2",
		},
	},
	["TireRearLeft"] = {
		partId = "TireRearLeft",
		itemToModel = {
			["Base.W460NormalTire2"] = "W460Tire0",
			["Base.W460WideTire2"] = "W460Tire1",
            ["Base.W460ModernTire2"] = "W460Tire2",
		},
	},
	["TireRearRight"] = {
		partId = "TireRearRight",
		itemToModel = {
			["Base.W460NormalTire2"] = "W460Tire0",
			["Base.W460WideTire2"] = "W460Tire1",
            ["Base.W460ModernTire2"] = "W460Tire2",
		},
	},
});

function W460.ContainerAccess.Trunk(vehicle, part, chr)
	if chr:getVehicle() == vehicle then
		local seat = vehicle:getSeat(chr)
		return 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 W460.ContainerAccess.TrunkTwo(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("TrunkDoor")
		if doorPart and doorPart:getDoor() and not doorPart:getDoor():isOpen() then
			return false
		end
		return true
	end
end

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