uint32 GetItemEnchantMod(int32 entry) { if (!entry) return 0; EnchantmentStore::const_iterator tab; if (entry > 0) { tab = RandomItemPropEnch.find(entry); if (tab == RandomItemPropEnch.end()) { sLog.outErrorDb("Item RandomProperty id #%u used in `item_template` but it doesn't have records in `item_enchantment_template` table.", entry); return 0; } } else { tab = RandomItemSuffixEnch.find(-entry); if (tab == RandomItemSuffixEnch.end()) { sLog.outErrorDb("Item RandomSuffix id #%u used in `item_template` but it doesn't have records in `item_enchantment_template` table.", -entry); return 0; } } double dRoll = rand_chance(); float fCount = 0; for(EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { fCount += ench_iter->chance; if (fCount > dRoll) return ench_iter->ench; } //we could get here only if sum of all enchantment chances is lower than 100% dRoll = (irand(0, (int)floor(fCount * 100) + 1)) / 100; fCount = 0; for(EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { fCount += ench_iter->chance; if (fCount > dRoll) return ench_iter->ench; } return 0; }
int* RandItemEnch(int32 item_id) { uint32 count = 0; ItemTemplate const* item = sObjectMgr->GetItemTemplate(item_id); if (item->RandomProperty) { EnchantmentStore::const_iterator tab = RandomItemEnch.find(item->RandomProperty); if (tab == RandomItemEnch.end()) return randitemench; EnchStoreList::const_iterator ench_iter = tab->second.begin(); for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { randitemench[count] = ench_iter->ench; count++; } } else { EnchantmentStore::const_iterator tab = RandomItemEnch.find(item->RandomSuffix); if (tab == RandomItemEnch.end()) return randitemench; EnchStoreList::const_iterator ench_iter = tab->second.begin(); for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { randitemench[count] = ench_iter->ench; count++; } } return randitemench; }
std::string* RandItemSuffix(int32 item_id) { uint32 count = 0; ItemTemplate const* item = sObjectMgr->GetItemTemplate(item_id); if (item->RandomProperty) { EnchantmentStore::const_iterator tab = RandomItemEnch.find(item->RandomProperty); if (tab == RandomItemEnch.end()) return randitemsuffix; EnchStoreList::const_iterator ench_iter = tab->second.begin(); for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { const ItemRandomPropertiesEntry* random_id = sItemRandomPropertiesStore.LookupEntry(ench_iter->ench); if ((count <= 31) && (ench_iter->ench != 0)) { randitemsuffix[count] = random_id->nameSuffix[2]; } count++; } } else { EnchantmentStore::const_iterator tab = RandomItemEnch.find(item->RandomSuffix); if (tab == RandomItemEnch.end()) return randitemsuffix; EnchStoreList::const_iterator ench_iter = tab->second.begin(); for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { const ItemRandomSuffixEntry* random_id = sItemRandomSuffixStore.LookupEntry(ench_iter->ench); if ((count <= 31) && (ench_iter->ench != 0)) { randitemsuffix[count] = random_id->nameSuffix[2]; } count++; } } return randitemsuffix; }
uint32 GetItemEnchantMod(int32 entry, uint32 type) { if (!entry) return 0; if (entry == -1) return 0; EnchantmentStore::const_iterator tab = type == ENCHANTMENT_RANDOM_PROPERTY ? RandomPropertyItemEnch.find(entry) : RandomSuffixItemEnch.find(entry) ; if (tab == (type == ENCHANTMENT_RANDOM_PROPERTY ? RandomPropertyItemEnch.end() : RandomSuffixItemEnch.end())) { sLog->outError(LOG_FILTER_SQL, "Item RandomProperty / RandomSuffix id #%u used in `item_template` but it does not have records in `item_enchantment_template` table.", entry); return 0; } double dRoll = rand_chance(); float fCount = 0; for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { fCount += ench_iter->chance; if (fCount > dRoll) return ench_iter->ench; } //we could get here only if sum of all enchantment chances is lower than 100% dRoll = (irand(0, (int)floor(fCount * 100) + 1)) / 100; fCount = 0; for (EnchStoreList::const_iterator ench_iter = tab->second.begin(); ench_iter != tab->second.end(); ++ench_iter) { fCount += ench_iter->chance; if (fCount > dRoll) return ench_iter->ench; } return 0; }