:: chessplay
<<set $here = 'chessplay'>>
<<set $ARGS = $location_var[$here]>>
<<set $menu_off = 1>>
<<if !$location_var[$here][0]>>
	<<if $chess_name == ''>>
		<<set $chess_name = 'Boy'>>

	<</if>>
	<<set $chess_GG = 20>>
	<<set $chess_com = 20>>
	<!-- ! chess_ind is used to show the integer difference between Sveta and her opponent-->
	<!-- ! if it is 0 then Sveta is equally skilled as her opponent-->
	<!-- ! the opponent will play more neutrally if the skill gap is within 5 points-->
	<!-- ! if it is > 0 then Sveta is less skilled then her opponent-->
	<!-- ! the opponent will play more aggressively if Sveta is less skilled by at least 5 points-->
	<!-- ! if it is < 0 then Sveta is more skilled then her opponent-->
	<!-- ! the opponent will play more conservatively if Sveta is more skilled by at least 5 points-->
	<<set $chess_ind = $chessV - $pc.skillLevel("chess")>>
	<!-- ! chess_diff is used to show how that difference affects the swing in momentum with each move-->
	<<if getvar("$chess_ind") < 0>>
		<<set $chess_diff = ($chess_ind / 2) * -1>>
	<<else>>
		<<set $chess_diff = ($chess_ind / 2)>>
	<</if>>
	<!-- ! move_limit and time_limit keeps games from going forever-->
	<<set $chess_move_limit = 60>>
	<<set $chess_time_limit = 120>>
	<!-- ! chess_move and total_chess_time keep track of total moves and time until it hits the limits-->
	<<set $chess_move = 0>>
	<<set $total_chess_time = 0>>
	<<gt 'chessplay' 'game'>>
<</if>>
<<if $location_var[$here][0] == 'expfame'>>
	<<if $location_var[$here][1] == 0>>
		<<set $chessmulti = 1>>
	<<elseif $location_var[$here][1] == 1>>
		<<set $chessmulti = 3>>
	<<elseif $location_var[$here][1] == 2>>
		<<set $chessmulti = 5>>
	<</if>>
	<<if getvar("$chessV") == 10>>
		<<run $pc.skillExperienceGain('chess',$chessmulti * 2)>>
		<<run $pc.fameInc('pav','chess',$chessmulti * 2)>>
		<<run $pc.skillExperienceGain('intelligence',rand(0,1))>>
	<<elseif getvar("$chessV") == 30>>
		<<run $pc.skillExperienceGain('chess',$chessmulti * 4)>>
		<<run $pc.fameInc('pav','chess',$chessmulti * 4)>>
		<<run $pc.skillExperienceGain('intelligence',rand(1,2))>>
	<<elseif getvar("$chessV") == 50>>
		<<run $pc.skillExperienceGain('chess',$chessmulti * 6)>>
		<<run $pc.fameInc('pav','chess',$chessmulti * 6)>>
		<<run $pc.skillExperienceGain('intelligence',rand(2,3))>>
	<<elseif getvar("$chessV") == 70>>
		<<run $pc.skillExperienceGain('chess',$chessmulti * 8)>>
		<<run $pc.fameInc('pav','chess',$chessmulti * 8)>>
		<<run $pc.skillExperienceGain('intelligence',rand(2,4))>>
	<<elseif getvar("$chessV") == 90>>
		<<run $pc.skillExperienceGain('chess',$chessmulti * 10)>>
		<<run $pc.fameInc('pav','chess',$chessmulti * 10)>>
		<<run $pc.skillExperienceGain('intelligence',rand(2,5))>>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'game'>>
	<<set $chess_move += 1>>
	<<set $chess_time = rand(1,3)>>
	<<set $time.minutes += $chess_time>>
	<<set $total_chess_time += $chess_time>>
	<<if getvar("$chess_move") == 1>>
		<<image "locations/pavlovsk/community/chess/board#.jpg" 1 1>>
		<<if getvar("$chess_ind") > 5>>
			<p>You are less skilled at chess than '+$chess_name+'. They will play more aggressively to try and defeat you.</p>
			You might want to play more conservatively and wear down their attacks.
		<<elseif getvar("$chess_ind") < -5>>
			<p>You are more skilled at chess than '+$chess_name+'. They will play more conservatively to try and defeat you.</p>
			You might want to play more aggressively and wear down their defenses.
		<<else>>
			<p>You are about equally skilled at chess as '+$chess_name+'. They will use a wide range of moves to try and defeat you.</p>
			You might want to try different types of moves to keep your opponent off balance.
		<</if>>
	<</if>>
	<<if getvar("$chess_GG") <= 0 and getvar("$chess_com") <= 0>>
		<<image "locations/pavlovsk/community/chess/stalemate#.jpg" 1 1>>
		<p>Stalemate! You have drawn the match against '+$chess_name+'!</p>
		<p>You and '+$chess_name+' could not find a way to win the match.</p>
		<<gs 'chessplay' 'expfame' 1>>
		<<act 'Return'>>
			<<gt 'kruchess'>>
		<</act>>
	<<elseif getvar("$chess_GG") <= 0>>
		<<image "locations/pavlovsk/community/chess/lose#.jpg" 1 1>>
		<p>Checkmate! You have lost the match against '+$chess_name+'!</p>
		<<gs 'chessplay' 'fame' 0>>
		<<act 'Return'>>
			<<gt 'kruchess'>>
		<</act>>
	<<elseif getvar("$chess_com") <= 0>>
		<<set $chess_win += 1>>
		<<image "locations/pavlovsk/community/chess/win#.jpg" 1 1>>
		<p>Checkmate! You have won the match against '+$chess_name+'!</p>
		<<gs 'chessplay' 'fame' 2>>
		<<act 'Return'>>
			<<gt 'kruchess'>>
		<</act>>
	<<elseif $chess_moves >= $chess_move_limit>>
		<<image "locations/pavlovsk/community/chess/stalemate#.jpg" 1 1>>
		<p>Draw! You agree to end the match with '+$chess_name+'.</p>
		<p>You and '+$chess_name+' have both used too many moves and neither could find a way to win the match.</p>
		<<gs 'chessplay' 'fame' 1>>
		<<act 'Return'>>
			<<gt 'kruchess'>>
		<</act>>
	<<elseif $total_chess_time >= $chess_time_limit>>
		<<image "locations/pavlovsk/community/chess/stalemate#.jpg" 1 1>>
		<p>Draw! You agree to end the match with '+$chess_name+'.</p>
		<p>You and '+$chess_name+' have both used too much time and neither could find a way to win the match.</p>
		<<gs 'chessplay' 'fame' 1>>
		<<act 'Return'>>
			<<gt 'kruchess'>>
		<</act>>
	<<else>>
		<<gs 'chessplay' 'moves'>>
	<</if>>
<</if>>
<<if $location_var[$here][0] == 'moves'>>
	<<if getvar("$chess_ind") > 5>>
		<<set $chessM = rand(4,11)>>
	<<elseif getvar("$chess_ind") < -5>>
		<<set $chessM = rand(0,7)>>
	<<else>>
		<<set $chessM = rand(2,9)>>
	<</if>>
	<<actCLA 'Play conservatively'>>
		<!-- ! this works as the opposite of aggressive play-->
		<!-- ! conservative wins against offense and trap-->
		<!-- ! conservative loses to defense and tactical-->
		<!-- ! conservative ties with conservative and aggressive-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' also plays conservatively.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' plays defensively and is now in a better position than you.'
			<<gs 'chessplay' 'advantage' 'conservative' 'bad'>>
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' plays tactically and is able to deftly pick apart your conservative defenses.'
			<<gs 'chessplay' 'advantage' 'conservative' 'bad'>>
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' tries to trap you, but you encircle it with your defenses.'
			<<gs 'chessplay' 'advantage' 'conservative' 'good'>>
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' plays offensively, but your defense repulses his attacks.'
			<<gs 'chessplay' 'advantage' 'conservative' 'good'>>
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' plays aggressively, but your defense manages to hold them off.'
			Neither of you gain an advantage from this move.
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
	<<actCLA 'Play defensively'>>
		<!-- ! this works as the opposite of offensive play-->
		<!-- ! defense wins against trap and conservative-->
		<!-- ! defense loses to aggressive and tactical-->
		<!-- ! defense ties with offense and defense-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' plays very conservatively and does not threaten your defenses at all.'
			<<gs 'chessplay' 'advantage' 'defense' 'good'>>
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' also plays defensively.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' plays tactically and is able to deftly pick apart your defenses.'
			<<gs 'chessplay' 'advantage' 'defense' 'bad'>>
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' tries to trap you, but you avoid it with your defenses.'
			<<gs 'chessplay' 'advantage' 'defense' 'good'>>
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' plays offensively, but your defense absorbs his attacks.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' plays aggressively and overwhelms your defenses.'
			<<gs 'chessplay' 'advantage' 'defense' 'bad'>>
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
	<<actCLA 'Play tactically'>>
		<!-- ! this works as the opposite of trap play-->
		<!-- ! tactical wins against defense and conservative-->
		<!-- ! tactical loses to aggressive and offense-->
		<!-- ! tactical ties with tactical and trap-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' plays very conservatively and your tactical moves leave you in a better position.'
			<<gs 'chessplay' 'advantage' 'tactical' 'good'>>
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' plays defensively allowing you to pick apart their defenses.'
			<<gs 'chessplay' 'advantage' 'tactical' 'good'>>
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' also plays tactically.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' tries to trap you, but you avoid it with your tactical movements.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' plays offensively, and some of your pieces are caught out of position.'
			<<gs 'chessplay' 'advantage' 'tactical' 'bad'>>
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' plays aggressively and rushes past your unprepared defenses.'
			<<gs 'chessplay' 'advantage' 'tactical' 'bad'>>
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
	<<actCLA 'Bait a trap for your opponent'>>
		<!-- ! this works as the opposite of tactical play-->
		<!-- ! trap wins against offense and aggressive-->
		<!-- ! trap loses to conservative and defense-->
		<!-- ! trap ties with tactical and trap-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' plays very conservatively and their defenses are now very well prepared.'
			<<gs 'chessplay' 'advantage' 'trap' 'bad'>>
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' plays defensively and your bait is now out of position.'
			<<gs 'chessplay' 'advantage' 'trap' 'bad'>>
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' plays tactically and avoids your trap.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' also tries to trap you.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' plays offensively, and a couple of their pieces are caught out of position.'
			<<gs 'chessplay' 'advantage' 'trap' 'good'>>
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' plays aggressively and many of their pieces fall into your trap.'
			<<gs 'chessplay' 'advantage' 'trap' 'good'>>
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
	<<actCLA 'Play offensively'>>
		<!-- ! this works as the opposite of defensive play-->
		<!-- ! offense wins against tactical and aggressive-->
		<!-- ! offense loses to conservative and trap-->
		<!-- ! offense ties with offense and defense-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' plays very conservatively and repulses all your attacks.'
			<<gs 'chessplay' 'advantage' 'offense' 'bad'>>
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' plays defensively and manages to absorb all your attacks.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' plays tactically, but your offense is able to outmaneuver them.'
			<<gs 'chessplay' 'advantage' 'offense' 'good'>>
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' traps some of your pieces. You should think more carefully next time.'
			<<gs 'chessplay' 'advantage' 'offense' 'bad'>>
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' also plays offensively.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' plays aggressively and overextends themselves.'
			<<gs 'chessplay' 'advantage' 'offense' 'good'>>
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
	<<actCLA 'Play aggressively'>>
		<!-- ! this works as the opposite of conservative play-->
		<!-- ! aggressive wins against defense and tactical-->
		<!-- ! aggressive loses to offense and trap-->
		<!-- ! aggressive ties with conservative and aggressive-->
		<<if getvar("$chessM") <= 1>>
			<<image "locations/pavlovsk/community/chess/conservative#.jpg" 1 1>>
			$chess_name + ' plays conservatively and their defenses manage to hold you off.'
			Neither of you gain an advantage from this move.
		<<elseif getvar("$chessM") <= 3>>
			<<image "locations/pavlovsk/community/chess/defensive#.jpg" 1 1>>
			$chess_name + ' plays defensively and you overwhelm a few of their pieces.'
			<<gs 'chessplay' 'advantage' 'aggressive' 'good'>>
		<<elseif getvar("$chessM") <= 5>>
			<<image "locations/pavlovsk/community/chess/tactical#.jpg" 1 1>>
			$chess_name + ' plays tactically and cannot cope with your aggressive moves.'
			<<gs 'chessplay' 'advantage' 'aggressive' 'good'>>
		<<elseif getvar("$chessM") <= 7>>
			<<image "locations/pavlovsk/community/chess/trap#.jpg" 1 1>>
			$chess_name + ' tries to trap you, but some of your pieces fall for it.'
			<<gs 'chessplay' 'advantage' 'aggressive' 'bad'>>
		<<elseif getvar("$chessM") <= 9>>
			<<image "locations/pavlovsk/community/chess/offensive#.jpg" 1 1>>
			$chess_name + ' plays offensively, leaving some of your pieces exposed.'
			<<gs 'chessplay' 'advantage' 'aggressive' 'bad'>>
		<<elseif getvar("$chessM") <= 11>>
			<<image "locations/pavlovsk/community/chess/aggressive#.jpg" 1 1>>
			$chess_name + ' also plays aggressively.'
			Neither of you gain an advantage from this move.
		<</if>>
		'You are on move '+str(chess_move)+' out of '+str(chess_move_limit)
		'You are on minute '+str(total_chess_time)+' out of '+str(chess_time_limit)
		<<set $chess_GG -= 1>>
		<<set $chess_com -= 1>>
		<<gs 'chessplay' 'game'>>
	<</actCLA>>
<</if>>
<!-- ! $ARGS[1] = move chosen by player - used to set base skill difference and advantage change-->
<!-- ! $ARGS[2] = whether this move was a good choice - whether Sveta should gain or lose advantage-->
<<if $location_var[$here][0] == 'advantage'>>
	<!-- ! conservative and aggressive are the most extreme and therefore have the biggest reward and risk-->
	<!-- ! but also requires the greatest difference in skill to pull off successfully or prevent your opponent from using successfully-->
	<<if $location_var[$here][1] == 'conservative' or $location_var[$here][1] == 'aggressive'>>
		<<set $chess_pos = 4>>
		<<set $chess_neg = -4>>
		<<set $chess_adv = 4>>
		<!-- ! defense and offense are a middle ground and have medium reward and risk-->
		<!-- ! requires a medium skill gap to pull off successfully or prevent your opponent from using successfully-->
	<<elseif $location_var[$here][1] == 'defense' or $location_var[$here][1] == 'offense'>>
		<<set $chess_pos = 2>>
		<<set $chess_neg = -2>>
		<<set $chess_adv = 2>>
		<!-- ! tactical and trap are the least extreme and therefore have the least reward and risk-->
		<!-- ! they require the least difference in skill to pull off successfully or prevent your opponent from using successfully-->
	<<elseif $location_var[$here][1] == 'tactical' or $location_var[$here][1] == 'trap'>>
		<<set $chess_pos = 1>>
		<<set $chess_neg = -1>>
		<<set $chess_adv = 1>>
	<</if>>
	<<if $location_var[$here][2] == 'good'>>
		<<if $chess_ind > $chess_pos>>
			You are less skilled than your opponent and cannot capitalize on your advantage.
			Try to gain more skill at chess to use this move successfully against this opponent.
		<<elseif $chess_ind < $chess_neg>>
			You are more skilled than your opponent and gain a major advantage.
			<<set $chess_GG = $chess_GG + $chess_adv + $chess_diff>>
			<<set $chess_com = $chess_com - $chess_adv - $chess_diff>>
		<<else>>
			You are about equally skilled as your opponent and gain some advantage.
			<<set $chess_GG = $chess_GG + $chess_adv / 2 + $chess_diff / 2>>
			<<set $chess_com = $chess_com - $chess_adv / 2 - $chess_diff / 2>>
		<</if>>
	<<elseif $location_var[$here][2] == 'bad'>>
		<<if $chess_ind > $chess_pos>>
			You are less skilled than your opponent and you lose a major advantage.
			Try to gain more skill at chess to prevent your opponent from using this move successfully.
			<<set $chess_GG = $chess_GG - $chess_adv - $chess_diff>>
			<<set $chess_com = $chess_com + $chess_adv + $chess_diff>>
		<<elseif $chess_ind < $chess_neg>>
			You are more skilled than your opponent and prevent them from capitalizing on their advantage.
		<<else>>
			You are about equally skilled as your opponent and you lose some advantage.
			<<set $chess_GG = $chess_GG - $chess_adv / 2 - $chess_diff / 2>>
			<<set $chess_com = $chess_com + $chess_adv / 2 + $chess_diff / 2>>
		<</if>>
	<</if>>
<</if>>
