# music_onlinemusic

if $ARGS[0] = 'set_up_account':
	ml_online['account'] = 1
	minut += 10
	gs 'internet_mobile', 'use_internet', $access['subscription'], 10
	gs 'stat'	
	'You log into Youtube to set up a channel for your music. You can upload videos or live stream, but you will need to open a bank account if you want to receive any tips from viewers of your stream.'	
!!	TODO: Ask for a screen name? 
	act 'Leave': gs 'music_actions', 'start'
end


if $ARGS[0] = 'live_stream':	
!!	TODO: Much, much better scene needed.
	ml_streaming['times_streamed'] += 1		
	gs 'music_onlinemusic', 'stream_interruptions'

	if ml_no_interruption ! 0: 
		!! TODO: Separate scenes by instrument used, not used
		ml_streamtime = 60
		gs 'music_onlinemusic', 'streaming_stats'
		if komp = 1 and webcamera = 1 and $location_type = 'private':
			'<center><img <<$set_imgh>> src="images/pc/activities/music/gomixer_hero.jpg"/></center>'
			'You set up your webcamera and start the streaming app on your computer. After settling down comfortably, you start to stream.'			
			'Your fans tipped you <<ml_superchats>> rubels for your performance.'
		else		
			'<center><img <<$set_imgh>> src="images/pc/activities/music/gomixer_hero.jpg"/></center>'
			'You set up your phone on a little tri-pod and log into your account. After settling down comfortably, you start to stream.'			
			'Your fans tipped you <<ml_superchats>> rubels for your performance.'
		end	
	else
		!! How many minutes did the stream last.
		ml_streaming = rand(1,60)
		gs 'music_onlinemusic', 'streaming_stats'
		!! TODO: Interruption events and such will come here
	end
	
	if bankAccount = 0:			
		*nl
		'You have earned <b><<ml_streaming[''unclaimed_earnings'']>></b> rubels so far, but you need to open a bank account before you can receive the money.'
	else		
		*nl
		'You have <b><<ml_streaming[''unclaimed_earnings'']>></b> rubels on your account.'

		act 'Stop the stream and transfer the money to your bank account':				
			karta += ml_streaming['unclaimed_earnings']
			ml_streaming['unclaimed_earnings'] = 0
			gs 'music_onlinemusic', 'finish', 'streaming'
		end
	end
	act 'Stop the stream':
		gs 'music_onlinemusic', 'finish', 'streaming'
	end
	killvar 'ml_streamtime'
	killvar 'ml_no_interruption'
end

if $ARGS[0] = 'record_song':
	recording_time = 30
	performed_minutes = 15
	gs 'music_onlinemusic', 'recording_interruptions'
	
	if ml_no_interruption ! 0:
	!!	TODO: Write a scene. It should describe that a song is recorded and then edited properly before uploading it to the net.
		'<center><img <<$set_imgh>> src="images/pc/activities/music/phonerecording.jpg"/></center>'
		'You set up your phone and settle down comfortably to record a song. After several tries you finally end up with a version you are content with and upload it to your account.'
		'As you don''t have a computer you can''t really do much with the songs quality. But then you have seen quite a few people work with only with their phones. Like Ling Ling.'
	end

	gs 'music_onlinemusic', 'recording_stats'

	killvar 'recording_time'
	killvar 'ml_no_interruption'
	killvar 'performed_minutes'

	if ml_online['account'] = 1 and $access ! 'denied':
		if pcs_inhib < 30:
			if pcs_inhib < 10: 
				$diff = 'hard'
			elseif pcs_inhib < 20: 
				$diff = 'medium'
			else 
				$diff = 'easy'
			end
			gs 'willpower', 'skill', 'self', $diff

			will_cost = (will_cost * 2) - (pcs_perform)
			if will_cost <= pcs_willpwr:
				act 'Upload music (<<will_cost>> Willpower)': gt 'music_onlinemusic', 'uploadmusic', 'recording'
			else	
				act 'Upload music (<font color="red"><<will_cost>> Willpower</font>)': '<br><font color="red">You don''t have enough willpower to use this action.</font>'
			end
		else
			act 'Upload music': gt 'music_onlinemusic', 'uploadmusic', 'recording'
		end
	end 
	act 'Leave': gs 'music_onlinemusic', 'finish', 'recording'
end

!! IMPORTANT 
!! TODO: Recording and Editing/Mixing needs to be split into two separate activities. So keep ''recrodSong'' as is and make this into purely about editing
if $ARGS[0] = 'edit_song':
!!	TODO: Write a scene. It should describe that a song is recorded and then edited properly before uploading it to the net.
!!	'<center><img <<$set_imgh>> src="images/pc/activities/music/editmusic.jpg"/></center>'
	'<center><video autoplay loop src="images/pc/activities/music/editmusic.mp4"></video></center>'
	'You plug in your home studio kit and start up the recording software. After several tries you finally end up with a version you are content with.'
	'The next hour just flies by as you edit the video and the audio, trying to increate the quality of the recording as much as you can'
	minut += 90

	gs 'exp_gain', 'vokal', rand(1,3)	
	if perform_lvl < 35: gs 'exp_gain', 'perform', rand(1,3)	
	if musicprod_lvl < 35: gs 'exp_gain', 'musicprod', rand(1,3)
	ml_performance['performed_minutes'] += 15
	ml_performance['total_time_performed'] += 15

	ml_onlinesong_hotcat[ml_onlinesongcount] = hotcat
	if ml_guitar['hasguitar'] = 1:
		ml_onlinesong_skilllevel[ml_onlinesongcount] = pcs_instrmusic + pcs_vokal + pcs_perform
		ml_onlinesong_freshness[ml_onlinesongcount] = pcs_instrmusic + pcs_vokal + pcs_perform + ((hotcat-4)*10)
		gs 'exp_gain', 'instrmusic', rand(1,3)		
	else
		ml_onlinesong_skilllevel[ml_onlinesongcount] = (pcs_vokal * 2) + pcs_perform
		ml_onlinesong_freshness[ml_onlinesongcount] = (pcs_vokal * 2) + pcs_perform + ((hotcat-4)*10)
	end

	ml_onlinesong_lastcalcday[ml_onlinesongcount] = daystart
	ml_onlinesong_uploaded[ml_onlinesongcount] = 0

	ml_uploadablemusic += 1
	ml_onlinesongcount += 1	

	if ml_online['account'] = 1 and $access ! 'denied':
		if pcs_inhib < 30:
			if pcs_inhib < 10: 
				$diff = 'hard'
			elseif pcs_inhib < 20: 
				$diff = 'medium'
			else 
				$diff = 'easy'
			end
			gs 'willpower', 'skill', 'self', $diff

			will_cost = (will_cost * 2) - (pcs_perform)
			if will_cost <= pcs_willpwr:
				act 'Upload music (<<will_cost>> Willpower)': gt 'music_onlinemusic', 'uploadmusic'
			else	
				act 'Upload music (<font color="red"><<will_cost>> Willpower</font>)': '<br><font color="red">You don''t have enough willpower to use this action.</font>'
			end
		else 
			act 'Upload music': gt 'music_onlinemusic', 'uploadmusic'
		end
	else
		act 'Leave': gs 'music_actions', 'finish'
	end

end


if $ARGS[0] = 'uploadmusic':
	if  pcs_inhib < 30:
		'You hesitate for a long moment, but finally take a deep breath and click on the "Upload" button and your newly recorded song moves over to the internet for all to see.'
		'You bite in your lip, then close the screen before you change your mind and delete it.'
	else
		'You smile brightly and click on the "Upload" button. Now the whole world can see you play. And if they don''t like it, well... "Haters gonna hate" you shrug mentally and close the screen. They will like it."'
	end	
	gs 'stat'

	ml_uploadablemusic -= 1 
	ml_onlinesong_uploaded[ml_onlinesongcount-1] = 1

	killvar 'will_cost'
	if $ARGS[1] = 'recording': 
		act 'Leave': gs 'music_onlinemusic', 'finish', 'recording'
	else
		act 'Leave': gs 'music_actions', 'start'
	end
end


if $ARGS[0] = 'uploadallmusic':
	'<center><img src="images/pc/activities/music/uploadmusic.jpg"/></center>'
	if will_cost > 0:
		'You go through the songs you recorded and clear out the old ones that you really, really don''t like anymore. Then after a moment of hesitation you take a deep breath and click on the "Upload" button.
		The screen changes and one by one, your songs move over to the internet for all to see.'
		'You bite in your lip, then close the screen before you change your mind and delete them.'
	else
		'You smile brightly as you browse through your recordings, deleting some old ones, then finally click the "Upload" button. Now the whole world can see you play. And if they don''t like it, well... "Haters gonna hate" you shrug mentally and close the screen, this is how art grows."'
	end

	gs 'music_onlinemusic', 'deleting'

	i = 0
	:uploadallmusic			
		if ml_onlinesong_uploaded[i] = 0 and $access ! 'denied': 
			minut += 5
			gs 'internet_mobile', 'use_internet', $access['subscription'], 5
			gs 'stat'

			ml_onlinesong_uploaded[i] = 1	
			ml_uploadablemusic -= 1		
		end
		i += 1
	if i < ml_onlinesongcount:jump 'uploadallmusic'
	killvar 'will_cost'

	act 'Leave': gs 'music_actions', 'start'
end

if $ARGS[0] = 'deleteoldmusic':
	'You go through your recorded musics and delete all the old ones where your playing doesn''t really reflect what you can do these days'
	gs 'music_onlinemusic', 'deleting'

	act 'Leave': gs 'music_actions', 'start'
end

!!----------------------------------------------------------------------------------------------------------------------------
!!-----------------------------------------   GoSub functions all go here   --------------------------------------------------
!!----------------------------------------------------------------------------------------------------------------------------

if $ARGS[0] = 'deleting':

	ml_threshold_skilllevel = ((pcs_instrmusic + pcs_vokal + pcs_perform)*80)/100

	i = 0
	j = -1
	
	:deletemusic
		if (ml_onlinesong_uploaded = 1) or (ml_onlinesong_uploaded = 0 and ml_onlinesong_skilllevel > ml_threshold_skilllevel):
			j += 1
			ml_tempsong_freshness[j] = ml_onlinesong_sfreshness[i]
			ml_tempsong_lastcalcday[j] = ml_onlinesong_lastcalcday[i]
			ml_tempsong_hotcat[j] = ml_onlinesong_hotcat[i]
			ml_tempsong_skilllevel[j] = ml_onlinesong_skilllevel[i]
			ml_tempsong_uploaded[j] = ml_onlinesong_uploaded[i]			
		else
			ml_uploadablemusic -= 1
		end

		i += 1
	if i < ml_onlinesongcount:jump 'deletemusic'

	killvar 'ml_onlinesong_freshness'
	killvar 'ml_onlinesong_lastcalcday'
	killvar 'ml_onlinesong_hotcat'
	killvar 'ml_onlinesong_skilllevel'
	killvar 'ml_onlinesong_uploaded'
	killvar 'i'

	ml_onlinesongcount = 0

	if j >= 0:
		:looprebuildsongs
			ml_onlinesong_freshness[ml_onlinesongcount] = ml_tempsong_freshness[ml_onlinesongcount]
			ml_onlinesong_hotcat[ml_onlinesongcount] = ml_tempsong_hotcat[ml_onlinesongcount]
			ml_onlinesong_lastcalcday[ml_onlinesongcount] = ml_tempsong_lastcalcday[ml_onlinesongcount]
			ml_onlinesong_skilllevel[ml_onlinesongcount] = ml_tempsong_skilllevel[ml_onlinesongcount]
			ml_onlinesong_uploaded[ml_onlinesongcount] = ml_tempsong_uploaded[ml_onlinesongcount]
			ml_onlinesongcount += 1
		if ml_onlinesongcount <= j: jump 'looprebuildsongs'
	end

	killvar 'ml_tempsong_freshness'
	killvar 'ml_tempsong_lastcalcday'
	killvar 'ml_tempsong_hotcat'
	killvar 'ml_tempsong_skilllevel'
	killvar 'ml_tempsong_uploaded'
	killvar 'ml_threshold_skilllevel'

end

if $ARGS[0] = 'finish':
	if $location_type = 'public_outdoors': 
		ml_rand_event = rand(0,100)
		if ml_rand_event <= 10 and $region = 'pav' and npc_rel['A144'] > 40: 
			if $ARGS[1] = 'streaming': 
				gs 'music_onlinemusic', 'anushka_streaming_end'
			elseif $ARGS[1] = 'recording': 
				gs 'music_onlinemusic', 'anushka_recording_end'
			end
		elseif ml_rand_event <= 30 and $region = 'pav':
			gs 'music_gigstarts', 'zariyah_passing_by'
		!!	elseif ml_rand_event < 15 and $ARGS[1] = 'pav' and ((npc_rel['A20'] < 20 or npc_rel['A21'] < 20):
		!! TODO: if the gopniks don''t like the PC and/or her music is awful, there is a chance that Lena and Lera harasses her.
		!!		gs 'music_buskingevents', 'lena_and_lera', 1
		!!	elseif ml_rand_event < 15 and $ARGS[1] = 'pav' and ( (npc_rel['A20'] < 40 or npc_rel['A21'] < 40) and (pcs_instrmusic < 30 or pcs_perform < 30 or pcs_vokal < 30) ):
		!!		gs 'music_buskingevents', 'lena_and_lera', 2
		else
			gs 'music_actions', 'finish'
		end
		killvar 'ml_rand_event'
	else
		gs 'music_actions', 'finish'
	end
end

if $ARGS[0] = 'streaming_stats':
	minut += ml_streamtime
	gs 'internet_mobile', 'use_internet', $access['subscription'], ml_streamtime

	ml_maxsuperchats = 	( fame['pav_music'] + (fame['city_music'] * 2) + fame['pushkin_music'] + fame['village_music'] + pcs_apprnc )
	ml_superchats = (rand( 0, ml_maxsuperchats) * ml_streamtime) / 60
	
	if ml_guitar['hasguitar'] = 1 and (ml_guitar['carried'] = 1 or $ml_guitar['location'] = $loc):
		ml_famebase = ( pcs_instrmusic + pcs_vokal + pcs_perform + ( (hotcat-5) * 20 ) ) / 20
		gs 'exp_gain', 'instrmusic', rand(1,3)					
	else	
		ml_famebase = ( (pcs_vokal * 2) + pcs_perform + ( (hotcat-5) * 20 ) ) / 20
	end
	
	gs 'fame', 'pav', 'music', rand(0, ml_famebase)
	gs 'fame', 'city', 'music', rand(0, ml_famebase)
	gs 'exp_gain', 'vokal', rand(1,3)	
	if perform_lvl < 35: gs 'exp_gain', 'perform', rand(1,3)

	ml_streaming['livestreamcount'] += 1
	ml_streaming['lastday'] = daystart
	ml_performance['performed_minutes'] += ml_streamtime
	ml_performance['total_time_performed'] += ml_streamtime
	ml_streaming['total_earnings'] += ml_superchats		
	ml_streaming['unclaimed_earnings'] += ml_superchats

	gs 'stat'
end

if $ARGS[0] = 'recording_stats':
	minut += recording_time

	if performed_minutes > 10:
		gs 'exp_gain', 'vokal', rand(1,4)	
		if perform_lvl < 35: gs 'exp_gain', 'perform', rand(1,3)
		ml_performance['performed_minutes'] += performed_minutes
		ml_performance['total_time_performed'] += performed_minutes

		ml_onlinesong_hotcat[ml_onlinesongcount] = hotcat
		if ml_guitar['hasguitar'] = 1 and (ml_guitar['carried'] = 1 or $ml_guitar['location'] = $loc):
			ml_onlinesong_skilllevel[ml_onlinesongcount] = pcs_instrmusic + pcs_vokal + pcs_perform
			ml_onlinesong_freshness[ml_onlinesongcount] = pcs_instrmusic + pcs_vokal + pcs_perform + ((hotcat-4)*10)
			gs 'exp_gain', 'instrmusic', rand(1,3)		
		else
			ml_onlinesong_skilllevel[ml_onlinesongcount] = (pcs_vokal * 2) + pcs_perform
			ml_onlinesong_freshness[ml_onlinesongcount] = (pcs_vokal * 2) + pcs_perform + ((hotcat-4)*10)
		end

		ml_onlinesong_lastcalcday[ml_onlinesongcount] = daystart
		ml_onlinesong_uploaded[ml_onlinesongcount] = 0

		ml_uploadablemusic += 1
		ml_onlinesongcount += 1		
	end
end

if $ARGS[0] = 'stream_interruptions':
	!! TODO: Will depend on chance and fame - the more famous Sveta is, the more likely someone will interrupt. Just like in real life.
	!{
		Planned scenarios:
		1.	Anushka shows up, just like with busking. 
			If Sveta's skills are good enough for Anushka and they have a good relationship she can join in.
		2.  Lena and Lera show up and if they don't like Sveta will mess with the stream - running around, 
			throwing twigs and leaves at Sveta, mocking her, making loud noises, etc.
		3.  Some other stuff.
	}
	ml_no_interruption = 1
end

if $ARGS[0] = 'recording_interruptions':
	!! TODO: Will depend on chance and fame - the more famous Sveta is, the more likely someone will interrupt. Just like in real life.
	!{
		Planned scenarios:
		1.	Anushka shows up, just like with busking. 
			If Sveta's skills are good enough for Anushka and they have a good relationship she can join in.
		2.  Lena and Lera show up and if they don't like Sveta will mess with the recording - running around, 
			throwing twigs and leaves at Sveta, mocking her, making loud noises, etc.
		3.  Some other stuff.
	}
	ml_no_interruption = 1
end

!!----------------------------------------------------------------------------------------------------------------------------
!!-----------------------------------------   Outdoors events all go here   --------------------------------------------------
!!----------------------------------------------------------------------------------------------------------------------------


if $ARGS[0] = 'anushka_streaming_end':
	gs 'music_actions', 'finish'
end

if $ARGS[0] = 'anushka_recording_end':
	gs 'music_actions', 'finish'
end
--- music_onlinemusic ---------------------------------
