diff options
author | Ovahlord <dreadkiller@gmx.de> | 2023-11-19 18:35:06 +0100 |
---|---|---|
committer | Ovahlord <dreadkiller@gmx.de> | 2023-11-19 18:35:06 +0100 |
commit | a75160131e6b5d8350bd08f12a1ac1b9f5d37e39 (patch) | |
tree | e3af90f83e04a347d5f676a3489bf0e72d3b65e5 | |
parent | 8aa917a3e45b006c16cbe58cf6323d400417a687 (diff) |
Core/Player: implemented a helper to reliably count spent talent points
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 25 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.h | 1 |
2 files changed, 14 insertions, 12 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 3e41f2aa05d..6c0185fb47d 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2414,20 +2414,17 @@ bool Player::IsMaxLevel() const void Player::InitTalentForLevel() { uint8 level = GetLevel(); + int32 talentPoints = CalculateTalentsPoints(); if (level < MIN_SPECIALIZATION_LEVEL) { // Remove all talent points ResetTalents(true); } - else - { - int32 talentTiers = DB2Manager::GetNumTalentsAtLevel(level, Classes(GetClass())); - if (!GetSession()->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_MORE_TALENTS_THAN_ALLOWED)) - for (int32 t = talentTiers; t < MAX_TALENT_TIERS; ++t) - for (uint32 c = 0; c < MAX_TALENT_COLUMNS; ++c) - for (TalentEntry const* talent : sDB2Manager.GetTalentsByPosition(GetClass(), t, c)) - RemoveTalent(talent); - } + else if (!GetSession()->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_MORE_TALENTS_THAN_ALLOWED)) + if (GetSpentTalentPointsCount() > talentPoints) + ResetTalents(true); + + SetUpdateFieldValue(m_values.ModifyValue(&Player::m_activePlayerData).ModifyValue(&UF::ActivePlayerData::MaxTalentTiers), talentPoints); if (!GetSession()->PlayerLoading()) SendTalentsInfoData(); // update at client @@ -26370,6 +26367,7 @@ void Player::SendTalentsInfoData() uint8 activeGroup = GetActiveTalentGroup(); packet.ActiveGroup = activeGroup; + packet.UnspentTalentPoints = CalculateTalentsPoints() - GetSpentTalentPointsCount(); for (uint8 i = 0; i < (1 + GetBonusTalentGroupCount()); ++i) { @@ -26404,9 +26402,6 @@ void Player::SendTalentsInfoData() } } - if (i == activeGroup) - packet.UnspentTalentPoints = std::max<int32>(0, CalculateTalentsPoints() - groupInfo.Talents.size()); - std::vector<uint32> glyphs = GetGlyphs(activeGroup); glyphs.resize(MAX_GLYPH_SLOT_INDEX, 0); // Blizzard always sends 6 glyph slots, no matter if they are used or not groupInfo.GlyphIDs.reserve(MAX_GLYPH_SLOT_INDEX); @@ -28737,6 +28732,12 @@ void Player::SetBonusTalentGroupCount(uint8 amount) SendTalentsInfoData(); } +uint32 Player::GetSpentTalentPointsCount() const +{ + PlayerTalentMap const& talentMap = _specializationInfo.Talents[GetActiveTalentGroup()]; + return std::count_if(talentMap.begin(), talentMap.end(), [](auto const& pair) { return (pair.second != PLAYERSPELL_REMOVED); }); +} + ChrSpecializationEntry const* Player::GetPrimarySpecializationEntry() const { return sChrSpecializationStore.LookupEntry(AsUnderlyingType(GetPrimarySpecialization())); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 0a6dc73fda6..55e67283755 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1824,6 +1824,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player> void SetActiveTalentGroup(uint8 group) { _specializationInfo.ActiveGroup = group; } uint8 GetBonusTalentGroupCount() const { return _specializationInfo.BonusGroups; } void SetBonusTalentGroupCount(uint8 amount); + uint32 GetSpentTalentPointsCount() const; uint32 GetDefaultSpecId() const; ChrSpecializationEntry const* GetPrimarySpecializationEntry() const; |