Core/Spell: allow Northrend Inscription Research to unlock three recipes the first time it is cast. (#23401)

Also prevent double skill-up because of duplicate UpdateCraftSkill() calls.

(cherry picked from commit 2315d43b2c)
This commit is contained in:
Wyrserth
2019-06-15 14:13:19 +02:00
committed by Shauren
parent 3ba08283ba
commit 6b7bc82641
3 changed files with 29 additions and 4 deletions

View File

@@ -207,6 +207,19 @@ bool HasDiscoveredAllSpells(uint32 spellId, Player* player)
return true;
}
bool HasDiscoveredAnySpell(uint32 spellId, Player* player)
{
SkillDiscoveryMap::const_iterator tab = SkillDiscoveryStore.find(int32(spellId));
if (tab == SkillDiscoveryStore.end())
return false;
for (SkillDiscoveryList::const_iterator item_iter = tab->second.begin(); item_iter != tab->second.end(); ++item_iter)
if (player->HasSpell(item_iter->spellId))
return true;
return false;
}
uint32 GetSkillDiscoverySpell(uint32 skillId, uint32 spellId, Player* player)
{
uint32 skillvalue = skillId ? player->GetSkillValue(skillId) : uint32(0);

View File

@@ -25,6 +25,7 @@ class Player;
TC_GAME_API void LoadSkillDiscoveryTable();
TC_GAME_API uint32 GetSkillDiscoverySpell(uint32 skillId, uint32 spellId, Player* player);
TC_GAME_API bool HasDiscoveredAllSpells(uint32 spellId, Player* player);
TC_GAME_API bool HasDiscoveredAnySpell(uint32 spellId, Player* player);
TC_GAME_API uint32 GetExplicitDiscoverySpell(uint32 spellId, Player* player);
#endif

View File

@@ -2564,6 +2564,11 @@ class spell_gen_pet_summoned : public SpellScript
}
};
enum ProfessionResearch
{
SPELL_NORTHREND_INSCRIPTION_RESEARCH = 61177
};
class spell_gen_profession_research : public SpellScript
{
PrepareSpellScript(spell_gen_profession_research);
@@ -2575,7 +2580,9 @@ class spell_gen_profession_research : public SpellScript
SpellCastResult CheckRequirement()
{
if (HasDiscoveredAllSpells(GetSpellInfo()->Id, GetCaster()->ToPlayer()))
Player* player = GetCaster()->ToPlayer();
if (HasDiscoveredAllSpells(GetSpellInfo()->Id, player))
{
SetCustomCastResultMessage(SPELL_CUSTOM_ERROR_NOTHING_TO_DISCOVER);
return SPELL_FAILED_CUSTOM_ERROR;
@@ -2589,11 +2596,15 @@ class spell_gen_profession_research : public SpellScript
Player* caster = GetCaster()->ToPlayer();
uint32 spellId = GetSpellInfo()->Id;
// learn random explicit discovery recipe (if any)
// Learn random explicit discovery recipe (if any)
// Players will now learn 3 recipes the very first time they perform Northrend Inscription Research (3.3.0 patch notes)
if (spellId == SPELL_NORTHREND_INSCRIPTION_RESEARCH && !HasDiscoveredAnySpell(spellId, caster))
for (int i = 0; i < 2; ++i)
if (uint32 discoveredSpellId = GetExplicitDiscoverySpell(spellId, caster))
caster->LearnSpell(discoveredSpellId, false);
if (uint32 discoveredSpellId = GetExplicitDiscoverySpell(spellId, caster))
caster->LearnSpell(discoveredSpellId, false);
caster->UpdateCraftSkill(spellId);
}
void Register() override