当前位置: 首页>>代码示例>>C++>>正文


C++ Inventory::add方法代码示例

本文整理汇总了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;
}
开发者ID:Fran89,项目名称:seiscomp3,代码行数:12,代码来源:responsepolynomial.cpp

示例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;
}
开发者ID:byteandahalf,项目名称:Mechanics,代码行数:50,代码来源:BarrelBlock.cpp

示例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();
}
开发者ID:byteandahalf,项目名称:Mechanics,代码行数:20,代码来源:BarrelBlock.cpp


注:本文中的Inventory::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。