TrinityCore
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 "DB2Stores.h"
21#include "GossipDef.h"
22#include "Log.h"
23#include "ObjectAccessor.h"
24#include "Pet.h"
25#include "Player.h"
26#include "SpellPackets.h"
27#include "TalentPackets.h"
28
30{
32 bool anythingLearned = false;
33 for (uint32 talentId : packet.Talents)
34 {
35 if (TalentLearnResult result = _player->LearnTalent(talentId, &learnTalentFailed.SpellID))
36 {
37 if (!learnTalentFailed.Reason)
38 learnTalentFailed.Reason = result;
39
40 learnTalentFailed.Talents.push_back(talentId);
41 }
42 else
43 anythingLearned = true;
44 }
45
46 if (learnTalentFailed.Reason)
47 SendPacket(learnTalentFailed.Write());
48
49 if (anythingLearned)
51}
52
54{
56 bool anythingLearned = false;
57 for (WorldPackets::Talent::PvPTalent pvpTalent : packet.Talents)
58 {
59 if (TalentLearnResult result = _player->LearnPvpTalent(pvpTalent.PvPTalentID, pvpTalent.Slot, &learnPvpTalentFailed.SpellID))
60 {
61 if (!learnPvpTalentFailed.Reason)
62 learnPvpTalentFailed.Reason = result;
63
64 learnPvpTalentFailed.Talents.push_back(pvpTalent);
65 }
66 else
67 anythingLearned = true;
68 }
69
70 if (learnPvpTalentFailed.Reason)
71 SendPacket(learnPvpTalentFailed.Write());
72
73 if (anythingLearned)
75}
76
78{
80 if (!unit)
81 {
82 TC_LOG_DEBUG("network", "WORLD: HandleConfirmRespecWipeOpcode - {} not found or you can't interact with him.", confirmRespecWipe.RespecMaster.ToString());
83 return;
84 }
85
86 if (confirmRespecWipe.RespecType != SPEC_RESET_TALENTS)
87 {
88 TC_LOG_DEBUG("network", "WORLD: HandleConfirmRespecWipeOpcode - reset type {} is not implemented.", confirmRespecWipe.RespecType);
89 return;
90 }
91
92 if (!unit->CanResetTalents(_player))
93 return;
94
95 // remove fake death
96 if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
98
99 if (!_player->ResetTalents())
100 return;
101
103 unit->CastSpell(_player, 14867, true); //spell: "Untalent Visual Effect"
104}
105
107{
108 SkillRaceClassInfoEntry const* rcEntry = sDB2Manager.GetSkillRaceClassInfo(packet.SkillLine, GetPlayer()->GetRace(), GetPlayer()->GetClass());
109 if (!rcEntry || !(rcEntry->Flags & SKILL_FLAG_UNLEARNABLE))
110 return;
111
112 GetPlayer()->SetSkill(packet.SkillLine, 0, 0, 0);
113}
114
116{
117 if (!_player->HasSpell(tradeSkillSetFavorite.RecipeID))
118 return;
119
120 _player->SetSpellFavorite(tradeSkillSetFavorite.RecipeID, tradeSkillSetFavorite.IsFavorite);
121}
#define sDB2Manager
Definition: DB2Stores.h:538
@ SKILL_FLAG_UNLEARNABLE
Definition: DBCEnums.h:1911
uint32_t uint32
Definition: Define.h:142
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:156
@ SPEC_RESET_TALENTS
Definition: Player.h:217
TalentLearnResult
Definition: Player.h:1060
@ SPELL_AURA_FEIGN_DEATH
@ UNIT_NPC_FLAG_TRAINER
Definition: UnitDefines.h:301
@ UNIT_NPC_FLAG_2_NONE
Definition: UnitDefines.h:336
@ UNIT_STATE_DIED
Definition: Unit.h:255
bool CanResetTalents(Player *player) const
Definition: Creature.cpp:1320
std::string ToString() const
Definition: ObjectGuid.cpp:554
Creature * GetNPCIfCanInteractWith(ObjectGuid const &guid, NPCFlags npcFlags, NPCFlags2 npcFlags2) const
Definition: Player.cpp:1947
void SendTalentsInfoData()
Definition: Player.cpp:27287
TalentLearnResult LearnTalent(uint32 talentId, int32 *spellOnCooldown)
Definition: Player.cpp:26794
void SetSkill(uint32 id, uint16 step, uint16 newVal, uint16 maxVal)
Definition: Player.cpp:5786
void SetSpellFavorite(uint32 spellId, bool favorite)
Definition: Player.cpp:3468
TalentLearnResult LearnPvpTalent(uint32 talentID, uint8 slot, int32 *spellOnCooldown)
Definition: Player.cpp:26908
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3792
bool ResetTalents(bool noCost=false)
Definition: Player.cpp:3529
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition: Unit.cpp:3812
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2896
WorldPacket const * Write() override
WorldPacket const * Write() override
Array< uint16, MAX_TALENT_TIERS > Talents
Definition: TalentPackets.h:66
void HandleLearnTalentsOpcode(WorldPackets::Talent::LearnTalents &packet)
void HandleConfirmRespecWipeOpcode(WorldPackets::Talent::ConfirmRespecWipe &confirmRespecWipe)
Player * GetPlayer() const
void HandleLearnPvpTalentsOpcode(WorldPackets::Talent::LearnPvpTalents &packet)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void HandleTradeSkillSetFavorite(WorldPackets::Spells::TradeSkillSetFavorite const &tradeSkillSetFavorite)
Player * _player
void HandleUnlearnSkillOpcode(WorldPackets::Spells::UnlearnSkill &packet)