:: webcam_attachToComputer[computer_after]
<<if setup.hasInternet() && $location.furniture.computer.webcam && $quest('camwhore').isCamwhore>>
	<<act 'Pose as Camgirl'>>
		<<gt 'webcam'>>
	<</act>>
<</if>>

:: webcam[event]
	<<webcamImage "pc/activities/camwhore/website.webp">>
	<p>Your alias on this website is <b><<=$quest('camwhore').webcamname>></b>.</p>
	<p>You have performed as a camgirl <<=$quest('camwhore').performances>> <<plural $quest('camwhore').performances 'time' 'times'>>.</p>
	<p>You have <<=$quest('camwhore').fans>> <<plural $quest('camwhore').fans 'follower' 'followers'>>.</p>
	<p>You have <<=$quest('camwhore').tokens>> <<plural $quest('camwhore').tokens 'token' 'tokens'>>.</p>

	<<act 'Start Session'>>
		<<gt 'webcam_session_start'>>
	<</act>>

	<<if $quest('camwhore').tokens > 0>>
		<<act 'Exchange tokens for money'>>
			<<gt 'webcam_exchange'>>
		<</act>>
	<</if>>

	<<act 'Change your mind'>>
		<<gt 'Computer'>>
	<</act>>

:: webcam_exchange[event]
	<<webcamImage "pc/activities/camwhore/website.webp">>
	<<set _tokens = $quest('camwhore').tokens>>

	<p>
		As soon as you have the minimum amount of tokens, you can have them transfered to your bank account with just one click.
		The exchange rates appear to have been set up in a way that encourages the girls to accumulate a large number of tokens before exchanging them for money.
	</p>

	<p>You have _tokens <<plural _tokens 'token' 'tokens'>>.</p>
	
	<<act 'Back'>><<gt 'webcam'>><</act>>

	<<set _courses = [[3,1],[10,4],[25,11],[50,24],[100,51],[250,140],[500,300],[1000,640],[2500,1750],[5000,3740],[10000,8000]]>> /*pow(0.8,max(0,5-log(10,n)))*n */

	<<if _tokens >= _courses[0][0]>>
		<<act 'Sell all tokens'>>
			<<for _course range _courses.reverse()>>
				<<for _tokens >= _course[0]>>
					<<set _tokens -= _course[0]>>
					<<set $finances.bank += _course[1]>>
				<</for>>
			<</for>>
			<<set $quest('camwhore').tokens = _tokens>>
			<<gt 'webcam_exchange'>>
		<</act>>
	<<else>>
		<p><<negative>>You need at least <<=_courses[0][0]>> tokens to exchange them for money.<</negative>></p>
	<</if>>

	<h3>Current exchange rates</h3>
	<table>
		<tr><th>Tokens</th><th>Money</th></tr>
		<<for _course range _courses>>
			<tr><td>_course[0]</td><td><<money _course[1]>></td></tr>
			<<if _tokens >= _course[0]>>
				<<act `_course[0]+' tokens to '+_course[1]+'₽'` undefined `{capture:['_course']}`>>
					<<set $quest('camwhore').tokens -= _course[0]>>
					<<set $finances.bank += _course[1]>>
					<<gt 'webcam_exchange'>>
				<</act>>
			<</if>>
		<</for>>
	</table>

:: webcam_session_start[event]
	<<set $quest('camwhore').session = {start: $time.now,tokens:0}>>
	<<webcamImage 'pc/activities/camwhore/idle.gif'>>
	<<set $quest('camwhore').session.viewers ??= Math.round($quest('camwhore').fans / 3)>>
	<<gs 'webcam_session'>>
:: webcam_session[event]
	<p>You have <<=$quest('camwhore').session.viewers>> <<plural $quest('camwhore').session.viewers 'viewer' 'viewers'>>.</p>

	<<if $quest('camwhore').session.viewers == 0>>
		<<actCLA 'Wait for viewers' undefined `{time: 15}`>>
			<<set _hotcat = $pc.hotcat>>
			<<set $quest('camwhore').session.viewers += [0,0,1,2,3] .random()>>
			<<webcamImage 'pc/activities/camwhore/idle.gif'>>
			<<gs 'webcam_session'>>
		<</actCLA>>
	<<else>>
		<<eventExecute 'webcam_request'>>
	<</if>>

	<<actCLA 'End session' undefined `{priority:-1000}`>>
		<<webcamImage 'pc/activities/camwhore/idle.gif'>>
		<<set _tokens = $quest('camwhore').session.tokens>>
		<<set $quest('camwhore').tokens += _tokens>>
		<<set _totalTokens = $quest('camwhore').tokens>>
		<<set $quest('camwhore').session = {}>>
		<p>You tell your viewers goodbye and turn off your camera.</p>
		<p>You just earned  _tokens <<plural _tokens 'token' 'tokens'>>. You now have _totalTokens <<plural _totalTokens 'token' 'tokens'>>.</p>
		<<act 'Camgirl Homepage'>>
			<<gt 'webcam'>>
		<</act>>
		<<ret 'Turn off computer'>>
	<</actCLA>>

:: webcam_request[webcam_request_events]
<<event>>
	<p>One of your viewers asks you to ''lick your breasts''.</p>
	<<actCLA 'Lick your breasts'>>
		<<set _newFans = Math.ceil($quest('camwhore').session.viewers*0.1)>>
		<<set $quest('camwhore').fans += _newFans>>

		<<addtime 5>>
		<<webcamImage 'pc/activities/camwhore/breastLick.webp'>>

		<<exp 'webcam' 1 true>>

		<<gs 'webcam_tokens_update'>>
		<<gs 'webcam_viewers_update'>>

		<<gs 'webcam_session'>>
	<</actCLA>>
	<<eventFired>>
<</event>>

:: webcam_tokens_update[inlcude]
	<<set _currentViewers = $quest('camwhore').session.viewers>>
	<<set _tokensGain = Math.ceil(_currentViewers * rand(0,10) / 100)>>
	<<set $quest('camwhore').session.tokens += _tokensGain>>
	<<set _currentTokens = $quest('camwhore').session.tokens>>
	<p>You gained _tokensGain <<plural _tokensGain 'token' 'tokens'>>. You have _currentTokens <<plural _currentTokens 'token' 'tokens'>>.</p>

:: webcam_viewers_update[include]
	<<set _viewerTarget = $quest('camwhore').viewerTarget>>
	<<set _currentViewers = $quest('camwhore').session.viewers>>

	<<if _currentViewers > _viewerTarget>>
		<<set _newViewers = Math.floor(-0.2 * _currentViewers)>>
	<<else>>
		<<set _growth = [-0.1,0,0,0.1,0.2].random()>>
		<<set _newViewersGrowth = Math.ceilAbs(_growth * _currentViewers)>>

		<<set _viewerToTarget = _viewerTarget - _currentViewers>>
		<<set _newViewersTarget = Math.floor(0.4 * _viewerToTarget)>>

		<<set _newViewers = Math.min(_newViewersTarget, _newViewersGrowth)>>
		
		<<if _newViewers < 0 && _newViewers + _currentViewers < 0>>
			<<set _newViewers = -1 * _currentViewers>>
		<</if>>
	<</if>>

	<<if _newViewers >= 0>>
		<p><<positive>>You gained _newViewers <<plural _newViewers 'viewer' 'viewers'>>.<</positive>></p>
	<<else>>
		<<set _newViewersAbs = -1 * _newViewers>>
		<p><<negative>>You lost _newViewersAbs <<plural _newViewersAbs 'viewer' 'viewers'>>.<</negative>></p>
	<</if>>

	<<set $quest('camwhore').session.viewers += _newViewers>>
