本文整理汇总了C++中Inventory::setItem方法的典型用法代码示例。如果您正苦于以下问题:C++ Inventory::setItem方法的具体用法?C++ Inventory::setItem怎么用?C++ Inventory::setItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory::setItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Inventory
/*
* Returns a filtered inventory for the actor's pack.
*/
Inventory * Actor::getInventory( unsigned short filter )
{
if( filter == K_EQUIPMENT )
{
Inventory *inv = new Inventory( this->countEquippedItems() ) ;
unsigned short is = 0 ;
for( unsigned short i = 0 ; i < EQUIPMENT_SLOTS ; i++ )
if( equipment[i] != NULL )
inv->setItem( is++, equipment[i] ) ;
return inv ;
}
else return pack->toInventory(filter) ;
}
示例2: handleMessage
void InventoryHandler::handleMessage(MessageIn &msg)
{
int number;
int index, amount, itemId, equipType, arrow;
int identified, cards[4], itemType;
Inventory *inventory = player_node->getInventory();
Inventory *storage = player_node->getStorage();
switch (msg.getId())
{
case SMSG_PLAYER_INVENTORY:
case SMSG_PLAYER_STORAGE_ITEMS:
if (msg.getId() == SMSG_PLAYER_INVENTORY)
{
// Clear inventory - this will be a complete refresh
clearEquipment();
inventory->clear();
}
else
{
/*
* This packet will always be followed by a
* SMSG_PLAYER_STORAGE_EQUIP packet. The two packets
* together comprise a complete refresh of storage, so
* clear storage here
*/
storage->clear();
}
msg.readInt16(); // length
number = (msg.getLength() - 4) / 18;
for (int loop = 0; loop < number; loop++)
{
index = msg.readInt16();
itemId = msg.readInt16();
itemType = msg.readInt8();
identified = msg.readInt8();
amount = msg.readInt16();
arrow = msg.readInt16();
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
index -= (msg.getId() == SMSG_PLAYER_INVENTORY) ?
INVENTORY_OFFSET : STORAGE_OFFSET;
if (debugInventory)
{
logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, "
"Qty: %d, Cards: %d, %d, %d, %d",
index, itemId, itemType, identified, amount,
cards[0], cards[1], cards[2], cards[3]);
}
if (msg.getId() == SMSG_PLAYER_INVENTORY) {
inventory->setItem(index, itemId, amount, false);
// Trick because arrows are not considered equipment
if (arrow & 0x8000) {
if (Item *item = inventory->getItem(index))
item->setEquipment(true);
}
} else {
storage->setItem(index, itemId, amount, false);
}
}
break;
case SMSG_PLAYER_STORAGE_EQUIP:
msg.readInt16(); // length
number = (msg.getLength() - 4) / 20;
for (int loop = 0; loop < number; loop++) {
index = msg.readInt16() - STORAGE_OFFSET;
itemId = msg.readInt16();
itemType = msg.readInt8();
identified = msg.readInt8();
amount = 1;
msg.readInt16(); // Equip Point?
msg.readInt16(); // Another Equip Point?
msg.readInt8(); // Attribute (broken)
msg.readInt8(); // Refine level
for (int i = 0; i < 4; i++)
cards[i] = msg.readInt16();
if (debugInventory)
{
logger->log("Index: %d, ID: %d, Type: %d, Identified: %d, "
"Qty: %d, Cards: %d, %d, %d, %d",
index, itemId, itemType, identified, amount,
cards[0], cards[1], cards[2], cards[3]);
}
storage->setItem(index, itemId, amount, false);
}
break;
case SMSG_PLAYER_INVENTORY_ADD:
index = msg.readInt16() - INVENTORY_OFFSET;
amount = msg.readInt16();
itemId = msg.readInt16();
//.........这里部分代码省略.........
示例3: handleMessage
void EquipmentHandler::handleMessage(MessageIn &msg)
{
int itemCount;
int index, equipPoint, itemId;
int type;
Inventory *inventory = player_node->getInventory();
switch (msg.getId())
{
case SMSG_PLAYER_EQUIPMENT:
msg.readInt16(); // length
itemCount = (msg.getLength() - 4) / 20;
for (int loop = 0; loop < itemCount; loop++)
{
index = msg.readInt16() - INVENTORY_OFFSET;
itemId = msg.readInt16();
msg.readInt8(); // type
msg.readInt8(); // identify flag
msg.readInt16(); // equip type
equipPoint = msg.readInt16();
msg.readInt8(); // attribute
msg.readInt8(); // refine
msg.skip(8); // card
inventory->setItem(index, itemId, 1, true);
setEquipment(equipPoint, index, true);
}
break;
case SMSG_PLAYER_EQUIP:
index = msg.readInt16() - INVENTORY_OFFSET;
equipPoint = msg.readInt16();
type = msg.readInt8();
if (!type)
{
localChatTab->chatLog(_("Unable to equip."), BY_SERVER);
break;
}
setEquipment(equipPoint, index, true);
break;
case SMSG_PLAYER_UNEQUIP:
index = msg.readInt16() - INVENTORY_OFFSET;
equipPoint = msg.readInt16();
type = msg.readInt8();
if (!type) {
localChatTab->chatLog(_("Unable to unequip."), BY_SERVER);
break;
}
setEquipment(equipPoint, index, false);
break;
case SMSG_PLAYER_ATTACK_RANGE:
player_node->setAttackRange(msg.readInt16());
break;
case SMSG_PLAYER_ARROW_EQUIP:
index = msg.readInt16();
if (index <= 1)
break;
index -= INVENTORY_OFFSET;
logger->log("Arrows equipped: %i", index);
setEquipment(0x8000, index, true);
break;
}
}