From 41d3df9fcbc862f9bb4cda89e213e75255fe98b6 Mon Sep 17 00:00:00 2001 From: UltraNix <80540499+UltraNix@users.noreply.github.com> Date: Sat, 29 Oct 2022 12:12:35 +0200 Subject: [PATCH] =?UTF-8?q?fix(Scripts/Commands):=20Fixed=20command=20`lea?= =?UTF-8?q?rn=20all=20my=20talents`=20for=20chars=E2=80=A6=20(#13529)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix(Scripts/Commands): Fixed command `learn all my talents` for chars with 255 level. Fixes #4788 --- src/server/game/Entities/Player/Player.cpp | 69 ++++++++++++++-------- src/server/game/Entities/Player/Player.h | 2 +- src/server/scripts/Commands/cs_learn.cpp | 5 +- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index ed896dcff..78de55590 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -13621,16 +13621,23 @@ void Player::CompletedAchievement(AchievementEntry const* entry) m_achievementMgr->CompletedAchievement(entry); } -void Player::LearnTalent(uint32 talentId, uint32 talentRank) +void Player::LearnTalent(uint32 talentId, uint32 talentRank, bool command /*= false*/) { uint32 CurTalentPoints = GetFreeTalentPoints(); - // xinef: check basic data - if (CurTalentPoints == 0) - return; + if (!command) + { + // xinef: check basic data + if (!CurTalentPoints) + { + return; + } - if (talentRank >= MAX_TALENT_RANK) - return; + if (talentRank >= MAX_TALENT_RANK) + { + return; + } + } TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId); if (!talentInfo) @@ -13659,10 +13666,15 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) if (currentTalentRank >= talentRank + 1) return; - // xinef: check if we have enough free talent points uint32 talentPointsChange = (talentRank - currentTalentRank + 1); - if (CurTalentPoints < talentPointsChange) - return; + if (!command) + { + // xinef: check if we have enough free talent points + if (CurTalentPoints < talentPointsChange) + { + return; + } + } // xinef: check if talent deponds on another talent if (talentInfo->DependsOn > 0) @@ -13684,23 +13696,26 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) return; } - // xinef: check amount of points spent in current talent tree - // xinef: be smart and quick - uint32 spentPoints = 0; - if (talentInfo->Row > 0) + if (!command) { - const PlayerTalentMap& talentMap = GetTalentMap(); - for (PlayerTalentMap::const_iterator itr = talentMap.begin(); itr != talentMap.end(); ++itr) - if (TalentSpellPos const* talentPos = GetTalentSpellPos(itr->first)) - if (TalentEntry const* itrTalentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) - if (itrTalentInfo->TalentTab == talentInfo->TalentTab) - if (itr->second->State != PLAYERSPELL_REMOVED && itr->second->IsInSpec(GetActiveSpec())) // pussywizard - spentPoints += talentPos->rank + 1; - } + // xinef: check amount of points spent in current talent tree + // xinef: be smart and quick + uint32 spentPoints = 0; + if (talentInfo->Row > 0) + { + const PlayerTalentMap& talentMap = GetTalentMap(); + for (PlayerTalentMap::const_iterator itr = talentMap.begin(); itr != talentMap.end(); ++itr) + if (TalentSpellPos const* talentPos = GetTalentSpellPos(itr->first)) + if (TalentEntry const* itrTalentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) + if (itrTalentInfo->TalentTab == talentInfo->TalentTab) + if (itr->second->State != PLAYERSPELL_REMOVED && itr->second->IsInSpec(GetActiveSpec())) // pussywizard + spentPoints += talentPos->rank + 1; + } - // xinef: we do not have enough talent points to add talent of this tier - if (spentPoints < (talentInfo->Row * MAX_TALENT_RANK)) - return; + // xinef: we do not have enough talent points to add talent of this tier + if (spentPoints < (talentInfo->Row * MAX_TALENT_RANK)) + return; + } // xinef: hacking attempt, tries to learn unknown rank uint32 spellId = talentInfo->RankID[talentRank]; @@ -13733,7 +13748,11 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) // xinef: update free talent points count m_usedTalentCount += talentPointsChange; - SetFreeTalentPoints(CurTalentPoints - talentPointsChange); + + if (!command) + { + SetFreeTalentPoints(CurTalentPoints - talentPointsChange); + } sScriptMgr->OnPlayerLearnTalents(this, talentId, talentRank, spellId); } diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index b31139f5c..480ff536d 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1677,7 +1677,7 @@ public: void BuildPlayerTalentsInfoData(WorldPacket* data); void BuildPetTalentsInfoData(WorldPacket* data); void SendTalentsInfoData(bool pet); - void LearnTalent(uint32 talentId, uint32 talentRank); + void LearnTalent(uint32 talentId, uint32 talentRank, bool command = false); void LearnPetTalent(ObjectGuid petGuid, uint32 talentId, uint32 talentRank); bool addTalent(uint32 spellId, uint8 addSpecMask, uint8 oldTalentRank); diff --git a/src/server/scripts/Commands/cs_learn.cpp b/src/server/scripts/Commands/cs_learn.cpp index 6ea772dd4..c997afab6 100644 --- a/src/server/scripts/Commands/cs_learn.cpp +++ b/src/server/scripts/Commands/cs_learn.cpp @@ -195,9 +195,12 @@ public: if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo)) continue; - player->LearnTalent(talentInfo->TalentID, rankId); + player->LearnTalent(talentInfo->TalentID, rankId, true); } + player->SetFreeTalentPoints(0); + player->SendTalentsInfoData(false); + handler->SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS); return true; }