aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOvahlord <dreadkiller@gmx.de>2024-07-28 02:04:58 +0200
committerOvahlord <dreadkiller@gmx.de>2024-07-28 02:04:58 +0200
commitba3ef410c8846b586b41d802202b473c05cc5dff (patch)
tree82e21b98670c508782af00023af4cba8c14c8f57
parentd8a9f7bd255f84db46edd5108ef62b1024119869 (diff)
Core/Players: fixed selecting primary talent trees, loading talent spells after relogging and improve validation of talents when loading from db
-rw-r--r--src/server/game/Entities/Player/Player.cpp23
-rw-r--r--src/server/game/Entities/Player/Player.h2
-rw-r--r--src/server/game/Handlers/SkillHandler.cpp4
3 files changed, 21 insertions, 8 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 781934a88ed..3ea08d0787e 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -17367,7 +17367,7 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder const& hol
UpdateDisplayPower();
_LoadTalents(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_TALENT_GROUPS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_TALENTS));
_LoadGlyphs(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_GLYPHS));
- SetActiveTalentGroup(HasTalentGroupUnlocked(fields.activeTalentGroup) ? fields.activeTalentGroup : 0, false);
+ SetActiveTalentGroup(HasTalentGroupUnlocked(fields.activeTalentGroup) ? fields.activeTalentGroup : 0, false, true);
_LoadSpells(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SPELLS), holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_SPELL_FAVORITES));
GetSession()->GetCollectionMgr()->LoadToys();
@@ -26447,7 +26447,9 @@ void Player::_LoadTalents(PreparedQueryResult talentGroupResult, PreparedQueryRe
TalentGroupInfo& talentGroup = _talentGroups.emplace_back();
uint32 talentTabId = fields[1].GetUInt32();
- if (sTalentTabStore.HasRecord(talentTabId))
+
+ TalentTabEntry const* talentTab = sTalentTabStore.LookupEntry(talentTabId);
+ if (talentTab && (talentTab->RaceMask & GetRaceMask()))
talentGroup.PrimaryTalentTabID = talentTabId;
} while (talentGroupResult->NextRow());
@@ -26469,11 +26471,18 @@ void Player::_LoadTalents(PreparedQueryResult talentGroupResult, PreparedQueryRe
uint32 talentId = fields[1].GetUInt32();
uint8 talentRank = fields[2].GetUInt8();
TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
- if (!talentInfo || talentInfo->SpellRank.size() <= talentRank || !sSpellMgr->GetSpellInfo(talentInfo->SpellRank[talentRank], DIFFICULTY_NONE))
+ if (!talentInfo)
+ continue;
+
+ if (talentRank >= talentInfo->SpellRank.size())
+ continue;
+
+ uint32 spellId = talentInfo->SpellRank[talentRank];
+ SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE);
+ if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, this, false))
continue;
_talentGroups[talentGroupId].Talents.try_emplace(talentId, talentRank);
- LearnSpell(talentInfo->SpellRank[talentRank], true);
} while (talentResult->NextRow());
}
@@ -28387,11 +28396,12 @@ void Player::SetTalentGroupCount(uint8 count)
SendTalentsInfoData();
}
-void Player::SetActiveTalentGroup(uint8 group, bool withUpdate /*= true*/)
+void Player::SetActiveTalentGroup(uint8 group, bool withUpdate /*= true*/, bool loading /*= false*/)
{
uint32 oldTalentTabId = _talentGroups[_activeTalentGroup].PrimaryTalentTabID;
uint32 newTalentTabId = _talentGroups[group].PrimaryTalentTabID;
+ if (!loading)
{
// Perform cleanup actions on switching talent groups
@@ -28467,6 +28477,9 @@ void Player::SetActiveTalentGroup(uint8 group, bool withUpdate /*= true*/)
// Perform post switch actions - resetting powers, loading action bars, updating shapeshifting auras
SetPrimaryTalentTree(newTalentTabId);
+ for (auto const& talentPair : _talentGroups[_activeTalentGroup].Talents)
+ LearnSpell(sTalentStore.AssertEntry(talentPair.first)->SpellRank[talentPair.second], true);
+
uint8 glyphSlot = 0;
for (uint16 glyphId : _talentGroups[_activeTalentGroup].Glyphs)
{
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 1569b2f00f8..deacd1e8c5f 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1857,7 +1857,7 @@ class TC_GAME_API Player final : public Unit, public GridObject<Player>
uint8 GetActiveTalentGroup() const { return _activeTalentGroup; }
bool HasTalentGroupUnlocked(uint8 group) const;
void SetTalentGroupCount(uint8 count);
- void SetActiveTalentGroup(uint8 group, bool withUpdate = true);
+ void SetActiveTalentGroup(uint8 group, bool withUpdate = true, bool loading = false);
void SetPrimaryTalentTree(uint32 talentTabId, bool withUpdate = false);
uint32 GetPrimaryTalentTree() const;
bool LearnTalent(uint32 talentId, uint8 rank);
diff --git a/src/server/game/Handlers/SkillHandler.cpp b/src/server/game/Handlers/SkillHandler.cpp
index 758bab9f1fd..bc1def97c6f 100644
--- a/src/server/game/Handlers/SkillHandler.cpp
+++ b/src/server/game/Handlers/SkillHandler.cpp
@@ -35,7 +35,7 @@ void WorldSession::HandleLearnTalentOpcode(WorldPackets::Talent::LearnTalent& pa
void WorldSession::HandleLearnPreviewTalentsOpcode(WorldPackets::Talent::LearnPreviewTalents& packet)
{
if (!_player->GetPrimaryTalentTree() && packet.TabIndex >= 0)
- if (TalentTabEntry const* talentTab = sDB2Manager.GetTalentTabByIndex(_player->GetClassMask(), packet.TabIndex))
+ if (TalentTabEntry const* talentTab = sDB2Manager.GetTalentTabByIndex(_player->GetClass(), packet.TabIndex))
_player->SetPrimaryTalentTree(talentTab->ID, true);
for (auto const& talentInfo : packet.Talents)
@@ -50,7 +50,7 @@ void WorldSession::HandleSetPrimaryTalentTreeOpcode(WorldPackets::Talent::SetPri
if (_player->GetPrimaryTalentTree() != 0 || packet.TabIndex < 0)
return;
- if (TalentTabEntry const* talentTab = sDB2Manager.GetTalentTabByIndex(_player->GetClassMask(), packet.TabIndex))
+ if (TalentTabEntry const* talentTab = sDB2Manager.GetTalentTabByIndex(_player->GetClass(), packet.TabIndex))
_player->SetPrimaryTalentTree(talentTab->ID, true);
}