:: beverage[event]

<<set _beverage = setup.Consumable.get($larg(0))>>


<<addtime _beverage.time>>

<<if typeof _beverage.image === 'object'>>
	<<image _beverage.image.template _beverage.image.min _beverage.image.max>>
<<else>>
	<<image _beverage.image>>
<</if>>

<p>_beverage.desc</p>

<<switch _beverage.type>>
	<<case 'candy'>>
		<<consume _beverage>>
		<<ret 'Finish'>>
	<<case 'drink'>>
		<<consume _beverage>>
		<<ret 'Finish'>>
	<<case 'meal'>>
		
		<p>
			<<if _beverage.energy <= 0.5>>
				This food provides you with a way lower than average amount of calories.
			<<elseif _beverage.energy <= 0.8>>
				This food provides you with a lower than average amount of calories.
			<<elseif _beverage.energy < 1>>
				This food provides you with a slightly lower than average amount of calories.
			<<elseif _beverage.energy == 1>>
				This food provides you with an average amount of calories.
			<<elseif _beverage.energy >= 2>>
				This food provides you with a massive amount of calories.
			<<elseif _beverage.energy >= 1.5>>
				This food provides you with a way above average amount of calories.
			<<elseif _beverage.energy >= 1.2>>
				This food provides you with an above average amount of calories.
			<<else>>
				This food provides you with a slightly above average amount of calories.
			<</if>>
			<<if _beverage.thirst === Infinity>>
				During eating you drink enough tap water to eliminate your thirst.
			<</if>>
		</p>

		<<set _percentageToEatToMaxHunger = (100 - $pc.pcs_energy) / _beverage.hunger * 100>>

		<<if _percentageToEatToMaxHunger <= 100>>
			<<act `'Eat til you are fed up ('+_percentageToEatToMaxHunger.roundToDecimal(1)+'% of the food)'`>>
				<<consume _beverage _percentageToEatToMaxHunger>>
				<<gt $location>>
			<</act>>
		<<else>>
			<<set _effectOf100P = $pc.pcs_energy + _beverage.hunger>>

			<<set _servingsRequired = _percentageToEatToMaxHunger/100>>
			<<set _servingsAvailable = _beverage.servings ?? 1>>
			<<if _beverage.repeat == 'direct' || _servingsAvailable >= _servingsRequired>>
				<<act `'Eat enough portions to get you fed up ('+(_percentageToEatToMaxHunger/100).roundToDecimal(1)+' portions)'`>>
					<<consume _beverage _percentageToEatToMaxHunger>>
					<<gt $location>>
				<</act>>
			<<elseif _servingsAvailable > 1>>
				<<act `'Eat '+_servingsAvailable+' complete portions (reduces hunger to '+($pc.pcs_energy + _beverage.hunger*_servingsAvailable).roundToDecimal(1)+')'`>>
					<<consume _beverage `100*_servingsAvailable`>>
					<<gt $location>>
				<</act>>
			<</if>>
			<<act `'Eat one complete portion (reduces hunger to '+_effectOf100P.roundToDecimal(1)+')'`>>
				<<consume _beverage 100>>
				<<gt $location>>
			<</act>>
		<</if>>

		<<set _effectOf75P = $pc.pcs_energy + _beverage.hunger * 0.75>>
		<<set _effectOf50P = $pc.pcs_energy + _beverage.hunger * 0.50>>
		<<set _effectOf25P = $pc.pcs_energy + _beverage.hunger * 0.25>>

		<<if _percentageToEatToMaxHunger > 75>>
			<<act `'Eat 3/4 of the portion (reduces hunger to '+_effectOf75P.roundToDecimal(1)+')'`>>
				<<consume _beverage 75>>
				<<gt $location>>
			<</act>>
		<</if>>

		<<if _percentageToEatToMaxHunger > 50>>
			<<act `'Eat 1/2 of the portion (reduces hunger to '+_effectOf50P.roundToDecimal(1)+')'`>>
				<<consume _beverage 50>>
				<<gt $location>>
			<</act>>
		<</if>>

		<<if _percentageToEatToMaxHunger > 25>>
			<<act `'Eat 1/4 of the portion (reduces hunger to '+_effectOf25P.roundToDecimal(1)+')'`>>
				<<consume _beverage 25>>
				<<gt $location>>
			<</act>>
		<</if>>
<</switch>>

<<for _moodletId range _beverage.moodletIds>>
	<<moodDisplay _moodletId>>
<</for>>
