From 65704274cbddd135dd815eb1c2f2f8f061f790b8 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 14 Feb 2021 19:15:09 -0500 Subject: [PATCH] [Quest API] Resolves traindiscs and scribespells issues in Perl/Lua. (#1249) --- zone/client.cpp | 2 ++ zone/questmgr.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index fb265dcd0..cdd32ee69 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -10091,6 +10091,8 @@ std::vector Client::GetScribeableSpells(uint8 min_level, uint8 max_level) { bool scribeable = false; if (!IsValidSpell(spell_id)) continue; + if (IsDiscipline(spell_id)) + continue; if (spells[spell_id].classes[WARRIOR] == 0) continue; if (max_level > 0 && spells[spell_id].classes[m_pp.class_ - 1] > max_level) diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index a61a4e856..c3c8ac8b1 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -1090,6 +1090,7 @@ uint16 QuestManager::scribespells(uint8 max_level, uint8 min_level) { int book_slot = initiator->GetNextAvailableSpellBookSlot(); std::vector spell_ids = initiator->GetScribeableSpells(min_level, max_level); int spell_count = spell_ids.size(); + int spells_learned = 0; if (spell_count > 0) { for (auto spell_id : spell_ids) { if (book_slot == -1) { @@ -1099,11 +1100,21 @@ uint16 QuestManager::scribespells(uint8 max_level, uint8 min_level) { ); break; } + + if (initiator->HasSpellScribed(spell_id)) + continue; + initiator->ScribeSpell(spell_id, book_slot); book_slot = initiator->GetNextAvailableSpellBookSlot(book_slot); + spells_learned++; } } - return spell_count; + + if (spells_learned > 0) { + std::string spell_message = (spells_learned == 1 ? "a new spell" : fmt::format("{} new spells", spells_learned)); + initiator->Message(Chat::White, fmt::format("You have learned {}!", spell_message).c_str()); + } + return spells_learned; } uint16 QuestManager::traindiscs(uint8 max_level, uint8 min_level) { @@ -1111,24 +1122,30 @@ uint16 QuestManager::traindiscs(uint8 max_level, uint8 min_level) { int character_id = initiator->CharacterID(); std::vector spell_ids = initiator->GetLearnableDisciplines(min_level, max_level); int discipline_count = spell_ids.size(); - bool discipline_learned = false; + int disciplines_learned = 0; if (discipline_count > 0) { for (auto spell_id : spell_ids) { + if (initiator->HasDisciplineLearned(spell_id)) + continue; + for (uint32 index = 0; index < MAX_PP_DISCIPLINES; index++) { if (initiator->GetPP().disciplines.values[index] == 0) { initiator->GetPP().disciplines.values[index] = spell_id; database.SaveCharacterDisc(character_id, index, spell_id); - initiator->Message(Chat::White, "You have learned a new discipline!"); - discipline_learned = true; + disciplines_learned++; + break; } } } } - if (discipline_learned) + if (disciplines_learned > 0) { + std::string discipline_message = (disciplines_learned == 1 ? "a new discipline" : fmt::format("{} new disciplines", disciplines_learned)); initiator->SendDisciplineUpdate(); + initiator->Message(Chat::White, fmt::format("You have learned {}!", discipline_message).c_str()); + } - return discipline_count; + return disciplines_learned; } void QuestManager::unscribespells() {