void Player::_SaveInventory() { // force items in buyback slots to new state // and remove those that aren't already for (uint8 i = BUYBACK_SLOT_START; i < BUYBACK_SLOT_END; i++) { Item *item = m_items[i]; if (!item || item->GetState() == ITEM_NEW) continue; CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item->GetGUIDLow()); CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid = '%u'", item->GetGUIDLow()); m_items[i]->FSetState(ITEM_NEW); } // update enchantment durations for(EnchantDurationList::iterator itr = m_enchantDuration.begin();itr != m_enchantDuration.end();++itr) { itr->item->SetEnchantmentDuration(itr->slot,itr->leftduration); } // if no changes if (m_itemUpdateQueue.empty()) return; // do not save if the update queue is corrupt bool error = false; for(size_t i = 0; i < m_itemUpdateQueue.size(); i++) { Item *item = m_itemUpdateQueue[i]; if(!item || item->GetState() == ITEM_REMOVED) continue; Item *test = GetItemByPos( item->GetBagSlot(), item->GetSlot()); if (test == NULL) { sLog.outError("Player::_SaveInventory - the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have an item at that position!", item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow()); error = true; } else if (test != item) { sLog.outError("Player::_SaveInventory - the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the item with guid %d is there instead!", item->GetBagSlot(), item->GetSlot(), item->GetGUIDLow(), test->GetGUIDLow()); error = true; } } if (error) { sLog.outError("Player::_SaveInventory - one or more errors occurred save aborted!"); ChatHandler(this).SendSysMessage(LANG_ITEM_SAVE_FAILED); return; } for(size_t i = 0; i < m_itemUpdateQueue.size(); i++) { Item *item = m_itemUpdateQueue[i]; if(!item) continue; Bag *container = item->GetContainer(); uint32 bag_guid = container ? container->GetGUIDLow() : 0; switch(item->GetState()) { case ITEM_NEW: CharacterDatabase.PExecute("INSERT INTO character_inventory (guid,bag,slot,item,item_template) VALUES ('%u', '%u', '%u', '%u', '%u')", GetGUIDLow(), bag_guid, item->GetSlot(), item->GetGUIDLow(), item->GetEntry()); break; case ITEM_CHANGED: CharacterDatabase.PExecute("UPDATE character_inventory SET guid='%u', bag='%u', slot='%u', item_template='%u' WHERE item='%u'", GetGUIDLow(), bag_guid, item->GetSlot(), item->GetEntry(), item->GetGUIDLow()); break; case ITEM_REMOVED: CharacterDatabase.PExecute("DELETE FROM character_inventory WHERE item = '%u'", item->GetGUIDLow()); break; case ITEM_UNCHANGED: break; } item->SaveToDB(); } m_itemUpdateQueue.clear(); }