void cEndCasting::Expire()
{
	P_PLAYER pMage = dynamic_cast<P_PLAYER>( FindCharBySerial( destSer ) );
	
	if( !pMage )
		return;

	pMage->setCasting( false );
	//pMage->stopRepeatedAction();

	P_PLAYER pp = dynamic_cast<P_PLAYER>(pMage);
	if( !pp->socket() )
		return;

	// Show a target cursor *or* cast directly
	stNewSpell *sInfo = NewMagic->findSpell( spell );
	if( !sInfo->targets )
	{
		NewMagic->execSpell( pp, spell, type );
	}
	else
		pp->socket()->attachTarget( new cSpellTarget( pp, spell, type ) );
}
void cNewMagic::castSpell( P_PLAYER pMage, UINT8 spell )
{
	P_PLAYER pp = dynamic_cast<P_PLAYER>(pMage);

	if( !pp || !pp->socket() )
		return;

	stNewSpell *sInfo = findSpell( spell );

	if( !sInfo )
	{
		pp->socket()->sysMessage( tr( "This spell is either not implemented or invalid" ) );
		return;
	}

	// Check if we can cast this spell
	if( !hasSpell( pMage, spell ) )
	{
		pp->socket()->sysMessage( tr( "You don't know this spell." ) );
		return;
	}

	// Check for required mana and required reagents, if not present: cancel casting
	if( !checkMana( pMage, spell ) )
	{
		pp->message( tr( "You don't have enough mana to cast this spell." ) );
		return;
	}
	
	if( !pp->isGM() && !checkReagents( pMage, spell ) )
		return;

	if( pMage->isCasting() )
		disturb( pMage, true );

	// We start casting here
	pMage->setCasting( true );

	// We get frozen here too
	pMage->setFrozen( true );

	// Say the mantra
	// Type 0x0A : Spell
	pMage->talk( sInfo->mantra, pMage->saycolor() );

	// This is a very interesting move of OSI 
	// They send all action-packets the character has to perform in a row. 
	// But they use the action 0xE9 instead of 0x10, maybe it's a bitmask 
	// of 0xD9 but i am unsure. 
	// This will repeat the animation until
	// We are done casting or until we are being
	// disturbed.
	//pMage->startRepeatedAction( sInfo->action, sInfo->actiondelay ); // Repeat every 1250 ms
	// I *do* know that this is a drawback but for now a single animation is exactly what we need.
	pMage->action( sInfo->action );

	// Now we have to do the following: 
	// We show the target cursor after a given amount of time (set in the scripts)
	// So what we are adding here is cEndCasting() supplying the Serial of our Mage 
	// And the ID of our Spell.
	TempEffects::instance()->insert( new cEndCasting( pMage, spell, CT_BOOK, sInfo->delay ) );
}