#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "soundent.h"
#include "decals.h"
#include "effects.h"
#include "aura.h"
#include "classes.h"
#include "magicattack.h"
#include "explodingattack.h"
#include "player.h"
#include "gamerules.h"
#include "magicattack.h"
#include "discattack.h"
// Added by Pcjoe
#include "blob.h"

extern int gmsgRemoveDisc;

void CDiscAttack::Spawn()
{	m_fReleased = true;
	m_fRemoved = false;
	CMagicAttack::Spawn();
}

/*
do damage to entity hit and move on
used by discs
*/
void CDiscAttack::HitTouch( CBaseEntity *pOther )
{	entvars_t *pevOwner;
	if (pev->owner)
	{	pevOwner=VARS(pev->owner);
	}
	else
	{	pevOwner=NULL;
	}

	//don't hit the one who fired the thing
	if (pevOwner==pOther->pev)
	{	return;			
	}

	//don't hit someone twice in a row
	//if (m_pPreviousHit != pOther)
	{	m_pPreviousHit = pOther;
		if (pOther->IsPlayer())
		{	CBasePlayer *pVictim = (CBasePlayer*)pOther;
			if ( pVictim->m_fPowerStruggling 
				|| pVictim->m_fBlockStruggleAttacker
				|| pVictim->m_fBlockStruggling 
				|| pVictim->m_Melee.m_eThrowStatus == THROW_LAY
				|| pVictim->m_Melee.m_eThrowStatus == THROW_LANDRECOVER
			)			
			{	Vaporize();
			}
			else
			{	pOther->TakeDamage(pev,pevOwner,pev->dmg,DMG_MAGIC);
				EMIT_SOUND(ENT(pev),CHAN_VOICE,"weapons/disckill.wav",1.0, ATTN_NORM);
			}
		}
	}
}

void CDiscAttack::Vaporize( void )
{	if(m_fReleased)
	{	Remove();
	}
	else
	{	m_fRemoved=true;
	}
	return;
}

/*
* Pcjoe: Aura Check
*/
void CDiscAttack::AuraCheck( void )
{	// Dont bother with released projectiles
	if(m_fReleased)
	{	return;
	}
	// Get Owner
	CBasePlayer *pOwner = NULL;
	if (pev->owner)
	{	pOwner = (CBasePlayer*)CBaseEntity::Instance(ENT(pev->owner));
		if(!pOwner)
		{	return;
		}
	}
	else
	{	return;
	}

	// Set movetype accordingly
	if(pOwner->m_pAura && pev->movetype == MOVETYPE_NOCLIP)
	{	pev->movetype = MOVETYPE_FOLLOW;
		pev->aiment = pev->owner;
	}
	else if(!pOwner->m_pAura && pev->movetype == MOVETYPE_FOLLOW)
	{	pev->movetype = MOVETYPE_NOCLIP;
		pev->aiment = NULL;
	}
	pev->nextthink = gpGlobals->time;
}

void CDiscAttack::Remove()
{	CMagicAttack::Remove();
	STOP_SOUND(ENT(pev), CHAN_WEAPON, "weapons/rotating.wav");
}