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 "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);
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
96 if (!_player->HasEnoughMoney(cost))
97 return; // // silently return, client should display the error by itself
98
99 // remove fake death
100 if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
102
103 if (!_player->ResetTalents())
104 {
105 _player->SendRespecWipeConfirm(ObjectGuid::Empty, 0, static_cast<SpecResetType>(confirmRespecWipe.RespecType));
106 return;
107 }
108
109 _player->ModifyMoney(-cost);
112
113 unit->CastSpell(_player, 14867 /*SPELL_UNTALENT_VISUAL_EFFECT*/, true);
114}
115
117{
118 SkillRaceClassInfoEntry const* rcEntry = sDB2Manager.GetSkillRaceClassInfo(packet.SkillLine, GetPlayer()->GetRace(), GetPlayer()->GetClass());
119 if (!rcEntry || !(rcEntry->Flags & SKILL_FLAG_UNLEARNABLE))
120 return;
121
122 GetPlayer()->SetSkill(packet.SkillLine, 0, 0, 0);
123}
124
126{
127 if (!_player->HasSpell(tradeSkillSetFavorite.RecipeID))
128 return;
129
130 _player->SetSpellFavorite(tradeSkillSetFavorite.RecipeID, tradeSkillSetFavorite.IsFavorite);
131}
#define sDB2Manager
Definition DB2Stores.h:579
@ SKILL_FLAG_UNLEARNABLE
Definition DBCEnums.h:2400
int64_t int64
Definition Define.h:149
uint32_t uint32
Definition Define.h:154
#define TC_LOG_DEBUG(filterType__, message__,...)
Definition Log.h:173
SpecResetType
Definition Player.h:243
@ SPEC_RESET_TALENTS
Definition Player.h:244
TalentLearnResult
Definition Player.h:1158
@ SPELL_AURA_FEIGN_DEATH
@ UNIT_NPC_FLAG_TRAINER
@ UNIT_NPC_FLAG_2_NONE
@ UNIT_STATE_DIED
Definition Unit.h:275
bool CanResetTalents(Player *player) const
static ObjectGuid const Empty
Definition ObjectGuid.h:314
uint32 GetNextResetTalentsCost() const
Definition Player.cpp:3380
bool ModifyMoney(int64 amount, bool sendError=true)
Definition Player.cpp:24800
Creature * GetNPCIfCanInteractWith(ObjectGuid const &guid, NPCFlags npcFlags, NPCFlags2 npcFlags2) const
Definition Player.cpp:1814
void SendTalentsInfoData()
Definition Player.cpp:28051
TalentLearnResult LearnTalent(uint32 talentId, int32 *spellOnCooldown)
Definition Player.cpp:27559
void SetSkill(uint32 id, uint16 step, uint16 newVal, uint16 maxVal)
Definition Player.cpp:5654
void SetSpellFavorite(uint32 spellId, bool favorite)
Definition Player.cpp:3349
void SendRespecWipeConfirm(ObjectGuid const &guid, uint32 cost, SpecResetType respecType) const
Definition Player.cpp:9164
TalentLearnResult LearnPvpTalent(uint32 talentID, uint8 slot, int32 *spellOnCooldown)
Definition Player.cpp:27673
void IncreaseResetTalentsCostAndCounters(uint32 lastResetTalentsCost)
Definition Player.cpp:3416
bool HasSpell(uint32 spell) const override
Definition Player.cpp:3626
bool ResetTalents(bool noCost=false)
Definition Player.cpp:3427
bool HasEnoughMoney(uint64 amount) const
Definition Player.h:1892
void RemoveAurasByType(AuraType auraType, std::function< bool(AuraApplication const *)> const &check, AuraRemoveMode removeMode=AURA_REMOVE_BY_DEFAULT)
Definition Unit.cpp:3973
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition Object.cpp:2222
WorldPacket const * Write() override
WorldPacket const * Write() override
Array< uint16, MAX_TALENT_TIERS > Talents
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)