function ShoulderCamera.isZoomed(U)return U.zoomState end function ShoulderCamera.setHideToolWhileZoomed(C,U)C.hideToolWhileZoomed=U end function ShoulderCamera.setZoomFactor(C,U)C.currentZoomFactor=U local y=math.rad(C.fieldOfView)local L=math.tan(y/2)local v=L/C.currentZoomFactor C.zoomedFOV=math.deg(math.atan(v)*2)C:updateZoomState()end function ShoulderCamera.resetZoomFactor(U)U:setZoomFactor(U.defaultZoomFactor)end function ShoulderCamera.setForceZoomed(C,U)if C.forcedZoomed==U then return end C.forcedZoomed=U C:updateZoomState()end function ShoulderCamera.setZoomedFromInput(C,U)if C.zoomedFromInput==U or C.currentHumanoid and C.currentHumanoid:GetState()==Enum.HumanoidStateType.Dead then return end C.zoomedFromInput=U C:updateZoomState()end function ShoulderCamera.updateZoomState(U)local C=U.forcedZoomed if U.canZoom and not U.forcedZoomed then C=U.zoomedFromInput end if not U.enabled or not U.currentTool then C=false end U.zoomState=C U.currentMouseRadsPerPixel=C and U.zoomedMouseRadsPerPixel or U.mouseRadsPerPixel U.currentTouchSensitivity=C and U.zoomedTouchSensitivity or U.touchSensitivity if U.weaponsSystem and U.weaponsSystem.gui then U.weaponsSystem.gui:setCrosshairScaleTarget(U.zoomState and U.zoomedCrosshairScale or U.normalCrosshairScale)U.weaponsSystem.gui:setCrosshairEnabled(not U.zoomState or not U.hasScope)U.weaponsSystem.gui:setScopeEnabled(U.zoomState and U.hasScope)if U.currentTool then U.currentTool.ManualActivationOnly=U.zoomState and(U.hasScope and UserInputService.TouchEnabled)end end if U.currentCamera then U.desiredFieldOfView=U:getCurrentFieldOfView()end end function ShoulderCamera.onZoomAction(L,U,C,y)if not L.enabled or not L.canZoom or not L.currentCamera or not L.currentCharacter or not L.weaponsSystem.currentWeapon then L:setZoomedFromInput(false)return Enum.ContextActionResult.Pass end L:setZoomedFromInput(C==Enum.UserInputState.Begin)return Enum.ContextActionResult.Sink end
-- Zoom related functions

function ShoulderCamera:isZoomed()
	return self.zoomState
end

function ShoulderCamera:setHideToolWhileZoomed(hide)
	self.hideToolWhileZoomed = hide
end

function ShoulderCamera:setZoomFactor(zoomFactor)
	self.currentZoomFactor = zoomFactor
	local nominalFOVRadians = math.rad(self.fieldOfView)
	local nominalImageHeight = math.tan(nominalFOVRadians / 2)
	local zoomedImageHeight = nominalImageHeight / self.currentZoomFactor
	self.zoomedFOV = math.deg(math.atan(zoomedImageHeight) * 2)
	self:updateZoomState()
end

function ShoulderCamera:resetZoomFactor()
	self:setZoomFactor(self.defaultZoomFactor)
end

function ShoulderCamera:setForceZoomed(zoomed)
	if self.forcedZoomed == zoomed then
		return
	end
	self.forcedZoomed = zoomed
	self:updateZoomState()
end

function ShoulderCamera:setZoomedFromInput(zoomedFromInput)
	if
		self.zoomedFromInput == zoomedFromInput
		or (self.currentHumanoid and self.currentHumanoid:GetState() == Enum.HumanoidStateType.Dead)
	then
		return
	end

	self.zoomedFromInput = zoomedFromInput
	self:updateZoomState()
end

function ShoulderCamera:updateZoomState()
	local isZoomed = self.forcedZoomed
	if self.canZoom and not self.forcedZoomed then
		isZoomed = self.zoomedFromInput
	end

	if not self.enabled or not self.currentTool then
		isZoomed = false
	end

	self.zoomState = isZoomed

	self.currentMouseRadsPerPixel = isZoomed and self.zoomedMouseRadsPerPixel or self.mouseRadsPerPixel
	self.currentTouchSensitivity = isZoomed and self.zoomedTouchSensitivity or self.touchSensitivity

	if self.weaponsSystem and self.weaponsSystem.gui then
		self.weaponsSystem.gui:setCrosshairScaleTarget(
			self.zoomState and self.zoomedCrosshairScale or self.normalCrosshairScale
		)
		self.weaponsSystem.gui:setCrosshairEnabled(not self.zoomState or not self.hasScope)
		self.weaponsSystem.gui:setScopeEnabled(self.zoomState and self.hasScope)
		if self.currentTool then
			self.currentTool.ManualActivationOnly = self.zoomState and self.hasScope and UserInputService.TouchEnabled
		end
	end

	if self.currentCamera then
		self.desiredFieldOfView = self:getCurrentFieldOfView()
	end
end

function ShoulderCamera:onZoomAction(actionName, inputState, inputObj)
	if
		not self.enabled
		or not self.canZoom
		or not self.currentCamera
		or not self.currentCharacter
		or not self.weaponsSystem.currentWeapon
	then
		self:setZoomedFromInput(false)
		return Enum.ContextActionResult.Pass
	end

	self:setZoomedFromInput(inputState == Enum.UserInputState.Begin)
	return Enum.ContextActionResult.Sink
end
