mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-20 09:11:30 +00:00
[Feature] Change #scribespells to be aware of spellgroups & ranks (#2501)
* Change #scribespells to be aware of spellgroups & ranks * Formatting * Fix Formatting, and change stored return data type to match function return type. * Compact If Statements * Implemented SQL Query to reduce number of iterations required. * Cleaned up Query, and improved performance * Cleaned up SQL Queries * Formatting * Indenting fix. * Update client.cpp * Fix Formatting in spells.cpp * Fix ValueWithin. Co-authored-by: Kinglykrab <kinglykrab@gmail.com> Co-authored-by: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com>
This commit is contained in:
parent
e01ac39887
commit
33b95c42c2
@ -10513,6 +10513,8 @@ std::vector<int> Client::GetMemmedSpells() {
|
||||
|
||||
std::vector<int> Client::GetScribeableSpells(uint8 min_level, uint8 max_level) {
|
||||
std::vector<int> scribeable_spells;
|
||||
std::unordered_map<uint32, std::vector<uint16>> spell_group_cache = LoadSpellGroupCache(min_level, max_level);
|
||||
|
||||
for (uint16 spell_id = 0; spell_id < SPDAT_RECORDS; ++spell_id) {
|
||||
bool scribeable = true;
|
||||
if (!IsValidSpell(spell_id)) {
|
||||
@ -10547,13 +10549,33 @@ std::vector<int> Client::GetScribeableSpells(uint8 min_level, uint8 max_level) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RuleB(Spells, EnableSpellGlobals) && !SpellGlobalCheck(spell_id, CharacterID())) {
|
||||
if (
|
||||
RuleB(Spells, EnableSpellGlobals) &&
|
||||
!SpellGlobalCheck(spell_id, CharacterID())
|
||||
) {
|
||||
scribeable = false;
|
||||
} else if (RuleB(Spells, EnableSpellBuckets) && !SpellBucketCheck(spell_id, CharacterID())) {
|
||||
} else if (
|
||||
RuleB(Spells, EnableSpellBuckets) &&
|
||||
!SpellBucketCheck(spell_id, CharacterID())
|
||||
) {
|
||||
scribeable = false;
|
||||
}
|
||||
|
||||
if (scribeable) {
|
||||
if (spells[spell_id].spell_group) {
|
||||
const auto& g = spell_group_cache.find(spells[spell_id].spell_group);
|
||||
if (g != spell_group_cache.end()) {
|
||||
for (const auto& s : g->second) {
|
||||
if (
|
||||
EQ::ValueWithin(spells[s].classes[m_pp.class_ - 1], min_level, max_level) &&
|
||||
s == spell_id &&
|
||||
scribeable
|
||||
) {
|
||||
scribeable_spells.push_back(spell_id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else if (scribeable) {
|
||||
scribeable_spells.push_back(spell_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1062,6 +1062,7 @@ public:
|
||||
inline uint32 GetSpellByBookSlot(int book_slot) { return m_pp.spell_book[book_slot]; }
|
||||
inline bool HasSpellScribed(int spellid) { return FindSpellBookSlotBySpellID(spellid) != -1; }
|
||||
uint32 GetHighestScribedSpellinSpellGroup(uint32 spell_group);
|
||||
std::unordered_map<uint32, std::vector<uint16>> LoadSpellGroupCache(uint8 min_level, uint8 max_level);
|
||||
uint16 GetMaxSkillAfterSpecializationRules(EQ::skills::SkillType skillid, uint16 maxSkill);
|
||||
void SendPopupToClient(const char *Title, const char *Text, uint32 PopupID = 0, uint32 Buttons = 0, uint32 Duration = 0);
|
||||
void SendFullPopup(const char *Title, const char *Text, uint32 PopupID = 0, uint32 NegativeID = 0, uint32 Buttons = 0, uint32 Duration = 0, const char *ButtonName0 = 0, const char *ButtonName1 = 0, uint32 SoundControls = 0);
|
||||
|
||||
@ -5520,6 +5520,33 @@ uint32 Client::GetHighestScribedSpellinSpellGroup(uint32 spell_group)
|
||||
return highest_spell_id;
|
||||
}
|
||||
|
||||
std::unordered_map<uint32, std::vector<uint16>> Client::LoadSpellGroupCache(uint8 min_level, uint8 max_level) {
|
||||
std::unordered_map<uint32, std::vector<uint16>> spell_group_cache;
|
||||
|
||||
const auto query = fmt::format(
|
||||
"SELECT a.spellgroup, a.id, a.rank "
|
||||
"FROM spells_new a "
|
||||
"INNER JOIN ("
|
||||
"SELECT spellgroup, MAX(rank) rank "
|
||||
"FROM spells_new "
|
||||
"GROUP BY spellgroup) "
|
||||
"b ON a.spellgroup = b.spellgroup AND a.rank = b.rank "
|
||||
"WHERE a.spellgroup IN (SELECT DISTINCT spellgroup FROM spells_new WHERE spellgroup != 0 and classes{} BETWEEN {} AND {}) ORDER BY rank DESC",
|
||||
m_pp.class_, min_level, max_level
|
||||
);
|
||||
|
||||
auto results = database.QueryDatabase(query);
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return spell_group_cache;
|
||||
}
|
||||
|
||||
for (auto row : results) {
|
||||
spell_group_cache[std::stoul(row[0])].push_back(static_cast<uint16>(std::stoul(row[1])));
|
||||
}
|
||||
|
||||
return spell_group_cache;
|
||||
}
|
||||
|
||||
bool Client::SpellGlobalCheck(uint16 spell_id, uint32 character_id) {
|
||||
std::string query = fmt::format(
|
||||
"SELECT qglobal, value FROM spell_globals WHERE spellid = {}",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user