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


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

