本文整理汇总了C++中ItemInstance类的典型用法代码示例。如果您正苦于以下问题:C++ ItemInstance类的具体用法?C++ ItemInstance怎么用?C++ ItemInstance使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eraseItems
//----[ eraseItems ]---------------------------------------------------------
int ClientItemsInterface::eraseItems(unsigned int item_type, int quantity) {
for (unsigned int i = 0; (quantity > 0) && (i < items_in_inventory_);) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
break;
} else {
if (item->getDescription()->type_index == item_type) {
quantity = item->removeQuantity(quantity);
update_inventory_ = true;
equipment_changed_ = equipment_changed_ || inventory_[i].equipped;
inventory_dirty_bits_.set(i);
// check to see if this item was destroyed by removing
// the given quantity.
if (quantity >= 0) {
GlobalDatabaseManager::singleton()
->itemOnAvatarErased(item->getUniqueID());
GlobalItemManager::singleton()->releaseItem(&inventory_[i].item);
shiftDownToEraseInInventory(i);
}
// If the quantity has been consumed, we're done!
if (quantity <= 0) return 0;
} else {
++i;
}
}
}
return quantity;
}
示例2: assert
//----[ onDeath ]------------------------------------------------------------
bool ClientItemsInterface::onDeath(Magic::MagicIndex* on_death_magic,
int* wishing_percent) {
assert(on_death_magic);
assert(wishing_percent);
bool found_on_death_magic = false;
int wishing_percent_sum = 0;
// iterate backward because we might remove an element
for (int i = items_in_inventory_; i > 0;) {
--i;
if (!inventory_[i].equipped) continue;
ItemInstance* item = inventory_[i].item.dereference();
assert(item);
Magic::MagicIndex death_magic = item->getDescription()->on_death_magic;
wishing_percent_sum += item->getDescription()->wishing_percent;
if (!found_on_death_magic &&
(death_magic != Magic::INVALID_MAGIC_INDEX)) {
found_on_death_magic = true;
*on_death_magic = death_magic;
update_inventory_ = true;
GlobalDatabaseManager::singleton()
->itemOnAvatarErased(item->getUniqueID());
GlobalItemManager::singleton()
->releaseItem(&inventory_[i].item);
shiftDownToEraseInInventory(i);
}
}
*wishing_percent = wishing_percent_sum;
return found_on_death_magic;
}
示例3: switch
Void Inventory::SortBufferBagItems()
{
if ( m_arrBags[INVENTORYBAGID_BUFFER].iFreeSlots == INVENTORY_BAG_SIZE )
return;
for( UInt i = 0; i < INVENTORY_BAG_SIZE; ++i ) {
ItemInstance * pItemInstance = m_arrBags[INVENTORYBAGID_BUFFER].arrSlots[i];
if ( pItemInstance == NULL )
continue;
InventoryBagID idTargetBag = INVENTORYBAGID_COUNT;
switch( pItemInstance->GetType() ) {
case ITEMTYPE_BLOCK: idTargetBag = INVENTORYBAGID_BLOCK; break;
case ITEMTYPE_EQUIPMENT: idTargetBag = INVENTORYBAGID_EQUIPMENT; break;
case ITEMTYPE_CONSUMABLE: idTargetBag = INVENTORYBAGID_CONSUMABLE; break;
case ITEMTYPE_QUEST: idTargetBag = INVENTORYBAGID_QUEST; break;
default: Assert(false); break;
}
if ( m_arrBags[idTargetBag].iFreeSlots == 0 )
continue;
UInt iFreeSlot = _Bag_GetFreeSlot( idTargetBag );
Assert( m_arrBags[idTargetBag].arrSlots[iFreeSlot] == NULL );
m_arrBags[INVENTORYBAGID_BUFFER].arrSlots[i] = NULL;
m_arrBags[idTargetBag].arrSlots[iFreeSlot] = pItemInstance;
++(m_arrBags[INVENTORYBAGID_BUFFER].iFreeSlots);
--(m_arrBags[idTargetBag].iFreeSlots);
}
SortBag( INVENTORYBAGID_BUFFER );
}
示例4: while
//----[ findStackableItemInInventory ]---------------------------------------
bool ClientItemsInterface::findStackableItemInInventory(
ItemInstance* find_match_for,
unsigned int start_search_index,
unsigned int* found_index,
ItemInstance** current_item) {
if (!find_match_for) return false; // no item?
const Evidyon::Item::ItemServerDescription* description
= find_match_for->getDescription();
if (description->max_stack_size <= 1) return false; // not stackable?
unsigned int i = start_search_index;
while (i < items_in_inventory_) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
// This item is invalid, but is listed as valid--fix the problem,
// then try again. This will loop until no problems are found
// or the list is emptied because all are bugged.
repackInventory();
} else {
if (item->getDescription() == description &&
!inventory_[i].equipped) { // don't stack equipped items
*found_index = start_search_index;
*current_item = item;
return true;
} else {
++i;
}
}
}
return false;
}
示例5: splitItem
//----[ splitItem ]----------------------------------------------------------
bool ClientItemsInterface::splitItem(unsigned int index) {
if (!inventoryItemIsValid(index)) return false;
AvatarInventoryItem* inventory_item = &inventory_[index];
if (!inventory_item->stackable || // item must be stackable...
inventory_item->equipped) return false; // ...and in the inventory
ItemInstance* item = inventory_item->item.dereferenceAssumingValid(); // justified by validity check
if (canHoldItems(1) == false) return false; //
const int original_quantity = item->getQuantity();
if (original_quantity <= 1) return false; // can't split a stack of 1
int new_quantity = original_quantity >> 1; // divide in half
int quantity_remaining = original_quantity - new_quantity;
// Create the new item
ItemPointer new_item;
if (!GlobalItemManager::singleton()->acquireNewItem(new_quantity,
item->getDescription()->type_index,
&new_item)) {
return false;
}
// Put the new item in the inventory
if (!addToInventory(new_item, NULL)) {
GlobalItemManager::singleton()->releaseItem(&new_item);
}
// Adjust the quantity of the original item
item->setQuantity(quantity_remaining);
return true;
}
示例6: GetItem
uint32 EQEmu::ItemInstance::GetItemID(uint8 slot) const
{
ItemInstance *item = GetItem(slot);
if (item)
return item->GetID();
return 0;
}
示例7: setStorageItem
//----[ setStorageItem ]-----------------------------------------------------
void ClientItemsInterface::setStorageItem(unsigned int index,
ItemPointer* item_pointer) {
ItemInstance* item = item_pointer->dereferenceAssumingValid();
storage_[index].id = item->getUniqueID();
storage_[index].quantity = item->getQuantity();
storage_[index].type = item->getDescription()->type_index;
GlobalItemManager::singleton()->releaseItem(item_pointer);
storage_dirty_bits_.set(index);
update_storage_ = true;
}
示例8: geosidSacrificeItem
//----[ geosidSacrificeItem ]------------------------------------------------
bool ClientItemsInterface::geosidSacrificeItem(unsigned int index,
Geosid::Geonite* geonite_value) {
if (!inventoryItemIsValid(index)) return false;
AvatarInventoryItem* inventory_item = &inventory_[index];
if (inventory_item->equipped) return false; // can't sacrifice equipped items
ItemInstance* item = inventory_item->item.dereferenceAssumingValid();
*geonite_value = item->getDescription()->geonite_value;
GlobalItemManager::singleton()->releaseItem(&inventory_item->item);
shiftDownToEraseInInventory(index);
return true;
}
示例9: if
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;
}
示例10: isCarrying
//----[ isCarrying ]---------------------------------------------------------
bool ClientItemsInterface::isCarrying(unsigned int item_type, int quantity) {
for (unsigned int i = 0; i < items_in_inventory_; ++i) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
return false;
} else {
if (item->getDescription()->type_index == item_type) {
quantity -= item->getQuantity();
if (quantity <= 0) return true;
}
}
}
return false;
}
示例11: setInventoryItem
//----[ setInventoryItem ]---------------------------------------------------
void ClientItemsInterface::setInventoryItem(unsigned int index,
ItemPointer& item_pointer) {
ItemInstance* item = item_pointer.dereferenceAssumingValid();
inventory_[index].item.copy(item_pointer);
inventory_[index].stackable = item->isStackable();
inventory_[index].equipped = false;
inventory_dirty_bits_.set(index);
update_inventory_ = true;
{ // become the owner of this item
//inventory_[index].item.becomeUniquePointer();
GlobalDatabaseManager::singleton()->itemChangeOwner(item->getUniqueID(),
account_id_,
character_id_,
session_id_);
}
}
示例12:
void EQEmu::ItemInstance::PutItem(uint8 index, const ItemInstance& inst)
{
// Clean up item already in slot (if exists)
DeleteItem(index);
// Delegate to internal method
_PutItem(index, inst.Clone());
}
示例13: isCarryingNew
//----[ isCarryingNew ]------------------------------------------------------
bool ClientItemsInterface::isCarryingNew(unsigned int item_type,
int quantity,
ItemIDType oldest_id) {
for (unsigned int i = 0; i < items_in_inventory_; ++i) {
ItemInstance* item = inventory_[i].item.dereference();
if (!item) {
repackInventory();
return false;
} else {
if (item->getDescription()->type_index == item_type &&
item->getUniqueID() >= oldest_id) { // consider only new items
quantity -= item->getQuantity();
if (quantity <= 0) return true;
}
}
}
return false;
}
示例14: getPower
int QualityBasedMiningToolItemTypeComponent::getPower(const ItemInstance& itemInstance) const
{
if(_strengths.size() == 0)
{
return 0;
}
ItemInstanceComponent* comp = itemInstance.getComponent(ItemInstanceComponent::QualityItemInstanceComponent);
int quality = comp == 0 ? 0 : static_cast<QualityItemInstanceComponent*>(comp)->getQualityValue();
return quality < 0 ? _strengths.front() : quality >= _strengths.size() ? _strengths.back() : _strengths[quality];
}
示例15: MonsterInstance
void Room::initializeFromFile(std::ifstream& fin, std::vector<Monster>& temp, std::vector<Items>& temp2, int level) {
initialized = true;
fin >> width;
fin >> height;
int nMonsters;
fin >> nMonsters;
for (int i = 0; i < nMonsters; i++) {
std::string name;
fin >> name;
MonsterInstance* m = 0;
for (int i = 0; i < temp.size(); i++) {
if (!name.compare(temp[i].getName()))
m = new MonsterInstance(temp[i]);
}
if (m == 0) throw "bad monster name";
int x, y;
fin >> x;
fin >> y;
m->setCoords(x, y);
monsters.push_back(*m);
}
int nItems;
fin >> nItems;
for (int i = 0; i < nItems; i++) {
std::string name;
fin >> name;
ItemInstance* m = 0;
for (int i = 0; i < temp2.size(); i++) {
if (!name.compare(temp2[i].getName()))
m = new ItemInstance(temp2[i]);
}
if (m == 0) throw "bad item name";
int x, y;
fin >> x;
fin >> y;
m->setCoords(x, y);
items.push_back(*m);
}
}