void Item::LoadLootFromDB(Field* fields) { uint32 itemId = fields[1].GetUInt32(); uint32 itemAmount = fields[2].GetUInt32(); // money value special case if (!itemId) { loot.gold = itemAmount; SetLootState(ITEM_LOOT_UNCHANGED); return; } // normal item case ItemPrototype const* proto = ObjectMgr::GetItemPrototype(itemId); if (!proto) { DeleteLootFromDB(GetGUIDLow(), itemId); sLog.outError("Item::LoadLootFromDB: %s has an unknown item (id: %u) in item_loot, deleted.", GetGuidStr().c_str(), itemId); return; } uint32 itemSuffix = fields[3].GetUInt32(); int32 itemPropId = fields[4].GetInt32(); loot.items.push_back(LootItem(itemId, itemAmount, itemSuffix, itemPropId)); ++loot.unlootedCount; SetLootState(ITEM_LOOT_UNCHANGED); }
void Item::LoadLootFromDB(Field *fields) { uint32 item_id = fields[1].GetUInt32(); uint32 item_amount = fields[2].GetUInt32(); uint32 item_suffix = fields[3].GetUInt32(); int32 item_propid = fields[4].GetInt32(); // money value special case if (item_id == 0) { loot.gold = item_amount; SetLootState(ITEM_LOOT_UNCHANGED); return; } // normal item case ItemPrototype const* proto = ObjectMgr::GetItemPrototype(item_id); if(!proto) { CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u' AND itemid = '%u'", GetGUIDLow(), item_id); sLog.outError("Item::LoadLootFromDB: %s has an unknown item (id: #%u) in item_loot, deleted.", GetOwnerGuid().GetString().c_str(), item_id); return; } loot.items.push_back(LootItem(item_id, item_amount, item_suffix, item_propid)); ++loot.unlootedCount; SetLootState(ITEM_LOOT_UNCHANGED); }
void Item::LoadLootFromDB(Field* fields) { uint32 item_id = abs(fields[1].GetInt32()); uint8 type = fields[1].GetInt32() > 0 ? LOOT_ITEM_TYPE_ITEM : LOOT_ITEM_TYPE_CURRENCY; uint32 item_amount = fields[2].GetUInt32(); uint32 item_suffix = fields[3].GetUInt32(); int32 item_propid = fields[4].GetInt32(); // money value special case if (item_id == 0) { loot.gold = item_amount; SetLootState(ITEM_LOOT_UNCHANGED); return; } // normal item case if (type == LOOT_ITEM_TYPE_ITEM) { ItemPrototype const* proto = ObjectMgr::GetItemPrototype(item_id); if (!proto) { CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u' AND itemid = '%u'", GetGUIDLow(), item_id); sLog.outError("Item::LoadLootFromDB: %s has an unknown item (id: #%u) in item_loot, deleted.", GetOwnerGuid().GetString().c_str(), item_id); return; } loot.items.push_back(LootItem(item_id, type, item_amount, item_suffix, item_propid)); } // currency case else //if (type == LOOT_ITEM_TYPE_CURRENCY) { CurrencyTypesEntry const* currencyEntry = sCurrencyTypesStore.LookupEntry(item_id); if (!currencyEntry) { CharacterDatabase.PExecute("DELETE FROM item_loot WHERE guid = '%u' AND itemid = '%i'", GetGUIDLow(), -int32(item_id)); sLog.outError("Item::LoadLootFromDB: %s has an unknown currency (id: #%u) in item_loot, deleted.", GetOwnerGuid().GetString().c_str(), item_id); return; } loot.items.push_back(LootItem(item_id, type, item_amount)); } ++loot.unlootedCount; SetLootState(ITEM_LOOT_UNCHANGED); }
bool Item::ItemContainerLoadLootFromDB() { // Loads the money and item loot associated with an openable item from the DB // Default. If there are no records for this item then it will be rolled for in Player::SendLoot() m_lootGenerated = false; ObjectGuid::LowType container_id = GetGUID().GetCounter(); // Save this for later use loot.containerID = container_id; // First, see if there was any money loot. This gets added directly to the container. PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ITEMCONTAINER_MONEY); stmt->setUInt32(0, container_id); PreparedQueryResult money_result = CharacterDatabase.Query(stmt); if (money_result) { Field* fields = money_result->Fetch(); loot.gold = fields[0].GetUInt32(); } // Next, load any items that were saved stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ITEMCONTAINER_ITEMS); stmt->setUInt32(0, container_id); PreparedQueryResult item_result = CharacterDatabase.Query(stmt); if (item_result) { // Get a LootTemplate for the container item. This is where // the saved loot was originally rolled from, we will copy conditions from it LootTemplate const* lt = LootTemplates_Item.GetLootFor(GetEntry()); if (lt) { do { // Create an empty LootItem LootItem loot_item = LootItem(); // Fill in the rest of the LootItem from the DB Field* fields = item_result->Fetch(); // item_id, itm_count, follow_rules, ffa, blocked, counted, under_threshold, needs_quest, rnd_prop, rnd_suffix loot_item.itemid = fields[0].GetUInt32(); loot_item.count = fields[1].GetUInt32(); loot_item.follow_loot_rules = fields[2].GetBool(); loot_item.freeforall = fields[3].GetBool(); loot_item.is_blocked = fields[4].GetBool(); loot_item.is_counted = fields[5].GetBool(); loot_item.canSave = true; loot_item.is_underthreshold = fields[6].GetBool(); loot_item.needs_quest = fields[7].GetBool(); loot_item.randomPropertyId = fields[8].GetInt32(); loot_item.randomSuffix = fields[9].GetUInt32(); // Copy the extra loot conditions from the item in the loot template lt->CopyConditions(&loot_item); // If container item is in a bag, add that player as an allowed looter if (GetBagSlot()) loot_item.allowedGUIDs.insert(GetOwner()->GetGUID().GetCounter()); // Finally add the LootItem to the container loot.items.push_back(loot_item); // Increment unlooted count loot.unlootedCount++; } while (item_result->NextRow()); } } // Mark the item if it has loot so it won't be generated again on open m_lootGenerated = !loot.isLooted(); return m_lootGenerated; }