本文整理汇总了C++中Inventory::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Inventory::add方法的具体用法?C++ Inventory::add怎么用?C++ Inventory::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory::add方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: attachTo
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool ResponsePolynomial::attachTo(PublicObject* parent) {
if ( parent == NULL ) return false;
// check all possible parents
Inventory* inventory = Inventory::Cast(parent);
if ( inventory != NULL )
return inventory->add(this);
SEISCOMP_ERROR("ResponsePolynomial::attachTo(%s) -> wrong class type", parent->className());
return false;
}
示例2: use
bool BarrelBlock::use(Player& player, const BlockPos& pos)
{
BarrelEntity* container = (BarrelEntity*)player.region.getBlockEntity(pos);
if(container == nullptr)
return false;
Inventory* playerInventory = *(Inventory**) (((uintptr_t) &player) + 0xD78); // TODO: Do the f*** header of Entity, Mob, Player.
ItemInstance* instance = player.getSelectedItem();
if(container->itemInstance == nullptr && instance != nullptr)
{
container->maxItems = instance->getMaxStackSize() * 64;
container->itemCount = instance->count;
container->itemInstance = ItemInstance::clone(instance);
playerInventory->clearSlot(playerInventory->getSelectedSlot());
}
else if((instance == nullptr || instance->getId() != container->itemInstance->getId()) && container->itemCount > 0)
{
ItemInstance temp(container->itemInstance->getId(), 1, container->itemInstance->getAuxValue());
if(!playerInventory->add(temp)) // This function clone the ItemInstance
{
//If the player does not have space, drop the item to the floor.
player.region.getLevel()->addEntity(std::unique_ptr<Entity>(new ItemEntity(player.region, Vec3(pos), temp, 1)));
}
container->itemCount -= 1;
}
else if(container->itemInstance->sameItemAndAux(instance) && (container->itemCount > 0) && (container->itemCount < container->maxItems))
{
if((container->itemCount + instance->count) > container->maxItems)
{
instance->count = (container->itemCount + instance->count) - container->maxItems;
container->itemCount = container->maxItems;
}
else
{
container->itemCount += instance->count;
playerInventory->clearSlot(playerInventory->getSelectedSlot());
}
}
container->setChanged();
if(container->itemCount <= 0)
container->clear();
if(instance == nullptr)
return false;
return true;
}
示例3: attack
void BarrelBlock::attack(Player* player, const BlockPos& pos)
{
BarrelEntity* container = (BarrelEntity*)player->region.getBlockEntity(pos);
if(container == nullptr || container->itemInstance == nullptr)
return;
int stackSize = ((container->itemCount > container->itemInstance->getMaxStackSize()) ? container->itemInstance->getMaxStackSize() : container->itemCount);
Inventory* playerInventory = *(Inventory**) (((uintptr_t) player) + 0xD78); // TODO: Do the f*** header of Entity, Mob, Player.
ItemInstance newItem(container->itemInstance->getId(), stackSize, container->itemInstance->getAuxValue());
if(!playerInventory->add(newItem))
{
player->region.getLevel()->addEntity(std::unique_ptr<Entity>(new ItemEntity(player->region, Vec3(pos), newItem, 1)));
}
container->itemCount -= stackSize;
if(container->itemCount <= 0)
container->clear();
container->setChanged();
}