41 QueryResult result =
WorldDatabase.Query(
"SELECT spellId, reqSpell, reqSkillValue, chance FROM skill_discovery_template");
45 SF_LOG_ERROR(
"server.loading",
">> Loaded 0 skill discovery definitions. DB table `skill_discovery_template` is empty.");
51 std::ostringstream ssNonDiscoverableEntries;
52 std::set<uint32> reportedReqSpells;
56 Field* fields = result->Fetch();
65 ssNonDiscoverableEntries <<
"spellId = " << spellId <<
" reqSkillOrSpell = " << reqSkillOrSpell
66 <<
" reqSkillValue = " << reqSkillValue <<
" chance = " << chance <<
"(chance problem)\n";
70 if (reqSkillOrSpell > 0)
76 if (reportedReqSpells.find(absReqSkillOrSpell) == reportedReqSpells.end())
78 SF_LOG_ERROR(
"sql.sql",
"Spell (ID: %u) have not existed spell (ID: %i) in `reqSpell` field in `skill_discovery_template` table", spellId, reqSkillOrSpell);
79 reportedReqSpells.insert(absReqSkillOrSpell);
89 if (reportedReqSpells.find(absReqSkillOrSpell) == reportedReqSpells.end())
91 SF_LOG_ERROR(
"sql.sql",
"Spell (ID: %u) not have MECHANIC_DISCOVERY (28) value in Mechanic field in spell.dbc"
92 " and not 100%% chance random discovery ability but listed for spellId %u (and maybe more) in `skill_discovery_template` table",
93 absReqSkillOrSpell, spellId);
94 reportedReqSpells.insert(absReqSkillOrSpell);
101 else if (reqSkillOrSpell == 0)
105 if (bounds.first == bounds.second)
107 SF_LOG_ERROR(
"sql.sql",
"Spell (ID: %u) not listed in `SkillLineAbility.dbc` but listed with `reqSpell`=0 in `skill_discovery_template` table", spellId);
111 for (SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
116 SF_LOG_ERROR(
"sql.sql",
"Spell (ID: %u) have negative value in `reqSpell` field in `skill_discovery_template` table", spellId);
121 }
while (result->NextRow());
123 if (!ssNonDiscoverableEntries.str().empty())
124 SF_LOG_ERROR(
"sql.sql",
"Some items can't be successfully discovered: have in chance field value < 0.000001 in `skill_discovery_template` DB table . List:\n%s", ssNonDiscoverableEntries.str().c_str());
127 for (
uint32 spell_id = 1; spell_id <
sSpellMgr->GetSpellInfoStoreSize(); ++spell_id)
138 SF_LOG_ERROR(
"sql.sql",
"Spell (ID: %u) is 100%% chance random discovery ability but not have data in `skill_discovery_template` table", spell_id);
155 float full_chance = 0;
156 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
157 if (item_iter->reqSkillValue <= skillvalue)
158 if (!player->
HasSpell(item_iter->spellId))
159 full_chance += item_iter->chance;
161 float rate = full_chance / 100.0f;
164 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
166 if (item_iter->reqSkillValue > skillvalue)
169 if (player->
HasSpell(item_iter->spellId))
172 if (item_iter->chance > roll)
173 return item_iter->spellId;
175 roll -= item_iter->chance;
203 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
206 item_iter->reqSkillValue <= skillvalue &&
207 !player->
HasSpell(item_iter->spellId))
208 return item_iter->spellId;
221 for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
224 item_iter->reqSkillValue <= skillvalue &&
225 !player->
HasSpell(item_iter->spellId))
226 return item_iter->spellId;
SkillDiscoveryEntry(uint32 _spellId, uint32 req_skill_val, float _chance)