/*
	Exo Regen
	Author: Keith Evans
	Description: A piece of equipment used to give you temporarily increased speed
*/

#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;
#include common_scripts\utility;
#include maps\mp\gametypes\_hostmigration;
#include maps\mp\perks\_perkfunctions;

CONST_EXO_REGEN_DURATION = 10;

watchFastHealUsage()
{
	self endon( "spawned_player" );
	self endon( "disconnect" );
	self endon( "death" );
	self endon( "faux_spawn" );
	
	if(!IsDefined(level.fastHealSettings))
	{
		FastHealInit();
	}
	
	while ( 1 )
	{
		self waittill( "grenade_fire", grenade, weapname );
		if ( weapname == "fast_heal_mp" )
		{
			if( !IsAlive( self ) )
			{
				grenade delete();
				return;
			}
			
			thread tryUseFastHeal();
		}
	}
}

FastHealInit()
{
	self.fastHealSettings = SpawnStruct();
}

tryUseFastHeal( ) // self == player
{
	// Force init (this is for test bots)
	if(!IsDefined(self.fastHealSettings))
	{
		FastHealInit();
	}
	
	//thread PrintHealthToScreen();
	
	ResetFastHeal();
	thread StartFastHeal();
	thread MonitorPlayerDeath();
	
	return true;
}

StartFastHeal()
{
	self endon("ClearFastHeal");
	self endon("death");
	
	//temp activation sound
	self playLocalSound( "earn_superbonus" );
	
	//temp hud overlay
	self.fastHealSettings.overlay = NewClientHudElem( self );
	self.fastHealSettings.overlay.x = 0;
	self.fastHealSettings.overlay.y = 0;
	self.fastHealSettings.overlay.horzAlign = "fullscreen";
	self.fastHealSettings.overlay.vertAlign = "fullscreen";
	self.fastHealSettings.overlay SetShader( "exo_hud_cloak_overlay", 640, 480 );
	self.fastHealSettings.overlay.archive = true;
	self.fastHealSettings.overlay.alpha = 1.0;
	
	self.IsFastHeal = true;
	self.ignoreRegenDelay = true;
	
	//Faster Heal
	self.healthRegenLevel = .99;
	self notify("damage");
	
	wait CONST_EXO_REGEN_DURATION;
	
	self.healthRegenLevel = undefined;
	
	self.IsFastHeal = false;
	
	if( IsDefined( self.fastHealSettings.overlay ) )
		self.fastHealSettings.overlay Destroy();
	
	self notify("EndFastHeal");
}

ResetFastHeal()
{
	if(IsDefined(self.IsFastHeal) && self.IsFastHeal == true)
	{
		if( IsDefined( self.fastHealSettings.overlay ) )
			self.fastHealSettings.overlay Destroy();
		
		self.healthRegenLevel = undefined;
		self notify("ClearFastHeal");
	}
}


MonitorPlayerDeath( )
{
	self endon( "EndFastHeal" );
	
	self waittill(	"death" );
	
	self.healthRegenLevel = undefined;
	self.IsFastHeal = false;
	
	if( IsDefined( self.fastHealSettings.overlay ) )
		self.fastHealSettings.overlay Destroy();
}

PrintHealthToScreen()
{
	self endon("EndFastHeal");
	self endon("death");
	
	while(true)
	{
		IPrintLnBold(self.health);
		wait 1;
	}
}
