:: KGOLfight
<<set $here = 'KGOLfight'>>
<<set $ARGS = $location_var[$here]>>
<<set $time.minutes += 1>>
<<if getvar("$otkathirki") > 0>>
	<<setn $otkathirki -= 1>>

<</if>>
<<if $KGHP < $KGHPMAX and getvar("$KGOLhirka") > 0 and getvar("$otkathirki") <= 0>>
	<<set $kghneed = $KGHPMAX - $KGHP>>
	<<set $otkathirki = 3>>
	<<if $KGOLhirka >= $kghneed>>
		<<set $KGOLhirka -= $kghneed>>
		<<set $KGHP = $KGHPMAX>>
	<<else>>
		<<set $KGHP = $KGOLhirka>>
		<<set $KGOLhirka = 0>>
	<</if>>
<</if>>
<<if getvar("$KGOLdist") < 0>>
	<<set $KGOLdist = 0>>

<</if>>
<<if getvar("$KGOLtimer") > 0>>
	<<set $KGOLtimer -= 1>>
	<<if getvar("$KGOLtimer") <= 0>>
		<<set $KGOLbrona -= $KGOLbronaMod>>
		<<set $KGOLbronaMod = 0>>
		<<set $KGOLstren -= $KGOLstrenMod>>
		<<set $KGOLstrenMod = 0>>
		<<set $KGOLspeed -= $KGOLspeedMod>>
		<<set $KGOLspeedMod = 0>>
		<<set $KGOLvital -= $KGOLvitalMod>>
		<<set $KGOLvitalMod = 0>>
		<<set $KGOLintel -= $KGOLintelMod>>
		<<set $KGOLintelMod = 0>>
		<<set $KGOLwpower -= $KGOLwpowerMod>>
		<<set $KGOLwpowerMod = 0>>
	<</if>>
<</if>>
<<if getvar("$unvis") > 0>>
	You are invisible

<</if>>
<<if getvar("$poison") > 0>>
	<<setn $poison -= 1>> <<set $KGHPV -= $KGOLspell4 * 10>> 

<</if>>
<<if getvar("$firecircle") > 0>>
	<<setn $firecircle -= 1>> <<set $KGHPV -= $KGOLspell9 * 50>> 

<</if>>
Life <<KGHP>>, the mana <<KGMana>>
<<$KGname>> Life <<KGHPV>>mana <<KGManaV>>
<<if getvar("$KGOLhirka") > 0>>
	Hirka can restore automatically <<KGOLhirka>> health units

<</if>>
<<if getvar("$otkathirki") > 0>>
	Hirka retrace through <<otkathirki>> moves.

<</if>>
Distance <<KGOLdist>>
<<if getvar("$KGOLtimer") > 0>>
	Obkast will act more <<KGOLtimer>> Rounds

<</if>>
<<if getvar("$KGOLcooldown") > 0>>
	Rollback skills completed by <<KGOLcooldown>> Rounds

<</if>>
<!-- !!end of fight-->
<<if getvar("$KGHP") <= 0>>
	<<set $KGOLloss += 1>>
	<<set $poison = 0>>
	<<set $firecircle = 0>>
	<<set $pcs_mana -= 100>>
	You lost the fight
	<<act 'Go to Rep.'>>
		<<gt 'KGOLgame'>>
	<</act>>
	$exit
<</if>>
<<if getvar("$KGHPV") <= 0>>
	<<set $poison = 0>>
	<<set $firecircle = 0>>
	<<set $KGOLWin += 1>>
	<<set $KGOLmoney += $KGOLPrizeM>>
	<<set $KGOLexp += $KGOLPrizeExp>>
	<<set $pcs_mana += 100>>
	<p>$KGname fell. You win the fight.</p>
	You got <<KGOLPrizeM>> coins and <<KGOLPrizeExp>> experience
	<<if getvar("$KGOLennumBoss") == 1 and getvar("$boss5lvl") == 0>>
		<<set $boss5lvl = 1>> <<setn $KGOLhirka += 5000>> 

	<</if>>
	<<if getvar("$KGOLennum") == 0 and getvar("$KGOLmqw") == 1>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 1 and getvar("$KGOLmqw") == 3>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 2 and getvar("$KGOLmqw") == 5>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 3 and getvar("$KGOLmqw") == 7>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 4 and getvar("$KGOLmqw") == 9>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 5 and getvar("$KGOLmqw") == 11>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<if getvar("$KGOLennum") == 6 and getvar("$KGOLmqw") == 13>>
		<<setn $KGOLqwvip += 1>> 

	<</if>>
	<<act 'Disengage'>>
		<<gt 'KGOLgame'>>
	<</act>>
	$exit
<</if>>
<!-- !!initiative-->
<<set $KGOLiniV = rand(KGOLspeedV / 2, KGOLspeedV * 2)>>
<<set $KGOLini = rand(KGOLspeed / 2, KGOLspeed * 2)>>
<<if $KGOLini == $KGOLiniV>>
	<<set $hodrand = rand(0, 1)>>
	<<if getvar("$hodrand") == 0>>
		<<set $KGOLini = 1>> <<set $KGOLiniV = 0>>

	<</if>>
	<<if getvar("$hodrand") == 1>>
		<<set $KGOLini = 0>> <<set $KGOLiniV = 1>>

	<</if>>
<</if>>
<<if $KGOLini > $KGOLiniV>>
	<<setn $KGOLiniSUM += 1>>

<</if>>
<<if $KGOLini < $KGOLiniV>>
	<<setn $KGOLiniSUM -= 1>>

<</if>>
<<if getvar("$KGOLiniSUM") > 3>>
	<<set $KGOLini = 0>> <<set $KGOLiniV = 1>> <<set $KGOLiniSUM = 0>>

<</if>>
<<if getvar("$KGOLiniSUM") < -3>>
	<<set $KGOLini = 1>> <<set $KGOLiniV = 0>> <<set $KGOLiniSUM = 0>>

<</if>>
<!-- !!moves-->
<<if $KGOLini > $KGOLiniV or getvar("$unvis") > 0>>
	Now your turn
	<<if getvar("$KGOLklass") == 1>>
		<!-- !!warrior-->
		<<if getvar("$KGOLdist") < 3>>
			<<actCLA 'Attack'>>
				<<set $KGOLpower = $KGOLstren + $KGOLwpower>>
				<<KGOLatk>>
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
			<<if getvar("$KGOLspell") > 0 and $KGMana >= $KGOLspell * 10>>
				<<actCLA 'Powerful blow (KGOLspell * 10 mana)'>>
					<<set $KGMana -= $KGOLspell>>
					<<set $KGOLpower = $KGOLstren + $KGOLwpower + ($KGOLspell * 100)>>
					<<KGOLatk>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
			<<if getvar("$KGOLspell2") > 0 and $KGMana >= $KGOLspell2 * 10>>
				<<actCLA 'Multiple shot (KGOLspell2 * 10 mana)'>>
					<<set $KGMana -= $KGOLspell2>>
					<<set $KGOLpower = $KGOLstren + $KGOLwpower>>
					<<set $KGLOloop = $KGOLspell2 + 1>>
					<<KGOLatkKGOLspell2>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
			<<if getvar("$KGOLspell3") > 0 and $KGMana >= $KGOLspell3 * 10 and getvar("$KGOLcooldown") <= 0>>
				<<actCLA 'Increase armor (KGOLspell3 * 10 mana)'>>
					<<set $KGMana -= $KGOLspell3>>
					<<set $KGOLbronaMod += $KGOLspell3 * 5>>
					<<set $KGOLtimer += $KGOLspell3 + 1>>
					<<set $KGOLcooldown += $KGOLspell3 + 3>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
		<</if>>
	<<elseif getvar("$KGOLklass") == 2>>
		<!-- !!thief-->
		<<if getvar("$KGOLdist") < 5>>
			<<actCLA 'Attack'>>
				<<set $KGOLpower = $KGOLstren + $KGOLwpower>>
				<<KGOLatk>>
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
			<<if getvar("$KGOLspell4") > 0 and $KGMana >= $KGOLspell4 * 10>>
				<<actCLA 'Sneaky shot (KGOLspell4 * 10 mana)'>>
					<<set $KGMana -= $KGOLspell4>>
					<<set $KGOLpower = $KGOLstren + $KGOLwpower + ($KGOLspell5 * 100)>>
					<<KGOLatk>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
			<<if getvar("$KGOLspell5") > 0 and $KGMana >= $KGOLspell5 * 10>>
				<<actCLA 'Poison Blade (KGOLspell5 * 10mana)'>>
					<<set $KGMana -= $KGOLspell5>>
					<<set $KGOLpower = $KGOLstren + $KGOLwpower>>
					<<KGOLatkPoison>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
			<<if getvar("$KGOLspell6") > 0 and $KGMana >= $KGOLspell6 * 10 and getvar("$KGOLcooldown") <= 0>>
				<<actCLA 'Invisibility (KGOLspell6 * 10 mana)'>>
					<<set $KGMana -= $KGOLspell6>>
					<<set $unvis += $KGOLspell6 + 1>>
					<<set $KGOLcooldown += $KGOLspell6 + 3>>
					<<actCLA 'Further'>>
						<<gt $curloc>>
					<</actCLA>>
				<</actCLA>>
			<</if>>
		<</if>>
	<<elseif getvar("$KGOLklass") == 3>>
		<!-- !!magican-->
		<<actCLA 'Attack'>>
			<<set $KGOLpower = $KGOLintel + $KGOLwpower>>
			<<KGOLatk>>
			<<actCLA 'Further'>>
				<<gt $curloc>>
			<</actCLA>>
		<</actCLA>>
		<<if getvar("$KGOLspell7") > 0 and $KGMana >= $KGOLspell7 * 10>>
			<<actCLA 'Faerboll (KGOLspell7 * 10 mana)'>>
				<<set $KGMana -= $KGOLspell7>>
				<<set $KGOLpower = rand(KGOLspell7 * 100, KGOLspell7 * 200)>>
				<<KGOLatkFB>>
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
		<</if>>
		<<if getvar("$KGOLspell8") > 0 and $KGMana >= $KGOLspell8 * 10>>
			<<actCLA 'Dropping (KGOLspell5 * 10 mana)'>>
				<<set $KGMana -= $KGOLspell5>>
				<<set $KGOLdist += rand(KGOLspell5 * 10, KGOLspell5 * 50)>>
				You flung the enemy and now the distance between you <<KGOLdist>> meter
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
		<</if>>
		<<if getvar("$KGOLspell9") > 0 and $KGMana >= $KGOLspell9 * 10 and getvar("$KGOLcooldown") <= 0>>
			<<actCLA 'Circle of fire (KGOLspell9 * 10 mana)'>>
				<<set $KGMana -= $KGOLspell9>>
				<<set $firecircle += $KGOLspell9 + 1>>
				<<set $KGOLcooldown += $KGOLspell9 + 3>>
				Everything around you is burning hellfire
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
		<</if>>
	<<elseif getvar("$KGOLklass") == 4>>
		<!-- !!priest-->
		<<actCLA 'Attack'>>
			<<set $KGOLpower = $KGOLintel + $KGOLwpower>>
			<<KGOLatk>>
			<<actCLA 'Further'>>
				<<gt $curloc>>
			<</actCLA>>
		<</actCLA>>
	<<elseif getvar("$KGOLklass") == 5>>
		<!-- !!archer-->
		<<actCLA 'Attack'>>
			<<set $KGOLpower = $KGOLspeed + $KGOLwpower>>
			<<KGOLatk>>
			<<actCLA 'Further'>>
				<<gt $curloc>>
			<</actCLA>>
		<</actCLA>>
	<<else>>
		<!-- !!barbarian-->
		<<if getvar("$KGOLdist") < 2>>
			<<actCLA 'Attack'>>
				<<set $KGOLpower = $KGOLstren + $KGOLwpower>>
				<<KGOLatk>>
				<<actCLA 'Further'>>
					<<gt $curloc>>
				<</actCLA>>
			<</actCLA>>
		<</if>>
	<</if>>
	<<if getvar("$KGOLdist") > 0>>
		<<actCLA 'Flee to the enemy'>>
			<<set $KGOLdist -= rand(KGOLspeed/20, KGOLspeed/10)>>
			<<gt $curloc>>
		<</actCLA>>
	<</if>>
	<<actCLA 'Flee from the enemy'>>
		<<set $KGOLdist += rand(KGOLspeed/20, KGOLspeed/10)>>
		<<gt $curloc>>
	<</actCLA>>
	<<if getvar("$KGOLpotionH") > 0>>
		<<actCLA 'Drink a health potion'>>
			<<set $KGOLpotionH -= 1>>
			<<set $KGHP += 100>>
			<<gt $curloc>>
		<</actCLA>>
	<</if>>
	<<if getvar("$KGOLpotionM") > 0>>
		<<actCLA 'Drink the potion mana'>>
			<<set $KGOLpotionM -= 1>>
			<<set $KGMana += 100>>
			<<gt $curloc>>
		<</actCLA>>
	<</if>>
<<else>>
	Now opponents
	<<if $KGOLdist <= $KGOLneedDist>>
		<p>$KGname attacks you</p>
		<<KGOLatkV>>
	<<else>>
		<<set $KGOLdist -= rand(KGOLspeedV/20, KGOLspeedV/10)>>
		<p>$KGname running toward you</p>
	<</if>>
	<<actCLA 'Further'>>
		<<gt $curloc>>
	<</actCLA>>
<</if>>
