void AuctionHouseMgr::LoadAuctionItems() { uint32 oldMSTime = getMSTime(); // need to clear in case we are reloading if (!mAitems.empty()) { for (ItemMap::iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr) delete itr->second; mAitems.clear(); } // data needs to be at first place for Item::LoadFromDB PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_AUCTION_ITEMS); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (!result) { TC_LOG_INFO("server.loading", ">> Loaded 0 auction items. DB table `auctionhouse` or `item_instance` is empty!"); return; } uint32 count = 0; do { Field* fields = result->Fetch(); uint32 item_guid = fields[11].GetUInt32(); uint32 itemEntry = fields[12].GetUInt32(); ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry); if (!proto) { TC_LOG_ERROR("misc", "AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid, itemEntry); continue; } Item* item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, fields, itemEntry)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); TC_LOG_INFO("server.loading", ">> Loaded %u auction items in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); }
bool Bag::LoadFromDB(uint32 guid, uint64 owner_guid) { if(!Item::LoadFromDB(guid, owner_guid)) return false; // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) for (uint32 i = 0; i < GetProto()->ContainerSlots; i++) { SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0); if (m_bagslot[i]) { delete m_bagslot[i]; m_bagslot[i] = NULL; } } if(!IsInBag()) // equiped bag { QueryResult *result = sDatabase.PQuery("SELECT `slot`,`item`,`item_template` FROM `character_inventory` WHERE `guid` = '%u' AND `bag` = '%u'", GUID_LOPART(GetOwnerGUID()), GetGUIDLow()); if (result) { do { Field *fields = result->Fetch(); uint8 slot = fields[0].GetUInt8(); uint32 item_guid = fields[1].GetUInt32(); uint32 item_id = fields[2].GetUInt32(); ItemPrototype const *proto = objmgr.GetItemPrototype(item_id); if(!proto) { sLog.outError( "Bag::LoadFromDB: Player %d have unknown item (id: #%u) in bag #%u, skipped.", GUID_LOPART(GetOwnerGUID()), item_id, GetSlot()); continue; } Item *item = NewItemOrBag(proto); item->SetSlot(NULL_SLOT); if(!item->LoadFromDB(item_guid, owner_guid)) { delete item; continue; } StoreItem( slot, item, true ); item->SetState(ITEM_UNCHANGED); } while (result->NextRow()); delete result; } } return true; }
void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB 0 1 2 3 QueryResult *result = CharacterDatabase.Query("SELECT data,text,itemguid,item_template FROM auction JOIN item_instance ON itemguid = guid"); if (!result) { BarGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded 0 auction items"); return; } BarGoLink bar(result->GetRowCount()); uint32 count = 0; Field *fields; do { bar.step(); fields = result->Fetch(); uint32 item_guid = fields[2].GetUInt32(); uint32 item_template = fields[3].GetUInt32(); ItemPrototype const *proto = ObjectMgr::GetItemPrototype(item_template); if (!proto) { sLog.outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); continue; } Item *item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, fields)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); delete result; sLog.outString(); sLog.outString(">> Loaded %u auction items", count); }
void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB // 0 1 2 3 4 5 6 7 8 9 10 11 12 QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, playedTime, text, itemguid, item_template FROM auctionhouse JOIN item_instance ON itemguid = guid"); if (!result) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded 0 auction items"); return; } barGoLink bar(result->GetRowCount()); uint32 count = 0; Field *fields; do { bar.step(); fields = result->Fetch(); uint32 item_guid = fields[11].GetUInt32(); uint32 item_template = fields[12].GetUInt32(); ItemPrototype const *proto = objmgr.GetItemPrototype(item_template); if (!proto) { sLog.outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); continue; } Item *item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, result, item_template)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u auction items", count); }
void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_LOAD_AUCTION_ITEMS); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (!result) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded 0 auction items"); return; } barGoLink bar(result->GetRowCount()); uint32 count = 0; do { bar.step(); uint32 item_guid = result->GetUInt32(11); uint32 item_template = result->GetUInt32(12); ItemPrototype const *proto = sObjectMgr.GetItemPrototype(item_template); if (!proto) { sLog.outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); continue; } Item *item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, result, item_template)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u auction items", count); }
void AuctionHouseMgr::LoadAuctionItems() { uint32 oldMSTime = getMSTime(); // data needs to be at first place for Item::LoadFromDB PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_LOAD_AUCTION_ITEMS); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (!result) { sLog->outString(">> Loaded 0 auction items. DB table `auctionhouse` or `item_instance` is empty!"); sLog->outString(); return; } uint32 count = 0; do { Field* fields = result->Fetch(); uint32 item_guid = fields[11].GetUInt32(); uint32 item_template = fields[12].GetUInt32(); ItemPrototype const *proto = ObjectMgr::GetItemPrototype(item_template); if (!proto) { sLog->outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); continue; } Item *item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, fields, item_template)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); sLog->outString(">> Loaded %u auction items in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); sLog->outString(); }
void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT data, itemguid, item_template FROM auctionhouse JOIN item_instance ON itemguid = guid"); if (!result) { sLog->outString(); sLog->outString(">> Loaded 0 auction items"); return; } uint32 count = 0; Field *fields; do { fields = result->Fetch(); uint32 item_guid = fields[1].GetUInt32(); uint32 item_template = fields[2].GetUInt32(); ItemPrototype const *proto = sObjectMgr->GetItemPrototype(item_template); if (!proto) { sLog->outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid, item_template); continue; } Item *item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, result)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); sLog->outString(); sLog->outString(">> Loaded %u auction items", count); }
void AuctionHouseMgr::LoadAuctionItems() { // data needs to be at first place for Item::LoadFromDB QueryResult_AutoPtr result = CharacterDatabase.Query("SELECT itemEntry, creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, itemTextId, itemguid, item_template FROM auctionhouse JOIN item_instance ON itemguid = guid"); if (!result) { sLog.outString(">> Loaded 0 auction items"); return; } uint32 count = 0; Field* fields; do { fields = result->Fetch(); uint32 item_guid = fields[11].GetUInt32(); uint32 item_template = fields[12].GetUInt32(); ItemTemplate const* proto = sObjectMgr.GetItemTemplate(item_template); if (!proto) { sLog.outError("AuctionHouseMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid, item_template); continue; } Item* item = NewItemOrBag(proto); if (!item->LoadFromDB(item_guid, 0, fields)) { delete item; continue; } AddAItem(item); ++count; } while (result->NextRow()); sLog.outString(">> Loaded %u auction items", count); }
void ObjectMgr::LoadMailedItems() { QueryResult *result = sDatabase.Query( "SELECT `guid` FROM `mail_item`" ); if( !result ) return; Field *fields; do { fields = result->Fetch(); Item* item = new Item; if(!item->LoadFromDB(fields[0].GetUInt32(), 0, 3)) continue; AddMItem(item); } while( result->NextRow() ); delete result; }
void Bag::LoadFromDB(uint64 GUID, uint64 OwnerGUID, uint64 ItemID) { Item::LoadFromDB(GUID, OwnerGUID, ItemID); QueryResult Result(sDatabase.PQuery("SELECT * FROM `items` WHERE `bagid` = %llu", GUID)); // TODO: Use only needed row. while (Result->next()) { uint64 ItemGUID = Result->getUInt64 (1); uint64 DB_OwnerGUID = Result->getUInt64 (2); uint64 BagGUID = Result->getUInt64 (3); uint8 Slot = Result->getUInt (4); uint64 ItemID = Result->getUInt64 (5); Item* pNewItem = new Item; pNewItem->LoadFromDB(ItemGUID, OwnerGUID, ItemID); m_Items[Slot] = pNewItem; } }
bool Guild::BankTab::LoadItemFromDB(Field* fields) { uint8 slotId = fields[13].GetUInt8(); uint32 itemGuid = fields[14].GetUInt32(); uint32 itemEntry = fields[15].GetUInt32(); if (slotId >= GUILD_BANK_MAX_SLOTS) { TC_LOG_ERROR(LOG_FILTER_GUILD, "Invalid slot for item (GUID: %u, id: %u) in guild bank, skipped.", itemGuid, itemEntry); return false; } ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry); if (!proto) { TC_LOG_ERROR(LOG_FILTER_GUILD, "Unknown item (GUID: %u, id: %u) in guild bank, skipped.", itemGuid, itemEntry); return false; } Item* pItem = NewItemOrBag(proto); if (!pItem->LoadFromDB(itemGuid, 0, fields, itemEntry)) { TC_LOG_ERROR(LOG_FILTER_GUILD, "Item (GUID %u, id: %u) not found in item_instance, deleting from guild bank!", itemGuid, itemEntry); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_NONEXISTENT_GUILD_BANK_ITEM); stmt->setUInt32(0, m_guildId); stmt->setUInt8 (1, m_tabId); stmt->setUInt8 (2, slotId); CharacterDatabase.Execute(stmt); delete pItem; return false; } pItem->AddToWorld(); m_items[slotId] = pItem; return true; }