fix(Scripts/Commands): Fixed command learn all my talents for chars… (#13529)

fix(Scripts/Commands): Fixed command `learn all my talents` for chars with 255 level.

Fixes #4788
This commit is contained in:
UltraNix
2022-10-29 12:12:35 +02:00
committed by GitHub
parent bcd9ad5066
commit 41d3df9fcb
3 changed files with 49 additions and 27 deletions

View File

@@ -13621,16 +13621,23 @@ void Player::CompletedAchievement(AchievementEntry const* entry)
m_achievementMgr->CompletedAchievement(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(); uint32 CurTalentPoints = GetFreeTalentPoints();
// xinef: check basic data if (!command)
if (CurTalentPoints == 0) {
return; // xinef: check basic data
if (!CurTalentPoints)
{
return;
}
if (talentRank >= MAX_TALENT_RANK) if (talentRank >= MAX_TALENT_RANK)
return; {
return;
}
}
TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId); TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId);
if (!talentInfo) if (!talentInfo)
@@ -13659,10 +13666,15 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank)
if (currentTalentRank >= talentRank + 1) if (currentTalentRank >= talentRank + 1)
return; return;
// xinef: check if we have enough free talent points
uint32 talentPointsChange = (talentRank - currentTalentRank + 1); uint32 talentPointsChange = (talentRank - currentTalentRank + 1);
if (CurTalentPoints < talentPointsChange) if (!command)
return; {
// xinef: check if we have enough free talent points
if (CurTalentPoints < talentPointsChange)
{
return;
}
}
// xinef: check if talent deponds on another talent // xinef: check if talent deponds on another talent
if (talentInfo->DependsOn > 0) if (talentInfo->DependsOn > 0)
@@ -13684,23 +13696,26 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank)
return; return;
} }
// xinef: check amount of points spent in current talent tree if (!command)
// xinef: be smart and quick
uint32 spentPoints = 0;
if (talentInfo->Row > 0)
{ {
const PlayerTalentMap& talentMap = GetTalentMap(); // xinef: check amount of points spent in current talent tree
for (PlayerTalentMap::const_iterator itr = talentMap.begin(); itr != talentMap.end(); ++itr) // xinef: be smart and quick
if (TalentSpellPos const* talentPos = GetTalentSpellPos(itr->first)) uint32 spentPoints = 0;
if (TalentEntry const* itrTalentInfo = sTalentStore.LookupEntry(talentPos->talent_id)) if (talentInfo->Row > 0)
if (itrTalentInfo->TalentTab == talentInfo->TalentTab) {
if (itr->second->State != PLAYERSPELL_REMOVED && itr->second->IsInSpec(GetActiveSpec())) // pussywizard const PlayerTalentMap& talentMap = GetTalentMap();
spentPoints += talentPos->rank + 1; 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 // xinef: we do not have enough talent points to add talent of this tier
if (spentPoints < (talentInfo->Row * MAX_TALENT_RANK)) if (spentPoints < (talentInfo->Row * MAX_TALENT_RANK))
return; return;
}
// xinef: hacking attempt, tries to learn unknown rank // xinef: hacking attempt, tries to learn unknown rank
uint32 spellId = talentInfo->RankID[talentRank]; uint32 spellId = talentInfo->RankID[talentRank];
@@ -13733,7 +13748,11 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank)
// xinef: update free talent points count // xinef: update free talent points count
m_usedTalentCount += talentPointsChange; m_usedTalentCount += talentPointsChange;
SetFreeTalentPoints(CurTalentPoints - talentPointsChange);
if (!command)
{
SetFreeTalentPoints(CurTalentPoints - talentPointsChange);
}
sScriptMgr->OnPlayerLearnTalents(this, talentId, talentRank, spellId); sScriptMgr->OnPlayerLearnTalents(this, talentId, talentRank, spellId);
} }

View File

@@ -1677,7 +1677,7 @@ public:
void BuildPlayerTalentsInfoData(WorldPacket* data); void BuildPlayerTalentsInfoData(WorldPacket* data);
void BuildPetTalentsInfoData(WorldPacket* data); void BuildPetTalentsInfoData(WorldPacket* data);
void SendTalentsInfoData(bool pet); 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); void LearnPetTalent(ObjectGuid petGuid, uint32 talentId, uint32 talentRank);
bool addTalent(uint32 spellId, uint8 addSpecMask, uint8 oldTalentRank); bool addTalent(uint32 spellId, uint8 addSpecMask, uint8 oldTalentRank);

View File

@@ -195,9 +195,12 @@ public:
if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo)) if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
continue; 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); handler->SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
return true; return true;
} }