54 QueryResult result =
WorldDatabase.Query(
"SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template");
58 TC_LOG_INFO(
"server.loading",
">> Loaded 0 skill discovery definitions. DB table `skill_discovery_template` is empty.");
64 std::ostringstream ssNonDiscoverableEntries;
65 std::set<uint32> reportedReqSpells;
69 Field* fields = result->Fetch();
78 ssNonDiscoverableEntries <<
"spellId = " << spellId <<
" reqSkillOrSpell = " << reqSkillOrSpell
79 <<
" reqSkillValue = " << reqSkillValue <<
" chance = " << chance <<
"(chance problem)\n";
83 if (reqSkillOrSpell > 0)
89 if (reportedReqSpells.find(absReqSkillOrSpell) == reportedReqSpells.end())
91 TC_LOG_ERROR(
"sql.sql",
"Spell (ID: {}) has a non-existing spell (ID: {}) in `reqSpell` field in the `skill_discovery_template` table.", spellId, reqSkillOrSpell);
92 reportedReqSpells.insert(absReqSkillOrSpell);
102 if (reportedReqSpells.find(absReqSkillOrSpell) == reportedReqSpells.end())
104 TC_LOG_ERROR(
"sql.sql",
"Spell (ID: {}) does not have any MECHANIC_DISCOVERY (28) value in the Mechanic field in spell.dbc"
105 " nor 100% chance random discovery ability, but is listed for spellId {} (and maybe more) in the `skill_discovery_template` table.",
106 absReqSkillOrSpell, spellId);
107 reportedReqSpells.insert(absReqSkillOrSpell);
114 else if (reqSkillOrSpell == 0)
118 if (bounds.first == bounds.second)
120 TC_LOG_ERROR(
"sql.sql",
"Spell (ID: {}) is not listed in `SkillLineAbility.dbc`, but listed with `reqSpell`= 0 in the `skill_discovery_template` table.", spellId);
124 for (SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
129 TC_LOG_ERROR(
"sql.sql",
"Spell (ID: {}) has a negative value in `reqSpell` field in the `skill_discovery_template` table.", spellId);
135 while (result->NextRow());
137 if (!ssNonDiscoverableEntries.str().empty())
138 TC_LOG_ERROR(
"sql.sql",
"Some items can't be successfully discovered, their chance field value is < 0.000001 in the `skill_discovery_template` DB table. List:\n{}", ssNonDiscoverableEntries.str());
141 for (
uint32 spell_id = 1; spell_id <
sSpellMgr->GetSpellInfoStoreSize(); ++spell_id)
152 TC_LOG_ERROR(
"sql.sql",
"Spell (ID: {}) has got 100% chance random discovery ability, but does not have data in the `skill_discovery_template` table.", spell_id);
169 float full_chance = 0;
170 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
171 if (item_iter->reqSkillValue <= skillvalue)
172 if (!player->
HasSpell(item_iter->spellId))
173 full_chance += item_iter->chance;
175 float rate = full_chance / 100.0f;
178 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
180 if (item_iter->reqSkillValue > skillvalue)
183 if (player->
HasSpell(item_iter->spellId))
186 if (item_iter->chance > roll)
187 return item_iter->spellId;
189 roll -= item_iter->chance;
230 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
233 item_iter->reqSkillValue <= skillvalue &&
234 !player->
HasSpell(item_iter->spellId))
235 return item_iter->spellId;
248 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
251 item_iter->reqSkillValue <= skillvalue &&
252 !player->
HasSpell(item_iter->spellId))
253 return item_iter->spellId;
SkillDiscoveryEntry(uint32 _spellId, uint32 req_skill_val, float _chance)