本文整理汇总了C++中P_PLAYER::getBackpack方法的典型用法代码示例。如果您正苦于以下问题:C++ P_PLAYER::getBackpack方法的具体用法?C++ P_PLAYER::getBackpack怎么用?C++ P_PLAYER::getBackpack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P_PLAYER
的用法示例。
在下文中一共展示了P_PLAYER::getBackpack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomSteal
void cSkills::RandomSteal( cUOSocket* socket, SERIAL victim )
{
P_PLAYER pChar = socket->player();
P_CHAR pVictim = FindCharBySerial( victim );
if ( !pVictim || !pChar )
return;
if ( pVictim->serial() == pChar->serial() )
{
socket->sysMessage( tr( "Why don't you simply take it?" ) );
return;
}
/* if( pVictim->npcaitype() == 17 )
{
socket->sysMessage( tr( "You cannot steal from Playervendors." ) );
return;
}
*/
if ( pVictim->objectType() == enPlayer )
{
P_PLAYER pp = dynamic_cast<P_PLAYER>( pVictim );
if ( pp->isGMorCounselor() )
socket->sysMessage( tr( "You can't steal from game masters." ) );
return;
}
if ( !pChar->inRange( pVictim, 1 ) )
{
socket->sysMessage( tr( "You are too far away to steal from that person." ) );
return;
}
P_ITEM pBackpack = pVictim->getBackpack();
if ( !pBackpack )
{
socket->sysMessage( tr( "Bad luck, your victim doesn't have a backpack." ) );
return;
}
float maxWeight = ( float ) QMIN( 1, pChar->skillValue( STEALING ) ); // We can steal max. 10 Stones when we are a GM
// 1000 Skill == 100 Weight == 10 Stones
QPtrList<cItem> containment = pBackpack->getContainment();
Q_UINT32 chance = containment.count();
P_ITEM pItem = containment.first();
P_ITEM pToSteal = 0;
bool sawOkItem = false;
while ( !pToSteal )
{
// We have nothing that could be stolen?
if ( !pItem && !sawOkItem )
{
socket->sysMessage( tr( "Your victim posesses nothing you could steal." ) );
return;
}
// Jump back to the beginning
else if ( !pItem && sawOkItem )
{
pItem = containment.first();
}
// Check if our chance becomes true (no spellbooks!)
if ( pItem->totalweight() <= maxWeight && !pItem->isLockedDown() && !pItem->newbie() && pItem->type() != 9 )
{
sawOkItem = true; // We have items that could be stolen (just in case we reach the end of our list)
// We have the chance of 1/chance that we reached our desired item
if ( RandomNum( 1, ( int )chance ) == ( int )chance )
{
pToSteal = pItem;
break;
}
}
pItem = containment.next();
}
socket->sysMessage( tr( "You reach into %1's backpack and try to steal something..." ).arg( pVictim->name() ) );
// The success of our Theft depends on the weight of the stolen item
bool success = pChar->checkSkill( STEALING, 0, ( long int )pToSteal->weight() );
bool caught = false;
if ( success )
{
socket->sysMessage( tr( "You successfully steal %1." ).arg( pToSteal->getName() ) );
P_ITEM pPack = pChar->getBackpack();
pPack->addItem( pToSteal );
// Update item onyl if still existent
if ( !pToSteal->free )
pToSteal->update();
caught = pChar->skillValue( STEALING ) < rand() % 1001;
}
else
//.........这里部分代码省略.........
示例2: dropOnItem
//.........这里部分代码省略.........
if ( !pChar->canPickUp( pItem ) )
{
socket->bounceItem( pItem, BR_CANNOT_PICK_THAT_UP );
return;
}
// We drop something on the belongings of one of our playervendors
/* if( ( packOwner != NULL ) && ( packOwner->npcaitype() == 17 ) && packOwner->owner() == pChar )
{
socket->sysMessage( tr( "You drop something into your playervendor (unimplemented)" ) );
socket->bounceItem( pItem, BR_NO_REASON );
return;
}*/
// Playervendors (chest equipped by the vendor - opened to the client)
/*if( !( pCont->pileable() && pItem->pileable() && pCont->id() == pItem->id() || ( pCont->type() != 1 && pCont->type() != 9 ) ) )
{
P_CHAR pc_j = GetPackOwner(pCont);
if (pc_j != NULL)
{
if (pc_j->npcaitype() == 17 && pc_j->isNpc() && pChar->Owns(pc_j))
{
pChar->inputitem = pItem->serial;
pChar->inputmode = cChar::enPricing;
sysmessage(s, "Set a price for this item.");
}
}
*/
// We may also drop into *any* locked chest
// So we can have post-boxes ;o)
if ( pCont->type() == 1 )
{
// If we're dropping it onto the closed container
if ( dropPos.x == 0xFFFF && dropPos.y == 0xFFFF )
{
pCont->addItem( pItem );
}
else
{
pCont->addItem( pItem, false );
pItem->setPos( dropPos );
}
// Dropped on another Container/in another Container
pChar->soundEffect( 0x57 );
pItem->update();
return;
}
else if ( pCont->canStack( pItem ) )
{
if ( pCont->amount() + pItem->amount() <= 65535 )
{
pCont->setAmount( pCont->amount() + pItem->amount() );
pItem->remove();
pCont->update(); // Need to update the amount
pCont->resendTooltip();
return;
}
else
{
// The delta between 65535 and pCont->amount() sub our Amount is the
// new amount
pItem->setAmount( pItem->amount() - ( 65535 - pCont->amount() ) );
pItem->resendTooltip();
pCont->setAmount( 65535 ); // Max out the amount
pCont->update();
pCont->resendTooltip();
}
}
// We dropped the item NOT on a container
// And were *un*able to stack it (!)
// >> Set it to the location of the item we dropped it on and stack it up by 2
if ( pCont->container() )
{
P_ITEM pNewCont = dynamic_cast<P_ITEM>( pCont->container() );
if ( pNewCont )
{
pNewCont->addItem( pItem, false );
pItem->setPos( pCont->pos() + Coord_cl( 0, 0, 2 ) );
}
else
{
pChar->getBackpack()->addItem( pItem );
}
}
else
{
pItem->removeFromCont();
pItem->moveTo( pCont->pos() + Coord_cl( 0, 0, 2 ) );
}
pItem->update();
}