#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "effects.h"
#include "aura.h"
#include "classes.h"
#include "magicattack.h"
#include "player.h"
#include "animation.h"
#include "decals.h"
#include "effects.h"
#include "customentity.h"

/**
* Regeneration
* @version 8-6-2001
* @author Herwin 'harSens' van Welbergen
*/
class CRegeneration:public CBasePlayerWeapon
{	
public:
	/**
	* Init function
	*/
	void Spawn( void );

	/**
	* Precaches sprites and sounds
	*/
	void Precache( void );

	/**
	* Get regeneration slot
	* return int: the slot, is 7 for regeneration
	*/
	int iItemSlot( void ) { return 7; }

	/**
	* Get regeneration item info
	* @param ItemInfo *p: The ItemInfo gets stored here
	* @return int: Always returns 1 (why???)
	*/
	int GetItemInfo(ItemInfo *p);

	/**
	 * Deploys attack
	 */
	BOOL Deploy();

	/**
	* regenerates
	*/
	void PrimaryAttack( void );


	/**
	* Holsters the eyelaser
	* @param int skiplocal: ??
	*/
	void Holster(int skiplocal);

	/**
	* Weapon idle function
	*/
	void WeaponIdle();	
private:
	
};

LINK_ENTITY_TO_CLASS( weapon_regeneration, CRegeneration );

void CRegeneration::Spawn( void )
{	Precache();
	m_iId = WEAPON_REGENERATION;
	m_iDefaultAmmo = 0;
	m_iClip = -1;
	FallInit();// get ready to fall down.
}

void CRegeneration::Precache( void )
{	PRECACHE_SOUND("weapons/regen.wav");
}

int CRegeneration::GetItemInfo(ItemInfo *p)
{	p->pszName = STRING(pev->classname);
	p->pszAmmo1 = "ki";
	p->iMaxAmmo1 = -1;	//max ammo is weapon independent
	p->pszAmmo2 = NULL;
	p->iMaxAmmo2 = -1;
	p->iMaxClip = WEAPON_NOCLIP;
	p->iSlot = 6;
	p->iPosition = 1;
	p->iId = m_iId = WEAPON_REGENERATION;
	p->iWeight = REGENERATION_WEIGHT;
	p->iFlags = 0;
	return 1;
}

BOOL CRegeneration::Deploy( void )
{	
	return DefaultDeploy( "regeneration" );	
}

void CRegeneration::WeaponIdle()
{	
	if(m_pPlayer->m_fCharging)
	{
		m_pPlayer->m_fCharging = false;
		m_pPlayer->m_flSlowDown = 1.0;
		// Added by Pcjoe: Stop sound
		EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);
	}
}

void CRegeneration::Holster(int skiplocal)
{	
	if(m_pPlayer->m_fCharging)
	{
		m_pPlayer->m_fCharging = false;
		m_pPlayer->m_flSlowDown = 1.0;
		// Added by Pcjoe: Stop sound
		EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);
	}
}

void CRegeneration::PrimaryAttack( void )
{	// Check we have some ammo
	if (m_pPlayer->UseKi(REGENERATION_KI_COST))
	{
		if(!m_pPlayer->m_fCharging)
		{	m_pPlayer->m_fCharging = true;
			m_pPlayer->m_flSlowDown = REGENERATION_PLAYERSLOWDOWN;	
			// Added by Pcjoe: Emit sound
			EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "weapons/regen.wav", 1.0, ATTN_NORM);

		}

		m_pPlayer->pev->health+=REGENERATION_HEALTHGAIN;
		if(m_pPlayer->pev->health>m_pPlayer->m_iMaxHealth)
		{	m_pPlayer->pev->health=m_pPlayer->m_iMaxHealth;
		}
	}
	// Edited by Pcjoe
	m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.6;
}
	
