当前位置: 首页>>代码示例>>C++>>正文


C++ P_NPC类代码示例

本文整理汇总了C++中P_NPC的典型用法代码示例。如果您正苦于以下问题:C++ P_NPC类的具体用法?C++ P_NPC怎么用?C++ P_NPC使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了P_NPC类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tr

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!" ) );
			}
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:60,代码来源:ai_humans.cpp

示例2: addPet

void cPlayer::addPet( P_NPC pPet, bool noOwnerChange )
{
	if ( !pPet )
		return;

	// It may be the follower of someone else already, so
	// check that...
	if ( pPet->owner() && pPet->owner() != this )
		pPet->owner()->removePet( pPet, true );

	// Only reset the owner if we have slots left
	if ( pets_.size() + pPet->controlSlots() <= maxControlSlots() )
	{
		pPet->setOwner( this, true );

		// Check if it already is our follower
		CharContainer::iterator it = std::find( pets_.begin(), pets_.end(), pPet );
		if ( it != pets_.end() )
			return;

		pets_.push_back( pPet );

		if ( socket_ )
		{
			socket_->sendStatWindow();
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:28,代码来源:player.cpp

示例3: spawnGuard

void cCombat::spawnGuard( P_CHAR pOffender, P_CHAR pCaller, const Coord& pos )
{
	if ( !pOffender || !pCaller )
		return;

	if ( pOffender->isDead() || pCaller->isDead() )
		return;

	cTerritory* pRegion = pCaller->region();

	if ( pRegion == NULL )
		return;

	if ( pRegion->isGuarded() && Config::instance()->guardsActive() )
	{
		QString guardsect = pRegion->getGuardSect();

		P_NPC pGuard = ( guardsect.isNull() ? NULL : cNPC::createFromScript( guardsect, pos ) );

		if ( !pGuard )
			return;

		// Send guard to surrounding Players
		pGuard->resend( false );
		pGuard->soundEffect( 0x1FE );
		pGuard->effect( 0x372A, 0x09, 0x06 );
		pGuard->fight( pOffender );
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:29,代码来源:combat.cpp

示例4: QString

void cSectorMaps::add( cUObject* object )
{
	// Very powerful statement. It completely
	// annihilates the need to check for
	// nullpointers in our object-map
	if ( !object )
		return;

	if ( isItemSerial( object->serial() ) )
	{
		P_ITEM pItem = dynamic_cast<P_ITEM>( object );
		if ( pItem )
		{
			Coord_cl pos = pItem->pos();

			std::map<unsigned char, cSectorMap*>::const_iterator it = itemmaps.find( pos.map );

			if ( it == itemmaps.end() )
				throw QString( "Couldn't find a map with the id %1." ).arg( pos.map );

			it->second->addItem( ( cUObject * ) pItem );

			Timing::instance()->addDecayItem( pItem );
		}
	}
	else if ( isCharSerial( object->serial() ) )
	{
		// This is a safety check to make sure that
		// stabled pets don't appear on our sectormap
		P_NPC npc = dynamic_cast<P_NPC>( object );

		if ( npc && npc->stablemasterSerial() != INVALID_SERIAL )
		{
			return;
		}

		// The same check for players
		/*P_PLAYER player = dynamic_cast<P_PLAYER>( object );

		if ( player && !player->socket() && !player->logoutTime() )
		{
			return;
		}*/

		P_CHAR pChar = dynamic_cast<P_CHAR>( object );
		if ( pChar )
		{
			Coord_cl pos = pChar->pos();

			std::map<unsigned char, cSectorMap*>::const_iterator it = charmaps.find( pos.map );

			if ( it == charmaps.end() )
				throw QString( "Couldn't find a map with the id %1." ).arg( pos.map );

			it->second->addItem( ( cUObject * ) pChar );
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:58,代码来源:sectors.cpp

示例5: PlayerVendorSpeech

bool PlayerVendorSpeech( cUOSocket *socket, P_PLAYER pPlayer, P_NPC pVendor, const QString &comm )
{
/*	if( pVendor->npcaitype() != 17 )
	     return false;*/

	if( pPlayer->dist( pVendor ) > 4 )
		return false;

	if( !VendorChkName( pVendor, comm ) )
		return false;

	if( ( comm.contains( " BROWSE" ) ) || ( comm.contains( " VIEW" ) ) || ( comm.contains( " LOOK" ) ) )
	{
		pVendor->talk( tr( "Take a look at my goods." ) );
		if( pPlayer->socket() )
			pPlayer->socket()->sendContainer( pVendor->getBackpack() );
	    return true;
	}
	
	if( ( comm.contains( " BUY" ) ) || ( comm.contains( " PURCHASE" ) ) )
	{
		// >> LEGACY
		/*addx[s]=pVendor->serial();
		npctalk(s,pVendor,"What would you like to buy?",0);
		target(s,0,1,0,224," ");*/
		return true;
	}

	if( pVendor->owner() != pPlayer )
		return false;

	if( ( comm.contains( " COLLECT" ) ) || ( comm.contains( " GOLD" ) ) || ( comm.contains( " GET" ) ) )
	{
		PlVGetgold( socket, pPlayer, pVendor);
		return true;
	}

	if( comm.contains( "PACKUP" ) )
	{
		P_ITEM pDeed = Items->SpawnItem( pPlayer, 1, "employment deed", 0, 0x14F0, 0, 1 );
		if( pDeed )
		{
			pDeed->setType( 217 );
			pDeed->setBuyprice( 2000 );
			pDeed->setSellprice( 1000 );
			pDeed->update();
			cCharStuff::DeleteChar( pVendor );
			socket->sysMessage( tr( "Packed up vendor %1." ).arg( pVendor->name() ) );
			return true;
		}
	}
	return false;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:53,代码来源:speech.cpp

示例6: RandomNum

// do one spawn and reset the timer
void cSpawnRegion::reSpawn( void )
{
	this->checkForDeleted();

	UI16 i = 0;
	for( i = 0; i < this->npcsPerCycle_; i++ )
	{
		if( this->npcSerials_.size() < this->maxNpcAmt_ )
		{
			// spawn a random npc
			// first find a valid position for the npc
			Coord_cl pos;
			if( this->findValidSpot( pos ) )
			{
				QString NpcSect = this->npcSections_[ RandomNum( 1, this->npcSections_.size() ) - 1 ];
				P_NPC pc = cCharStuff::createScriptNpc( NpcSect, pos );
				if( pc != NULL )
				{
					this->npcSerials_.push_back( pc->serial() );
					pc->setSpawnregion( this->name_ );
				}
			}
		}
	}

	for( i = 0; i < this->itemsPerCycle_; i++ )
	{
		if( this->itemSerials_.size() < this->maxItemAmt_ )
		{
			// spawn a random item
			// first find a valid position for the item
			Coord_cl pos;
			if( this->findValidSpot( pos ) )
			{
				QString ItemSect = this->itemSections_[ RandomNum( 1, this->itemSections_.size() ) - 1 ];
				P_ITEM pi = cItem::createFromScript( ItemSect );
				if( pi != NULL )
				{
					pi->moveTo( pos );
					this->itemSerials_.push_back( pi->serial() );
//					pi->setSpawnRegion( this->name_ );
				}
			}
		}
	}

	this->nextTime_ = uiCurrentTime + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:49,代码来源:spawnregions.cpp

示例7: spawnSingleNPC

void cSpawnRegion::spawnSingleNPC()
{
	Coord_cl pos;
	if ( findValidSpot( pos ) )
	{
		QString NpcSect = this->npcSections_[RandomNum( 1, this->npcSections_.size() ) - 1];
		P_NPC pc = cNPC::createFromScript( NpcSect, pos );
		if ( pc )
		{
			pc->setSpawnregion( this );
			if ( pc->wanderType() == enFreely )
			{
				pc->setWanderType( enWanderSpawnregion );
			}
			pc->update();
			onSpawn( pc );
		}
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:19,代码来源:spawnregions.cpp

示例8: while

void cSpawnRegion::reSpawnToMax( void )
{
	this->checkForDeleted();

	while( this->npcSerials_.size() < this->maxNpcAmt_ )
	{
		// spawn a random npc
		// first find a valid position for the npc
		Coord_cl pos;
		if( this->findValidSpot( pos ) )
		{
			QString NpcSect = this->npcSections_[ RandomNum( 1, static_cast<uint>(this->npcSections_.size()) ) - 1 ];
			P_NPC pc = cCharStuff::createScriptNpc( NpcSect, pos );
			if( pc != NULL )
			{
				this->npcSerials_.push_back( pc->serial() );
				pc->setSpawnregion( this->name_ );
				pc->update();
			}
		}
	}

	while( this->npcSerials_.size() < this->maxNpcAmt_ )
	{
		// spawn a random item
		// first find a valid position for the item
		Coord_cl pos;
		if( this->findValidSpot( pos ) )
		{
			QString ItemSect = this->itemSections_[ RandomNum( 1, this->itemSections_.size() ) - 1 ];
			P_ITEM pi = cItem::createFromScript( ItemSect );
			if( pi != NULL )
			{
				pi->setPos( pos );
				this->itemSerials_.push_back( pi->serial() );
//				pi->setSpawnRegion( this->name_ );
			}
		}
	}

	this->nextTime_ = uiCurrentTime + RandomNum( this->minTime_, this->maxTime_ ) * MY_CLOCKS_PER_SEC;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:42,代码来源:spawnregions.cpp

示例9: QuestionSpeech

// All this Stuff should be scripted
bool QuestionSpeech( cUOSocket *socket, P_PLAYER pPlayer, P_NPC pChar, const QString& comm )
{
	if( !pChar->isHuman() || pPlayer->dist( pChar ) > 3 )
		return false;
	
	// Tell the questioner our name
	if( comm.contains( "NAME" ) )
	{
		pChar->talk( tr( "Hello, my name is %1." ).arg( pChar->name() ) );
		return true;
	}
	
    // say time and the npChar gives the time.
	if( comm.contains( "TIME" ) )
	{
		pChar->talk( tr( "It is now %1" ).arg( uoTime.toString() ) );
		return true;
	}	

	if( comm.contains( "LOCATION" ) )
	{
		cTerritory* Region = pPlayer->region();
		
		if( Region )
			pChar->talk( tr( "You are in %1" ).arg( Region->name() ) );
		else 
			pChar->talk( tr( "You are in the wilderness" ) );
				
		return true;
	}

	// We couldn't handle the speech
	return false;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:35,代码来源:speech.cpp

示例10: response

/////////////////
// name:	response
// purpose:	tries to get a response from an npc standing around
// history:	heavily revamped/rewritten by Duke, Oct 2001
// remark:	The new logic tries to minimize the # of strstr() calls by *first* checking
//			what kind of npcs are standing around and then checking only those keywords
//			that they might be interested in.
//			This is especially usefull in crowded places.
bool Speech::response( cUOSocket* socket, P_PLAYER pPlayer, const QString& comm, QValueVector<Q_UINT16>& keywords )
{
	if ( !pPlayer->socket() || pPlayer->isDead() )
	{
		return false;
	}

	QString speechUpr = comm.upper();

	MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( pPlayer->pos(), 18 );
	for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() )
	{
		P_NPC pNpc = dynamic_cast<P_NPC>( pChar );

		// We will only process NPCs here
		if ( !pNpc )
			continue;

		// at least they should be on the screen
		if ( pPlayer->dist( pNpc ) > 16 )
			continue;

		if ( pNpc->canHandleEvent( EVENT_SPEECH ) )
		{
			PyObject* pkeywords = PyTuple_New( keywords.size() );

			// Set Items
			for ( unsigned int i = 0; i < keywords.size(); ++i )
				PyTuple_SetItem( pkeywords, i, PyInt_FromLong( keywords[i] ) );

			PyObject* args = Py_BuildValue( "(NNNO)", pNpc->getPyObject(), pPlayer->getPyObject(), QString2Python( comm ), pkeywords );

			bool result = pNpc->callEventHandler( EVENT_SPEECH, args );

			Py_DECREF( args );
			Py_DECREF( pkeywords );

			if ( result )
				return true;
		}

		if ( pNpc->ai() )
		{
			pNpc->ai()->onSpeechInput( pPlayer, speechUpr );
		}

		if ( QuestionSpeech( socket, pPlayer, pNpc, speechUpr ) )
			return true;
	}

	return false;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:60,代码来源:speech.cpp

示例11: checkScriptAI

void cAIFactory::checkScriptAI( const QStringList& oldSections, const QStringList& newSections )
{
	QStringList::const_iterator aiit = oldSections.begin();
	for ( ; aiit != oldSections.end(); ++aiit )
	{
		// We must reset all existing and scripted AI objects, so changes can take effect.
		if ( !newSections.contains( *aiit ) )
		{
			cCharIterator iter;
			for ( P_CHAR pChar = iter.first(); pChar; pChar = iter.next() )
			{
				P_NPC pNPC = dynamic_cast<P_NPC>( pChar );
				if ( pNPC )
				{
					ScriptAI* ai = dynamic_cast<ScriptAI*>( pNPC->ai() );
					if ( ai && ai->name() == ( *aiit ) )
					{
						pNPC->setAI( *aiit );
					}
				}
			}
		}
		else
		{
			cCharIterator iter;
			for ( P_CHAR pChar = iter.first(); pChar; pChar = iter.next() )
			{
				P_NPC pNPC = dynamic_cast<P_NPC>( pChar );
				if ( pNPC )
				{
					ScriptAI* ai = dynamic_cast<ScriptAI*>( pNPC->ai() );
					if ( ai && ai->name() == ( *aiit ) )
					{
						delete ai;
						pNPC->setAI( NULL );
					}
				}
			}
			unregisterType( *aiit );
		}
	}
	aiit = newSections.begin();
	while ( aiit != newSections.end() )
	{
		if ( !oldSections.contains( *aiit ) )
		{
			ScriptAI::registerInFactory( *aiit );
		}
		++aiit;
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:51,代码来源:ai.cpp

示例12: removePet

void cPlayer::removePet( P_NPC pPet, bool noOwnerChange )
{
	if ( !pPet )
		return;

	CharContainer::iterator it = std::find( pets_.begin(), pets_.end(), pPet );
	if ( it != pets_.end() )
		pets_.erase( it );

	if ( !noOwnerChange )
	{
		pPet->setOwner( NULL, true );
	}

	if ( socket_ )
	{
		socket_->sendStatWindow();
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:19,代码来源:player.cpp

示例13: handleTargetInput

void Human_Stablemaster::handleTargetInput( P_PLAYER player, cUORxTarget* target )
{
	if ( !player )
		return;

	P_ITEM pPack = m_npc->getBankbox();
	if ( !pPack )
		return;

	P_NPC pPet = dynamic_cast<P_NPC>( World::instance()->findChar( target->serial() ) );
	if ( !pPet )
	{
		m_npc->talk( tr( "I cannot stable that!" ) );
		return;
	}

	if ( pPet->owner() != player )
	{
		m_npc->talk( tr( "This does not belong to you!" ) );
		return;
	}

	// we spawn a worldgem in the stablemasters bankbox for the pet
	// it does only hold the serial of it, the serial of the owner and the
	// number of refresh signals since begin of stabling
	// the pet becomes "free", which means, that it isnt in the world
	// but will still be saved.
	P_ITEM pGem = new cItem();
	pGem->Init( true );
	pGem->setTag( "player", cVariant( player->serial() ) );
	pGem->setTag( "pet", cVariant( pPet->serial() ) );
	pGem->setId( 0x1ea7 );
	pGem->setName( tr( "petitem: %1" ).arg( pPet->name() ) );
	pGem->setVisible( 2 ); // gm visible
	pPack->addItem( pGem );
	pGem->update();


	//pPet->free = true;
	MapObjects::instance()->remove( pPet );
	pPet->setStablemasterSerial( this->m_npc->serial() );
	pPet->removeFromView();

	// we need this for db saves
    m_npc->talk( tr( "Say release to get your pet back!" ) );
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:46,代码来源:ai_humans.cpp

示例14: atLayer

P_NPC cPlayer::unmount()
{
	P_ITEM pi = atLayer( Mount );
	if ( pi && !pi->free )
	{
		P_NPC pMount = dynamic_cast<P_NPC>( FindCharBySerial( pi->getTag( "pet" ).toInt() ) );
		if ( pMount && !pMount->free )
		{
			pMount->setWanderType( enHalt );
			pMount->setStablemasterSerial( INVALID_SERIAL );
			pMount->moveTo( pos() );
			pMount->setDirection( direction_ );
			pMount->resend( false );
			pMount->bark( Bark_Idle );
		}
		pi->remove();
		resend( false );
		return pMount;
	}
	return NULL;
}
开发者ID:Mutilador,项目名称:Wolfpack,代码行数:21,代码来源:player.cpp

示例15: npcRegisterAfterLoading

static void npcRegisterAfterLoading( P_NPC pc )
{
	if (pc->stablemasterSerial() == INVALID_SERIAL) {
		MapObjects::instance()->add(pc);
	}
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:6,代码来源:npc.cpp


注:本文中的P_NPC类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。