port over some changes from Trinity version including one possible memory leak fix
[AHbot.git] / src / game / SkillHandler.cpp
blob81c0a12178ae9ba9819e5b845b1f1b48bf590495
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "Opcodes.h"
22 #include "Log.h"
23 #include "Player.h"
24 #include "WorldPacket.h"
25 #include "WorldSession.h"
26 #include "ObjectAccessor.h"
27 #include "UpdateMask.h"
29 void WorldSession::HandleLearnTalentOpcode( WorldPacket & recv_data )
31 CHECK_PACKET_SIZE(recv_data,4+4);
33 uint32 talent_id, requested_rank;
34 recv_data >> talent_id >> requested_rank;
36 _player->LearnTalent(talent_id, requested_rank);
37 _player->SendTalentsInfoData(false);
40 void WorldSession::HandleLearnPreviewTalents(WorldPacket& recvPacket)
42 sLog.outDebug("CMSG_LEARN_PREVIEW_TALENTS");
44 CHECK_PACKET_SIZE(recvPacket, 4);
46 uint32 talentsCount;
47 recvPacket >> talentsCount;
49 uint32 talentId, talentRank;
51 for(uint32 i = 0; i < talentsCount; ++i)
53 CHECK_PACKET_SIZE(recvPacket, recvPacket.rpos()+4+4);
55 recvPacket >> talentId >> talentRank;
57 _player->LearnTalent(talentId, talentRank);
60 _player->SendTalentsInfoData(false);
63 void WorldSession::HandleTalentWipeConfirmOpcode( WorldPacket & recv_data )
65 CHECK_PACKET_SIZE(recv_data,8);
67 sLog.outDetail("MSG_TALENT_WIPE_CONFIRM");
68 uint64 guid;
69 recv_data >> guid;
71 Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_TRAINER);
72 if (!unit)
74 sLog.outDebug( "WORLD: HandleTalentWipeConfirmOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
75 return;
78 // remove fake death
79 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
80 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
82 if(!(_player->resetTalents()))
84 WorldPacket data( MSG_TALENT_WIPE_CONFIRM, 8+4); //you have not any talent
85 data << uint64(0);
86 data << uint32(0);
87 SendPacket( &data );
88 return;
91 _player->SendTalentsInfoData(false);
92 unit->CastSpell(_player, 14867, true); //spell: "Untalent Visual Effect"
95 void WorldSession::HandleUnlearnSkillOpcode(WorldPacket & recv_data)
97 CHECK_PACKET_SIZE(recv_data,4);
99 uint32 skill_id;
100 recv_data >> skill_id;
101 GetPlayer()->SetSkill(skill_id, 0, 0);