Exemplo n.º 1
0
void Human_Stablemaster::onSpeechInput( P_PLAYER pTalker, const QString& message )
{
	if ( !pTalker->socket() )
		return;

	if ( m_npc->inRange( pTalker, 4 ) && ( VendorChkName( m_npc, message ) || message.contains( tr( "STABLEMASTER" ) ) ) )
	{
		if ( message.contains( tr( " STABLE" ) ) )
		{
			m_npc->talk( tr( "Which pet do you want me to stable?" ) );
			pTalker->socket()->attachTarget( new cStableTarget( m_npc ) );
		}
		else if ( message.contains( tr( " RELEASE" ) ) )
		{
			int gold = pTalker->countBankGold() + pTalker->countGold();
			P_ITEM pPack = m_npc->getBankbox();
			
			cItem::ContainerContent stableitems;
			if ( pPack )
			{
				cItem::ContainerContent content = pPack->content();
				cItem::ContainerContent::const_iterator it( content.begin() );
				while ( it != content.end() )
				{
					if ( !( *it )->hasTag( "player" ) || !( *it )->hasTag( "pet" ) )
						continue;

					if ( ( *it ) && ( uint )( *it )->getTag( "player" ).toInt() == pTalker->serial() )
						stableitems.push_back( ( *it ) );
					++it;
				}
			}

			if ( !stableitems.empty() )
			{
				cItem::ContainerContent::const_iterator it( stableitems.begin() );
				while ( it != stableitems.end() )
				{
					if ( ( *it ) )
					{
						P_NPC pPet = dynamic_cast<P_NPC>( World::instance()->findChar( ( *it )->getTag( "pet" ).toInt() ) );
						if ( pPet )
						{
							pPet->free = false;
							// we need this for db saves
							pPet->setStablemasterSerial( INVALID_SERIAL );
							pPet->moveTo( m_npc->pos() );
							pPet->resend();
						}
						( *it )->remove();
					}
					++it;
				}

				pPack->update();
				m_npc->talk( tr( "Here's your pet back!" ) );
			}
		}
	}
}
Exemplo n.º 2
0
static bool cont_has_spell( P_ITEM pCont, UINT8 spell )
{
	if( pCont->objectID() == "cSpellBook" )
	{
		cSpellBook *pBook = dynamic_cast< cSpellBook* >( pCont );

		if( pBook )
			return pBook->hasSpell( spell );

		return false;
	}
	else if( pCont->content().size() > 0 )
	{
		cItem::ContainerContent content = pCont->content();
		cItem::ContainerContent::const_iterator iter;
		cItem::ContainerContent::const_iterator end = content.end();
		for( iter = content.begin(); iter != end; ++iter )
			if( cont_has_spell( *iter, spell ) )
				return true;
	}

	return false;
}