#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "candy.h"
#include "monsters.h"
#include "nodes.h"
#include "effects.h"
#include "aura.h"
#include "classes.h"
#include "magicattack.h"
#include "explodingattack.h"
#include "player.h"
#include "gamerules.h"

LINK_ENTITY_TO_CLASS( candy, CCandy );

void CCandy::Spawn()
{	Precache();
	pev->movetype = MOVETYPE_FLY;
	pev->solid = SOLID_TRIGGER;
	pev->classname = MAKE_STRING("candy");
}

void CCandy::Precache()
{	PRECACHE_MODEL("models/chocolate.mdl");
	PRECACHE_MODEL("models/cookie.mdl");
	PRECACHE_MODEL("models/donut.mdl");
	PRECACHE_SOUND("buu/candyeat.wav");
	PRECACHE_SOUND("fatbuu/candyeat.wav");
}

void CCandy::Touch(CBaseEntity *pOther)
{	entvars_t *pevOwner;
	if (pev->owner)
	{	pevOwner=VARS(pev->owner);
	}
	else
	{	pevOwner=NULL;
	}

	//don't eat yourself
	if (pevOwner == pOther->pev)
	{	return;	
	}

	if (pOther->IsPlayer())
	{	CBasePlayer *pPlayer = (CBasePlayer*)pOther;
		if (pPlayer->m_pClass->Classify() == PC_BUU)
		{	// get something from the candy here
			GetStuff(pPlayer);
			pPlayer->EmitClassSound("candyeat.wav");
			UTIL_Remove(this);
			return;
		}
	}	
}

CChocolate *CChocolate::CreateChocolate(Vector origin, entvars_t *pevOwner)
{	CChocolate *pChocolate = GetClassPtr( (CChocolate *)NULL );
	pChocolate->Spawn();
	pChocolate->pev->owner = ENT(pevOwner);	
	SET_MODEL(ENT(pChocolate->pev), "models/chocolate.mdl");
	UTIL_SetSize(pChocolate->pev,Vector(-5,-5,0),Vector(5,5,5));
	UTIL_SetOrigin(pChocolate->pev,origin);

	return pChocolate;
}

void CChocolate::GetStuff(CBasePlayer *pPlayer)
{	pPlayer->pev->health += 40;
	if(pPlayer->pev->health>pPlayer->m_iMaxHealth)
	{	pPlayer->pev->health=pPlayer->m_iMaxHealth;
	}
	pPlayer->IncreasePL(50000);
}

CCookie *CCookie::CreateCookie(Vector origin,entvars_t *pevOwner)
{	CCookie *pCookie = GetClassPtr( (CCookie *)NULL );
	pCookie->Spawn();
	pCookie->pev->owner = ENT(pevOwner);
	SET_MODEL(ENT(pCookie->pev), "models/cookie.mdl");
	UTIL_SetSize(pCookie->pev,Vector(-5,-5,0),Vector(5,5,5));
	UTIL_SetOrigin(pCookie->pev,origin);

	return pCookie;
}

void CCookie::GetStuff(CBasePlayer *pPlayer)
{	pPlayer->pev->health = pPlayer->m_iMaxHealth;	
}

CDonut *CDonut::CreateDonut(Vector origin, entvars_t *pevOwner)
{	CDonut *pDonut = GetClassPtr( (CDonut *)NULL );
	pDonut->Spawn();
	pDonut->pev->owner = ENT(pevOwner);	
	SET_MODEL(ENT(pDonut->pev), "models/donut.mdl");
	UTIL_SetSize(pDonut->pev,Vector(-5,-5,0),Vector(5,5,5));
	UTIL_SetOrigin(pDonut->pev,origin);

	return pDonut;
}

void CDonut::GetStuff(CBasePlayer *pPlayer)
{	// Added by Pcjoe, Donut gives 100,000 Pl!
	pPlayer->IncreasePL(100000);	
}
