本文整理汇总了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 )
//.........这里部分代码省略.........
示例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;
}