本文整理汇总了C++中P_ITEM::setLayer方法的典型用法代码示例。如果您正苦于以下问题:C++ P_ITEM::setLayer方法的具体用法?C++ P_ITEM::setLayer怎么用?C++ P_ITEM::setLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P_ITEM
的用法示例。
在下文中一共展示了P_ITEM::setLayer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dropOnGround
void cDragItems::dropOnGround( P_CLIENT client, P_ITEM pItem, const Coord_cl &pos )
{
P_CHAR pChar = client->player();
// Check if the destination is in line of sight
if( !line_of_sight( client->socket(), pChar->pos, pos, TREES_BUSHES|WALLS_CHIMNEYS|DOORS|ROOFING_SLANTED|FLOORS_FLAT_ROOFING|LAVA_WATER ) )
{
client->sysMessage( "You cannot see the target." );
bounceItem( client, pItem );
return;
}
if( !pChar->canPickUp( pItem ) )
{
bounceItem( client, pItem );
return;
}
pItem->setContSerial( INVALID_SERIAL );
pItem->moveTo( pos );
pItem->setLayer( 0 );
RefreshItem( pItem ); // Send it to all clients in range
pChar->weight -= pItem->getWeight();
statwindow( client->socket(), pChar ); // Update our weight-stats
if( pItem->glow != INVALID_SERIAL )
{
pChar->removeHalo( pItem );
pChar->glowHalo( pItem );
}
// Multi handling (Hm i don't like that...)
if( pChar->multis > 0 )
{
P_ITEM pMulti = FindItemBySerial( pChar->multis );
if( pMulti != NULL )
{
pMulti = findmulti( pItem->pos );
if( pItem != NULL )
pItem->SetMultiSerial( pMulti->serial );
}
}
}
示例2: applyStartItemDefinition
void cPlayer::applyStartItemDefinition( const cElement* element )
{
for ( unsigned int i = 0; i < element->childCount(); ++i )
{
const cElement* node = element->getChild( i );
// Apply another startitem definition
if ( node->name() == "inherit" )
{
const cElement* inheritNode = Definitions::instance()->getDefinition( WPDT_STARTITEMS, node->getAttribute( "id" ) );
if ( inheritNode )
{
applyStartItemDefinition( inheritNode );
}
}
// Item related nodes
else
{
P_ITEM pItem = 0;
if ( node->hasAttribute( "id" ) && node->getAttribute( "id" ) != QString::null )
{
pItem = cItem::createFromScript( node->getAttribute( "id" ) );
}
else if ( node->hasAttribute( "list" ) && node->getAttribute( "list" ) != QString::null )
{
pItem = cItem::createFromList( node->getAttribute( "list" ) );
}
else if ( node->hasAttribute( "randomlist" ) && node->getAttribute( "randomlist" ) != QString::null )
{
QStringList RandValues = node->getAttribute( "randomlist" ).split( "," );
pItem = cItem::createFromList( RandValues[RandomNum( 0, RandValues.size() - 1 )] );
}
if ( !pItem )
{
Console::instance()->log( LOG_ERROR, tr( "Invalid item tag without id or list in startitem definition '%1'" ).arg( element->getAttribute( "id" ) ) );
}
else
{
pItem->applyDefinition( node );
if ( node->name() == "item" )
{
pItem->toBackpack( this );
}
else if ( node->name() == "bankitem" )
{
getBackpack()->addItem( pItem );
}
else if ( node->name() == "equipment" )
{
unsigned char layer = pItem->layer();
pItem->setLayer( 0 );
if ( !layer )
{
tile_st tile = TileCache::instance()->getTile( pItem->id() );
layer = tile.layer;
}
if ( layer )
{
// Check if there is sth there already.
// Could happen due to inherit.
P_ITEM existing = atLayer( static_cast<cBaseChar::enLayer>( layer ) );
if ( existing )
existing->remove();
addItem( static_cast<cBaseChar::enLayer>( layer ), pItem );
}
else
{
Console::instance()->log( LOG_ERROR, tr( "Trying to equip invalid item (%1) in startitem definition '%2'" ).arg( pItem->id(), 0, 16 ).arg( element->getAttribute( "id" ) ) );
}
}
else
{
pItem->remove();
Console::instance()->log( LOG_ERROR, tr( "Unrecognized startitem tag '%1' in definition '%2'." ).arg( QString(node->name()) ).arg( element->getAttribute( "id" ) ) );
}
}
}
}
}
示例3: grabItem
//.........这里部分代码省略.........
if( outmostCont && ( outmostCont->contserial == pChar->serial ) && ( outmostCont->layer() == 0 ) && ( outmostCont->id() == 0x1E5E ) )
{
// Get the other sides tradewindow
P_ITEM tradeWindow = FindItemBySerial( calcserial( outmostCont->moreb1(), outmostCont->moreb2(), outmostCont->moreb3(), outmostCont->moreb4() ) );
// If one of the trade-windows has the ack-status reset it
if( tradeWindow && ( tradeWindow->morez || outmostCont->morez ) )
{
tradeWindow->morez = 0;
outmostCont->morez = 0;
sendtradestatus( tradeWindow, outmostCont );
}
}
// If the top-most container ( thats important ) is a corpse
// and looting is a crime, flag the character criminal.
if( outmostCont && outmostCont->corpse() )
{
// For each item we take out we loose carma
// if the corpse is innocent and not in our guild
bool sameGuild = ( GuildCompare( pChar, FindCharBySerial( outmostCont->ownserial ) ) != 0 );
if( ( outmostCont->more2 == 1 ) && !pChar->Owns( outmostCont ) && !sameGuild )
{
pChar->karma -= 5;
criminal( pChar );
client->sysMessage( "You lost some karma." );
}
}
// Check if the item is too heavy
//if( !pc_currchar->isGMorCounselor() )
//{
//} << Deactivated (DarkStorm)
// ==== Grabbing the Item is allowed here ====
// Remove eventual item-bonusses if we're unequipping something
if( pItem->layer() > 0 )
{
P_CHAR wearer = FindCharBySerial( pItem->contserial );
if( wearer )
wearer->removeItemBonus( pItem );
}
// Send the user a pickup sound if we're picking it up
// From a container/paperdoll
if( !pItem->isInWorld() )
soundeffect( client->socket(), 0x00, 0x57 );
// If we're picking up a specific amount of what we got
// Take that into account
if( pItem->amount() > 1 )
{
UI32 pickedAmount = min( amount, pItem->amount() );
// We only have to split if we're not taking it all
if( pickedAmount != pItem->amount() )
{
P_ITEM splitItem = new cItem( *pItem ); // Create a new item to pick that up
splitItem->SetSerial( cItemsManager::getInstance()->getUnusedSerial() );
splitItem->setAmount( pItem->amount() - pickedAmount );
splitItem->setContSerial( pItem->contserial );
splitItem->SetOwnSerial( pItem->ownserial );
splitItem->SetSpawnSerial( pItem->spawnserial );
// He needs to see the new item
RefreshItem( splitItem );
// If we're taking something out of a spawn-region it's spawning "flag" is removed isn't it?
pItem->SetSpawnSerial( INVALID_SERIAL );
pItem->setAmount( pickedAmount );
}
}
pItem->setContSerial( pChar->serial );
pItem->SetMultiSerial( INVALID_SERIAL );
pItem->setLayer( 0x1E );
// It's in the equipment of another character
if( itemOwner && ( itemOwner != pChar ) )
{
itemOwner->weight -= pItem->getWeight();
statwindow( calcSocketFromChar( itemOwner ), itemOwner );
}
// If the item is in the bank or any sell-container it's NOT counted as char-weight
bool inBank = ( outmostCont && ( outmostCont->contserial == pChar->serial ) && ( outmostCont->layer() >= 0x1A ) );
// Add the weight if:
// - Picked from ground
// - Picked out of another character
// - Picked out of our bank or any other non-visible container
if( ( itemOwner != pChar ) || !inBank )
{
pChar->weight += pItem->getWeight();
statwindow( client->socket(), pChar );
}
}
示例4: dropOnItem
//.........这里部分代码省略.........
client->sysMessage( "That spellbook already contains this spell" );
bounceItem( client, pItem );
return;
}
}
// We drop something on the belongings of one of our playervendors
if( ( packOwner != NULL ) && ( packOwner->npcaitype() == 17 ) && pChar->Owns( packOwner ) )
{
client->sysMessage( "You drop something into your playervendor" );
bounceItem( client, pItem );
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)
// Spellbooks are containers for us as well
if( pCont->type() == 9 || pCont->type() == 1 || pCont->type() == 8 || pCont->type() == 63 || pCont->type() == 65 || pCont->type() == 66 )
{
pItem->setContSerial( pCont->serial );
pItem->setLayer( 0 ); // Remove it from our drag-layer
// Huh ? - Make that random will you!
pItem->pos = dropPos;
SndRemoveitem( pItem->serial );
RefreshItem( pItem );
// Dropped on another Container/in another Container
soundeffect2( pChar, 0x57 );
return;
}
// Item matching needs to be extended !!! at least Color! (for certain types)
else if ( pCont->isPileable() && pItem->isPileable() && ( pCont->id() == pItem->id() ) )
{
if( pCont->amount() + pItem->amount() <= 65535 )
{
pCont->setAmount( pCont->amount() + pItem->amount() );
Items->DeleItem( pItem );
RefreshItem( pCont ); // Need to update the amount
return;
}
// We have to *keep* our current item
else
{
pCont->setAmount( 65535 ); // Max out the amount
RefreshItem( pCont );
// The delta between 65535 and pCont->amount() sub our Amount is the
// new amount
pItem->setAmount( pItem->amount() - ( 65535 - pCont->amount() ) );
}
}
// 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 1
pItem->moveTo( pCont->pos );
pItem->pos.z++; // Increase z by 1
pItem->pos.y++; // To get it visualized do that with y as well
pItem->setLayer( 0 );
pItem->setContSerial( pCont->contserial );
RefreshItem( pItem );
// This needs to be checked
// It annoyingly shows the spellbook
// whenever you add a scroll
if( pCont->type() == 9 )
Magic->openSpellBook( pChar, pCont );
// Glowing Objects moved between chars
if( pItem->glow != INVALID_SERIAL )
{
pChar->removeHalo( pItem );
if( packOwner != NULL )
{
packOwner->addHalo(pItem);
packOwner->glowHalo(pItem);
}
}
}
示例5: dropOnChar
void cDragItems::dropOnChar( P_CLIENT client, 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 = client->player();
// Dropped on ourself
if( pChar == pOtherChar )
{
pItem->setLayer( 0 );
pItem->setContSerial( INVALID_SERIAL );
pItem->toBackpack( pChar );
return;
}
// Are we in range of our target
if( !inrange1p( pChar, pOtherChar ) )
{
client->sysMessage( "You are too far away from that character." );
bounceItem( client, pItem );
return;
}
// Can wee see our target
if( !line_of_sight( client->socket(), pChar->pos, pOtherChar->pos, TREES_BUSHES|WALLS_CHIMNEYS|DOORS|ROOFING_SLANTED|FLOORS_FLAT_ROOFING|LAVA_WATER ) )
{
client->sysMessage( "You can't see this character" );
bounceItem( client, pItem );
return;
}
// Open a secure trading window
if( !pOtherChar->isNpc() && online( pOtherChar ) )
{
// Check if we're already trading,
// if not create a new window
vector< SERIAL > equipment = contsp.getData( pChar->serial );
P_ITEM tradeWindow = NULL;
for( UI16 i = 0; i < equipment.size(); i++ )
{
P_ITEM pEquip = FindItemBySerial( equipment[ i ] );
// Is it a trade-window ?
if( ( pEquip->layer() == 0 ) && ( pEquip->id() == 0x1E5E ) )
{
P_ITEM tradeWindow = FindItemBySerial( calcserial( pEquip->moreb1(), pEquip->moreb2(), pEquip->moreb3(), pEquip->moreb4() ) );
if( tradeWindow && ( tradeWindow->contserial == pOtherChar->serial ) )
{
tradeWindow = pEquip;
break;
}
}
}
if( !tradeWindow )
tradeWindow = Trade->tradestart( client->socket(), pOtherChar );
pItem->setContSerial( tradeWindow->serial);
pItem->pos.x = rand() % 60;
pItem->pos.y = rand() % 60;
pItem->pos.z = 9;
pItem->setLayer( 0 );
SndRemoveitem( pItem->serial );
RefreshItem( pItem );
return;
}
// For our hirelings we have a special function
if( pChar->Owns( pOtherChar ) )
{
dropOnPet( client, pItem, pOtherChar );
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 );
//.........这里部分代码省略.........
示例6: equipItem
//.........这里部分代码省略.........
// Males can't wear female armor
if( ( pChar->id() == 0x0190 ) && ( pItem->id() >= 0x1C00 ) && ( pItem->id() <= 0x1C0D ) )
{
client->sysMessage( "You cannot wear female armor." );
bounceItem( client, pItem );
return;
}
// Needs a check (!)
// Checks for equipment on the same layer
// If there is any it tries to unequip it
// If that fails it cancels
UI08 layer = pItem->layer();
vector< SERIAL > equipment = contsp.getData( pWearer->serial );
for( UI32 i = 0; i < equipment.size(); i++ )
{
P_ITEM pEquip = FindItemBySerial( equipment[ i ] );
if( pEquip )
continue;
// We found an item which is on the same layer (!)
// Unequip it if we can
bool twoHanded = false;
if( pEquip->twohanded() && ( layer == 1 || layer == 2 ) )
twoHanded = true;
if( pItem->twohanded() && ( pEquip->layer() == 1 || pEquip->layer() == 2 ) )
twoHanded = true;
if( ( pEquip->layer() == layer ) || twoHanded )
{
if( pChar->canPickUp( pEquip ) ) // we're equipping so we do the check
pEquip->toBackpack( pWearer );
// If it's still on the char: cancel equipment
if( pEquip->contserial == pWearer->serial )
{
client->sysMessage( "You already have an item on that layer." );
bounceItem( client, pItem );
return;
}
}
}
// At this point we're certain that we can wear the item
pItem->setContSerial( playerId );
pItem->setLayer( pTile.layer ); // Don't trust the user input on this one
// Handle the weight if the item is leaving our "body"
if( pWearer != pChar )
{
pChar->weight -= pItem->getWeight();
pWearer->weight += pItem->getWeight();
// Update the status-windows
statwindow( client->socket(), pChar );
statwindow( calcSocketFromChar( pWearer ), pWearer );
}
if( pTile.layer == 0x19 )
pWearer->setOnHorse( true );
// Apply the bonuses
pWearer->st += pItem->st2;
pWearer->chgDex( pItem->dx2 );
pWearer->in += pItem->in2;
// Show debug information if requested
if( showlayer )
clConsole.send( QString( "Item (%1) equipped on layer %2" ).arg( pItem->name() ).arg( pItem->layer() ) );
// I don't think we need to remove the item
// as it's only visible to the current char
// And he looses contact anyway
// SndRemoveitem( pi->serial );
// Build our packets
cWornItems wearItem( pWearer->serial, pItem->serial, pItem->layer(), pItem->id(), pItem->color() );
cSoundEffect soundEffect( 0x57, pWearer->pos );
// Send to all sockets in range
// ONLY the new equipped item and the sound-effect
for( UOXSOCKET s = 0; s < now; s++ )
if( perm[s] && inrange1p( pWearer, currchar[s] ) )
{
soundEffect.send( s );
wearItem.send( s );
}
// Lord Binaries Glow stuff
if( pItem->glow != INVALID_SERIAL )
{
pChar->removeHalo( pItem );
pWearer->addHalo( pItem );
pWearer->glowHalo( pItem );
}
}