root/trunk/src/game/SkillHandler.cpp @ 6

Revision 2, 5.5 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "Common.h"
20#include "Database/DatabaseEnv.h"
21#include "Opcodes.h"
22#include "Log.h"
23#include "Player.h"
24#include "World.h"
25#include "WorldPacket.h"
26#include "WorldSession.h"
27#include "ObjectAccessor.h"
28#include "UpdateMask.h"
29#include "SpellAuras.h"
30
31void WorldSession::HandleLearnTalentOpcode( WorldPacket & recv_data )
32{
33    CHECK_PACKET_SIZE(recv_data,4+4);
34
35    uint32 talent_id, requested_rank;
36    recv_data >> talent_id >> requested_rank;
37
38    uint32 CurTalentPoints =  GetPlayer()->GetFreeTalentPoints();
39
40    if(CurTalentPoints == 0)
41        return;
42
43    if (requested_rank > 4)
44        return;
45
46    TalentEntry const *talentInfo = sTalentStore.LookupEntry( talent_id );
47
48    if(!talentInfo)
49        return;
50
51    TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
52
53    if(!talentTabInfo)
54        return;
55
56    Player * player = GetPlayer();
57
58    // prevent learn talent for different class (cheating)
59    if( (player->getClassMask() & talentTabInfo->ClassMask) == 0 )
60        return;
61
62    // prevent skip talent ranks (cheating)
63    if(requested_rank > 0 && !player->HasSpell(talentInfo->RankID[requested_rank-1]))
64        return;
65
66    // Check if it requires another talent
67    if (talentInfo->DependsOn > 0)
68    {
69        if(TalentEntry const *depTalentInfo = sTalentStore.LookupEntry(talentInfo->DependsOn))
70        {
71            bool hasEnoughRank = false;
72            for (int i = talentInfo->DependsOnRank; i <= 4; i++)
73            {
74                if (depTalentInfo->RankID[i] != 0)
75                    if (player->HasSpell(depTalentInfo->RankID[i]))
76                        hasEnoughRank = true;
77            }
78            if (!hasEnoughRank)
79                return;
80        }
81    }
82
83    // Check if it requires spell
84    if( talentInfo->DependsOnSpell && !player->HasSpell(talentInfo->DependsOnSpell) )
85        return;
86
87    // Find out how many points we have in this field
88    uint32 spentPoints = 0;
89
90    uint32 tTab = talentInfo->TalentTab;
91    if (talentInfo->Row > 0)
92    {
93        unsigned int numRows = sTalentStore.GetNumRows();
94        for (unsigned int i = 0; i < numRows; i++)          // Loop through all talents.
95        {
96            // Someday, someone needs to revamp
97            const TalentEntry *tmpTalent = sTalentStore.LookupEntry(i);
98            if (tmpTalent)                                  // the way talents are tracked
99            {
100                if (tmpTalent->TalentTab == tTab)
101                {
102                    for (int j = 0; j <= 4; j++)
103                    {
104                        if (tmpTalent->RankID[j] != 0)
105                        {
106                            if (player->HasSpell(tmpTalent->RankID[j]))
107                            {
108                                spentPoints += j + 1;
109                            }
110                        }
111                    }
112                }
113            }
114        }
115    }
116
117    // not have required min points spent in talent tree
118    if(spentPoints < (talentInfo->Row * 5))
119        return;
120
121    // spell not set in talent.dbc
122    uint32 spellid = talentInfo->RankID[requested_rank];
123    if( spellid == 0 )
124    {
125        sLog.outError("Talent.dbc have for talent: %u Rank: %u spell id = 0", talent_id, requested_rank);
126        return;
127    }
128
129    // already known
130    if(GetPlayer( )->HasSpell(spellid))
131        return;
132
133    // learn! (other talent ranks will unlearned at learning)
134    GetPlayer( )->learnSpell(spellid);
135    sLog.outDetail("TalentID: %u Rank: %u Spell: %u\n", talent_id, requested_rank, spellid);
136
137    // update free talent points
138    GetPlayer()->SetFreeTalentPoints(CurTalentPoints - 1);
139}
140
141void WorldSession::HandleTalentWipeOpcode( WorldPacket & recv_data )
142{
143    CHECK_PACKET_SIZE(recv_data,8);
144
145    sLog.outDetail("MSG_TALENT_WIPE_CONFIRM");
146    uint64 guid;
147    recv_data >> guid;
148
149    Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid,UNIT_NPC_FLAG_TRAINER);
150    if (!unit)
151    {
152        sLog.outDebug( "WORLD: HandleTalentWipeOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
153        return;
154    }
155
156    // remove fake death
157    if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
158        GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
159
160    if(!(_player->resetTalents()))
161    {
162        WorldPacket data( MSG_TALENT_WIPE_CONFIRM, 8+4);    //you have not any talent
163        data << uint64(0);
164        data << uint32(0);
165        SendPacket( &data );
166        return;
167    }
168
169    unit->CastSpell(_player, 14867, true);                  //spell: "Untalent Visual Effect"
170}
171
172void WorldSession::HandleUnlearnSkillOpcode(WorldPacket & recv_data)
173{
174    CHECK_PACKET_SIZE(recv_data,4);
175
176    uint32 skill_id;
177    recv_data >> skill_id;
178    GetPlayer()->SetSkill(skill_id, 0, 0);
179}
Note: See TracBrowser for help on using the browser.