TrinityCore
Loading...
Searching...
No Matches
SkillHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "Common.h"
20#include "DBCStores.h"
21#include "Log.h"
22#include "ObjectAccessor.h"
23#include "Pet.h"
24#include "Player.h"
25#include "TalentPackets.h"
26#include "WorldPacket.h"
27
29{
30 uint32 talentId, requestedRank;
31 recvData >> talentId >> requestedRank;
32
33 if (_player->LearnTalent(talentId, requestedRank))
35}
36
38{
39 TC_LOG_DEBUG("network", "CMSG_LEARN_PREVIEW_TALENTS");
40
41 uint32 talentsCount;
42 recvPacket >> talentsCount;
43
44 uint32 talentId, talentRank;
45
46 // Client has max 44 talents for tree for 3 trees, rounded up : 150
47 uint32 const MaxTalentsCount = 150;
48
49 for (uint32 i = 0; i < talentsCount && i < MaxTalentsCount; ++i)
50 {
51 recvPacket >> talentId >> talentRank;
52
53 if (!_player->LearnTalent(talentId, talentRank))
54 {
55 recvPacket.rfinish();
56 break;
57 }
58 }
59
61
62 recvPacket.rfinish();
63}
64
66{
67 TC_LOG_DEBUG("network", "MSG_TALENT_WIPE_CONFIRM");
68
70 if (!trainer)
71 {
72 TC_LOG_DEBUG("network", "WORLD: HandleTalentWipeConfirmOpcode - {} not found or you can't interact with him.", confirmRespecWipe.RespecMaster);
73 return;
74 }
75
76 if (!trainer->CanResetTalents(_player, false))
77 return;
78
80 if (!_player->HasEnoughMoney(cost))
81 return; // // silently return, client should display the error by itself
82
83 // remove fake death
84 if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
86
87 if (!_player->ResetTalents())
88 {
90 return;
91 }
92
93 _player->ModifyMoney(-(int32)cost);
96
97 trainer->CastSpell(_player, 14867 /*SPELL_UNTALENT_VISUAL_EFFECT*/, true);
98}
99
101{
102 uint32 skillId;
103 recvData >> skillId;
104
105 SkillRaceClassInfoEntry const* rcEntry = GetSkillRaceClassInfo(skillId, GetPlayer()->GetRace(), GetPlayer()->GetClass());
106 if (!rcEntry || !(rcEntry->Flags & SKILL_FLAG_UNLEARNABLE))
107 return;
108
109 GetPlayer()->SetSkill(skillId, 0, 0, 0);
110}
@ SKILL_FLAG_UNLEARNABLE
Definition DBCEnums.h:376
SkillRaceClassInfoEntry const * GetSkillRaceClassInfo(uint32 skill, uint8 race, uint8 class_)
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
#define TC_LOG_DEBUG(filterType__,...)
Definition Log.h:156
@ SPELL_AURA_FEIGN_DEATH
@ UNIT_NPC_FLAG_TRAINER
@ UNIT_STATE_DIED
Definition Unit.h:220
void rfinish()
Definition ByteBuffer.h:316
bool CanResetTalents(Player *player, bool pet) const
static ObjectGuid const Empty
Definition ObjectGuid.h:140
void SendTalentsInfoData(bool pet)
Definition Player.cpp:25366
bool LearnTalent(uint32 talentId, uint32 talentRank)
Definition Player.cpp:24950
void SendTalentWipeConfirm(ObjectGuid trainerGuid) const
Definition Player.cpp:9158
bool ModifyMoney(int32 amount, bool sendError=true)
Definition Player.cpp:22339
void SetSkill(uint32 id, uint16 step, uint16 newVal, uint16 maxVal)
Definition Player.cpp:5759
bool HasEnoughMoney(uint32 amount) const
Definition Player.h:1410
uint32 ResetTalentsCost() const
Definition Player.cpp:3660
Creature * GetNPCIfCanInteractWith(ObjectGuid const &guid, NPCFlags npcFlags) const
Definition Player.cpp:2094
bool ResetTalents(bool involuntarily=false)
Definition Player.cpp:3707
void IncreaseResetTalentsCostAndCounters(uint32 lastResetTalentsCost)
Definition Player.cpp:3696
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3765
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2832
Player * GetPlayer() const
void HandleLearnPreviewTalents(WorldPacket &recvPacket)
Player * _player
void HandleTalentWipeConfirmOpcode(WorldPackets::Talent::ConfirmRespecWipe &confirmRespecWipe)
void HandleUnlearnSkillOpcode(WorldPacket &recvPacket)
void HandleLearnTalentOpcode(WorldPacket &recvPacket)