require "DAMN_Parts";
require "DAMN_Spawns";

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

DAMN.Parts:processConfigV2("ARRW", {
	["Mudflaps"] = {
		partId = "ARRWMudflaps",
		itemToModel = {
			["Base.90pierceArrowMudflaps2"] = "Mudflaps0",
		},
		default = "trve_random",
		noPartChance = 50,
	},
	["WindowFrontLeftArmor"] = {
		partId = "ARRWWindowFrontLeftArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinfla",
		},
	},
	["WindowFrontRightArmor"] = {
		partId = "ARRWWindowFrontRightArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinfra",
		},
	},
	["WindowRearLeftArmor"] = {
		partId = "ARRWWindowRearLeftArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinrla",
		},
	},
	["WindowRearRightArmor"] = {
		partId = "ARRWWindowRearRightArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinrra",
		},
	},
	["WindowMiddleLeftArmor"] = {
		partId = "ARRWWindowMiddleLeftArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinmla",
		},
	},
	["WindowMiddleRightArmor"] = {
		partId = "ARRWWindowMiddleRightArmor",
		itemToModel = {
			["Base.90pierceArrowSideWindowArmor"] = "ARRWwinmra",
		},
	},
	["WindshieldArmor"] = {
		partId = "ARRWWindshieldArmor",
		itemToModel = {
			["Base.90pierceArrowWindshieldArmor"] = "ARRWwinda",
		},
	},
	["WindshieldRearArmor"] = {
		partId = "ARRWWindshieldRearArmor",
		itemToModel = {
			["Base.90pierceArrowWindshieldRearArmor"] = "ARRWwindra",
		},
	},
});


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

function ARRW.ContainerAccess.TrunkLeft(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("TrunkDoorLeft")
	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 ARRW.ContainerAccess.TrunkRight(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("TrunkDoorRight")
	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

function ARRW.Dismantle2Tires(items, result, player, selectedItem)

    local addType = "Base.90pierceArrowTire2"
    local tireCond = selectedItem:getCondition();

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

end