require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("M923", {
	["Bumper"] = {
		partId = "DAMNBumperFront",
		itemToModel = {
			["Base.M923Bumper1"] = "M923Bumper1",
			["Base.M923Bumper2"] = "M923Bumper2",
		},
		default = "trve_random",
		noPartChance = 10,
	},
	["Stakes"] = {
		partId = "M923Stakes",
		itemToModel = {
			["Base.M923FlatbedStakes1"] = "M923Stakes1",
		},
		default = "trve_random",
		noPartChance = 50,
	},
    ["SpareMount"] = {
		partId = "M923SpareMount",
		itemToModel = {
			["Base.M923SpareMount1"] = "M923SpareMount1",
		},
		default = "first",
	},
    ["SpareTire"] = {
		partId = "DAMNSpareTire",
		itemToModel = {
			["runFlat.LargeTire"] = "M923SpareTire1",
		},
		default = "trve_random",
		noPartChance = 25,
	},
	["WindshieldArmor"] = {
		partId = "DAMNWindshieldArmor",
		itemToModel = {
			["Base.M923WindshieldArmor1"] = "M923WindshieldArmor1",
		},
	},
	["DoorLeftArmor"] = {
		partId = "DAMNFrontLeftArmor",
		itemToModel = {
			["Base.M923DoorArmor1"] = "M923DoorLeftArmor1",
		},
	},
	["DoorRightArmor"] = {
		partId = "DAMNFrontRightArmor",
		itemToModel = {
			["Base.M923DoorArmor1"] = "M923DoorRightArmor1",
		},
	},
	["GuntruckArmor"] = {
		partId = "M923GuntruckArmor",
		itemToModel = {
			["Base.M923GuntruckArmor1"] = "M923GuntruckArmor1",
		},
        default = "trve_random",
			noPartChance = 85,
	},
	["Mudflaps"] = {
		partId = "DAMNMudflaps",
		itemToModel = {
			["Base.M923Mudflaps1"] = "M923Mudflaps1",
		},
        default = "trve_random",
			noPartChance = 25,
	},
	["Muffler"] = {
		partId = "Muffler",
		itemToModel = {
			["Base.M923Muffler1"] = "M923Muffler1",
		},
		default = "first",
	},
    ["CabCover"] = {
		partId = "M923CabCovers",
		itemToModel = {
			["Base.M923HardCover1"] = "M923HardCover1",
		},
		default = "first",
	},
});


function M923.ContainerAccess.Storage(vehicle, part, chr)
	if chr:getVehicle() then return false end
	if not vehicle:isInArea(part:getArea(), chr) then return false end
	local ToolboxLid = vehicle:getPartById("M923StorageDoor")
	if ToolboxLid and ToolboxLid:getDoor() then
		if not ToolboxLid:getInventoryItem() then return true end
		if not ToolboxLid:getDoor():isOpen() then return false end
	end
	--
	return true
end

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