Core/Player: allow players to learn a primary specialization without having to select a talent

* converted CMSG_LEARN_PREVIEW_TALENTS to packet class
This commit is contained in:
Ovahlord committed 2025-06-16 20:32:28 +02:00
1 parent 53df12ae73
commit c092c6ad00
7 files changed
+147 -59

No files matched your search

+39 -25
View File
@@ -25474,21 +25474,18 @@ void Player::CompletedAchievement(AchievementEntry const* entry)
bool Player::LearnTalent(uint32 talentId, uint32 talentRank)
{
uint32 CurTalentPoints = GetFreeTalentPoints();
if (CurTalentPoints == 0)
if (talentId == 0 || talentRank >= MAX_TALENT_RANK)
return false;
if (talentRank >= MAX_TALENT_RANK)
uint32 freeTalentPoints = GetFreeTalentPoints();
if (freeTalentPoints == 0)
return false;
TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
if (!talentInfo)
return false;
TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TabID);
if (!talentTabInfo)
return false;
@@ -25512,7 +25509,7 @@ bool Player::LearnTalent(uint32 talentId, uint32 talentRank)
return false;
// check if we have enough talent points
if (CurTalentPoints < (talentRank - curtalent_maxrank + 1))
if (freeTalentPoints < (talentRank - curtalent_maxrank + 1))
return false;
// Check if it requires another talent
@@ -25587,24 +25584,8 @@ bool Player::LearnTalent(uint32 talentId, uint32 talentRank)
TC_LOG_DEBUG("entities.player", "TalentID: %u Rank: %u Spell: %u Spec: %u\n", talentId, talentRank, spellid, GetActiveSpec());
// set talent tree for player
if (!GetPrimaryTalentTree(GetActiveSpec()))
{
SetPrimaryTalentTree(GetActiveSpec(), talentInfo->TabID);
std::vector<uint32> const* specSpells = sDBCManager.GetTalentTreePrimarySpells(talentInfo->TabID);
if (specSpells)
for (size_t i = 0; i < specSpells->size(); ++i)
LearnSpell(specSpells->at(i), false);
if (CanUseMastery())
for (uint32 i = 0; i < MAX_MASTERY_SPELLS; ++i)
if (SpellInfo const* masterySpell = sSpellMgr->GetSpellInfo(talentTabInfo->MasterySpellID[i]))
if (masterySpell->IsPassive() && HandlePassiveSpellLearn(masterySpell))
CastSpell(this, masterySpell->Id, true);
}
// update free talent points
SetFreeTalentPoints(CurTalentPoints - (talentRank - curtalent_maxrank + 1));
SetFreeTalentPoints(freeTalentPoints - (talentRank - curtalent_maxrank + 1));
return true;
}
@@ -25743,6 +25724,38 @@ void Player::LearnPetTalent(ObjectGuid petGuid, uint32 talentId, uint32 talentRa
pet->SetFreeTalentPoints(CurTalentPoints - (talentRank - curtalent_maxrank + 1));
}
bool Player::LearnPrimaryTalentSpecialization(uint8 talentTabIndex)
{
if (talentTabIndex >= MAX_TALENT_TABS)
return false;
if (GetPrimaryTalentTree(GetActiveSpec()) != 0)
return false;
uint32 const* talentTabs = sDBCManager.GetTalentTabPages(getClass());
if (!talentTabs)
return false;
TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentTabs[talentTabIndex]);
if (!talentTabInfo)
return false;
SetPrimaryTalentTree(GetActiveSpec(), talentTabInfo->ID);
// Learn specialization spells and mastery
if (std::vector<uint32> const* specSpells = sDBCManager.GetTalentTreePrimarySpells(talentTabInfo->ID))
for (uint32 spellId : *specSpells)
LearnSpell(spellId, false);
if (CanUseMastery())
for (uint8 i = 0; i < MAX_MASTERY_SPELLS; ++i)
if (SpellInfo const* masterySpell = sSpellMgr->GetSpellInfo(talentTabInfo->MasterySpellID[i]))
if (masterySpell->IsPassive() && HandlePassiveSpellLearn(masterySpell))
CastSpell(this, masterySpell->Id, true);
return true;
}
void Player::AddKnownCurrency(uint32 itemId)
{
if (CurrencyTypesEntry const* ctEntry = sCurrencyTypesStore.LookupEntry(itemId))
@@ -27793,7 +27806,8 @@ uint32 Player::GetPrimaryTalentTree(uint8 spec) const
void Player::SetPrimaryTalentTree(uint8 spec, uint32 tree)
{
_talentMgr->SpecInfo[spec].TalentTree = tree; UpdateArmorSpecialization();
_talentMgr->SpecInfo[spec].TalentTree = tree;
UpdateArmorSpecialization();
}
uint8 Player::GetActiveSpec() const
+1
View File
@@ -1583,6 +1583,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void SendTalentsInfoData(bool pet);
bool LearnTalent(uint32 talentId, uint32 talentRank);
void LearnPetTalent(ObjectGuid petGuid, uint32 talentId, uint32 talentRank);
bool LearnPrimaryTalentSpecialization(uint8 talentTabIndex);
bool AddTalent(uint32 spellId, uint8 spec, bool learning);
bool HasTalent(uint32 spell_id, uint8 spec) const;
uint32 CalculateTalentsPoints() const;