Ejemplo n.º 1
0
void Stash::CreateAndAddItem(const ItemType itemType, const ItemID itemID)
{
    Item* newItem = ItemFactory::Instance().CreateItem(itemType, itemID);
    if( newItem == nullptr )
    {
        ASSERT_DEBUG(newItem != nullptr);
        return;
    }

    const ItemGroup itemGroup = newItem->GetItemGroup();
    ItemList& itemList = this->m_ItemList[itemGroup];

    {
        ScopedLock lockForSerialize(m_LockForSerialize);
        itemList.push_back(newItem);
    }
}
Ejemplo n.º 2
0
BOOL Stash::MoveItemToAnotherStash(Stash& stash, const ItemID itemID)
{
    Item* moveItem = nullptr;
    BOOL result = false;
    
    {
        ScopedLock lockForSerialize(m_LockForSerialize);
        for( INT i = 0; i< ItemGroup_Max; ++i )
        {
            ItemList& itemList = m_ItemList[i];
            ItemList::iterator iter = std::find_if(itemList.begin() , itemList.end(), [itemID](Item* item)->bool
                {
                    if( item->GetItemID() == itemID )
                    {
                        return true;
                    }
                    return false;
                });
            if( iter != itemList.end() )
            {
                moveItem = *iter;
                itemList.erase(iter);
                result = true;
                
                break;
            }
        }
    }
    
    if( moveItem != nullptr )
    {
        ScopedLock lockForSerialize(stash.m_LockForSerialize);
        stash.m_ItemList[moveItem->GetItemGroup()].push_back(moveItem);
    }
    
    return result;
}