2010-10-07 15:35:36 +02:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
2010-06-08 17:01:03 -06:00
#include "DatabaseEnv.h"
2008-10-02 16:23:55 -05:00
#include "Opcodes.h"
#include "Log.h"
#include "Player.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "ObjectAccessor.h"
#include "UpdateMask.h"
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleLearnTalentOpcode ( WorldPacket & recv_data )
2008-10-02 16:23:55 -05:00
{
2012-01-14 19:27:14 +00:00
uint32 talentId , requestedRank ;
recv_data >> talentId >> requestedRank ;
2009-10-17 15:51:44 -07:00
2012-01-29 17:40:14 +01:00
if ( _player -> LearnTalent ( talentId , requestedRank ))
_player -> SendTalentsInfoData ( false );
2009-06-11 00:45:59 -05:00
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
void WorldSession :: HandleLearnPreviewTalents ( WorldPacket & recvPacket )
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "CMSG_LEARN_PREVIEW_TALENTS" );
2009-10-17 15:51:44 -07:00
2012-01-29 17:40:14 +01:00
int32 tabPage ;
2009-06-11 00:45:59 -05:00
uint32 talentsCount ;
2012-01-29 17:40:14 +01:00
recvPacket >> tabPage ; // talent tree
// prevent cheating (selecting new tree with points already in another)
if ( tabPage >= 0 ) // -1 if player already has specialization
{
2012-01-29 18:22:50 +01:00
if ( TalentTabEntry const * talentTabEntry = sTalentTabStore . LookupEntry ( _player -> GetPrimaryTalentTree ( _player -> GetActiveSpec ())))
2012-01-29 17:40:14 +01:00
{
if ( talentTabEntry -> tabpage != tabPage )
{
recvPacket . rfinish ();
return ;
}
}
}
2009-06-11 00:45:59 -05:00
recvPacket >> talentsCount ;
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
uint32 talentId , talentRank ;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( uint32 i = 0 ; i < talentsCount ; ++ i )
2009-06-11 00:45:59 -05:00
{
recvPacket >> talentId >> talentRank ;
2009-10-17 15:51:44 -07:00
2012-01-29 17:40:14 +01:00
if ( ! _player -> LearnTalent ( talentId , talentRank ))
{
recvPacket . rfinish ();
break ;
}
2009-06-11 00:45:59 -05:00
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
_player -> SendTalentsInfoData ( false );
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleTalentWipeConfirmOpcode ( WorldPacket & recv_data )
2008-10-02 16:23:55 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "MSG_TALENT_WIPE_CONFIRM" );
2008-10-02 16:23:55 -05:00
uint64 guid ;
recv_data >> guid ;
2009-10-17 15:51:44 -07:00
2011-06-12 01:47:45 +02:00
Creature * unit = GetPlayer () -> GetNPCIfCanInteractWith ( guid , UNIT_NPC_FLAG_TRAINER );
2008-10-02 16:23:55 -05:00
if ( ! unit )
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: HandleTalentWipeConfirmOpcode - Unit (GUID: %u) not found or you can't interact with him." , uint32 ( GUID_LOPART ( guid )));
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// remove fake death
2010-12-17 13:43:24 +01:00
if ( GetPlayer () -> HasUnitState ( UNIT_STAT_DIED ))
2009-04-06 13:31:14 +02:00
GetPlayer () -> RemoveAurasByType ( SPELL_AURA_FEIGN_DEATH );
2009-10-17 15:51:44 -07:00
2012-01-29 17:40:14 +01:00
if ( ! _player -> ResetTalents ())
2008-10-02 16:23:55 -05:00
{
2010-04-07 22:59:46 +02:00
WorldPacket data ( MSG_TALENT_WIPE_CONFIRM , 8 + 4 ); //you have not any talent
2008-10-02 16:23:55 -05:00
data << uint64 ( 0 );
data << uint32 ( 0 );
2010-04-07 22:59:46 +02:00
SendPacket ( & data );
2008-10-02 16:23:55 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
_player -> SendTalentsInfoData ( false );
2008-10-02 16:23:55 -05:00
unit -> CastSpell ( _player , 14867 , true ); //spell: "Untalent Visual Effect"
}
2009-10-17 15:51:44 -07:00
2012-01-14 18:21:36 +00:00
void WorldSession :: HandleUnlearnSkillOpcode ( WorldPacket & recv_data )
2008-10-02 16:23:55 -05:00
{
2012-01-14 18:21:36 +00:00
uint32 skillId ;
recv_data >> skillId ;
GetPlayer () -> SetSkill ( skillId , 0 , 0 , 0 );
2008-10-02 16:23:55 -05:00
}
2009-02-17 20:07:49 -06:00