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


C++ P_ITEM::onDropOnChar方法代码示例

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


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

示例1: dropOnChar

void cDragItems::dropOnChar( cUOSocket *socket, P_ITEM pItem, P_CHAR pOtherChar )
{
	// Three possibilities:
	// If we're dropping it on ourself: packintobackpack
	// If we're dropping it on some other player: trade-window
	// If we're dropping it on some NPC: checkBehaviours
	// If not handeled: Equip the item if the NPC is owned by us

	// To prevent bad effects remove it from the clients view first
	cUOTxRemoveObject rObject;
	rObject.setSerial( pItem->serial() );
	socket->send( &rObject );

	P_CHAR pChar = socket->player();

	if( pItem->onDropOnChar( pOtherChar ) )
	{
		// Still dragging? Bounce!
		if( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	if( pOtherChar->onDropOnChar( pItem ) )
	{
		// Still dragging? Bounce!
		if( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	// Dropped on ourself
	if( pChar == pOtherChar )
	{
		pItem->toBackpack( pChar );
		return;
	}

	// Are we in range of our target
	if( !inrange1p( pChar, pOtherChar ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_REACH );
		return;
	}

	// Can wee see our target
	if( !lineOfSight( pChar->pos(), pOtherChar->pos(), TREES_BUSHES|WALLS_CHIMNEYS|DOORS|ROOFING_SLANTED|FLOORS_FLAT_ROOFING|LAVA_WATER ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_SIGHT );
		return;
	}

	// Open a secure trading window
	if( pOtherChar->objectType() == enPlayer && dynamic_cast<P_PLAYER>(pOtherChar)->socket() )
	{
		// Check if we're already trading, 
		// if not create a new window
		P_ITEM tradeWindow = pChar->atLayer( cBaseChar::TradeWindow );

		//if( !tradeWindow )
		//	tradeWindow = Trade->tradestart( client->socket(), pOtherChar );
		socket->bounceItem( pItem, BR_NO_REASON );
		socket->sysMessage( "Trading is disabled" );
		return;

		tradeWindow->addItem( pItem, false, false );
		pItem->setPos( Coord_cl(rand() % 60, rand() % 60, 9) );
		pItem->removeFromView( false );
		pItem->update();
		return;
	}

	// Dropping based on AI Type
	/*switch( pOtherChar->npcaitype() )
	{
	case 4:
		dropOnGuard( client, pItem, pOtherChar );
		break;
	case 5:
		dropOnBeggar( client, pItem, pOtherChar );
		break;
	case 8:
		dropOnBanker( client, pItem, pOtherChar );
		break;
	case 19:
		dropOnBroker( client, pItem, pOtherChar );
		break;
	};

	// Try to train - works for any NPC
	if( pOtherChar->cantrain() )
		if( pChar->trainer() == pOtherChar->serial )
			dropOnTrainer( client, pItem, pOtherChar );
		else
			pOtherChar->talk( "You need to tell me what you want to learn first" );*/

	// Finally lets check if it is simple food
	if( pItem->type() == 14 )
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:101,代码来源:dragdrop.cpp

示例2: dropOnChar

void DragAndDrop::dropOnChar( cUOSocket* socket, P_ITEM pItem, P_CHAR pOtherChar )
{
	// Three possibilities:
	// If we're dropping it on ourself: packintobackpack
	// If we're dropping it on some other player: trade-window
	// If we're dropping it on some NPC: checkBehaviours
	// If not handeled: Equip the item if the NPC is owned by us

	P_CHAR pChar = socket->player();

	if ( pItem->onDropOnChar( pOtherChar ) )
	{
		// Still dragging? Bounce!
		if ( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	if ( pOtherChar->onDropOnChar( pItem ) )
	{
		// Still dragging? Bounce!
		if ( socket->dragging() == pItem )
			socket->bounceItem( pItem, BR_NO_REASON );

		return;
	}

	// Dropped on ourself
	if ( pChar == pOtherChar )
	{
		pItem->toBackpack( pChar );
		return;
	}

	// Are we in range of our target
	if ( !pChar->inRange( pOtherChar, 3 ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_REACH );
		return;
	}

	// Can wee see our target
	if ( !pChar->lineOfSight( pOtherChar ) )
	{
		socket->bounceItem( pItem, BR_OUT_OF_SIGHT );
		return;
	}

	// Open a secure trading window
	if ( pOtherChar->objectType() == enPlayer && dynamic_cast<P_PLAYER>( pOtherChar )->socket() )
	{
		dynamic_cast<P_PLAYER>( pChar )->onTradeStart( dynamic_cast<P_PLAYER>( pOtherChar ), pItem );
		// Check if we're already trading,
		// if not create a new window
		/*
				P_ITEM tradeWindow = pChar->atLayer( cBaseChar::TradeWindow );
				//if( !tradeWindow )
				//	tradeWindow = Trade->tradestart( client->socket(), pOtherChar );
				socket->bounceItem( pItem, BR_NO_REASON );
				socket->sysMessage( "Trading is disabled" );
				return;
				tradeWindow->addItem( pItem, false, false );
				pItem->setPos( Coord_cl(rand() % 60, rand() % 60, 9) );
				pItem->removeFromView( false );
				pItem->update();
				*/
		return;
	}

	// Dropping based on AI Type
	/*switch( pOtherChar->npcaitype() )
	{
	case 4:
		dropOnGuard( client, pItem, pOtherChar );
		break;
	case 5:
		dropOnBeggar( client, pItem, pOtherChar );
		break;
	case 8:
		dropOnBanker( client, pItem, pOtherChar );
		break;
	case 19:
		dropOnBroker( client, pItem, pOtherChar );
		break;
	};
	// Try to train - works for any NPC
	if( pOtherChar->cantrain() )
		if( pChar->trainer() == pOtherChar->serial )
			dropOnTrainer( client, pItem, pOtherChar );
		else
			pOtherChar->talk( "You need to tell me what you want to learn first" );*/

	socket->sysMessage( tr( "The character does not seem to want the item." ) );
	socket->bounceItem( pItem, BR_NO_REASON );
	return;
}
开发者ID:BackupTheBerlios,项目名称:wolfpack-svn,代码行数:97,代码来源:dragdrop.cpp


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