root/trunk/src/game/CombatHandler.cpp @ 9

Revision 2, 3.1 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 "Log.h"
21#include "WorldPacket.h"
22#include "WorldSession.h"
23#include "World.h"
24#include "ObjectAccessor.h"
25#include "CreatureAI.h"
26#include "ObjectDefines.h"
27
28void WorldSession::HandleAttackSwingOpcode( WorldPacket & recv_data )
29{
30    CHECK_PACKET_SIZE(recv_data,8);
31
32    uint64 guid;
33    recv_data >> guid;
34
35    DEBUG_LOG( "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid), GUID_HIPART(guid) );
36
37    Unit *pEnemy = ObjectAccessor::GetUnit(*_player, guid);
38
39    if(!pEnemy)
40    {
41        if(!IS_UNIT_GUID(guid))
42            sLog.outError("WORLD: Object %u (TypeID: %u) isn't player, pet or creature",GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)));
43        else
44            sLog.outError( "WORLD: Enemy %s %u not found",GetLogNameForGuid(guid),GUID_LOPART(guid));
45
46        // stop attack state at client
47        SendAttackStop(NULL);
48        return;
49    }
50
51    if(_player->IsFriendlyTo(pEnemy) || pEnemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
52    {
53        sLog.outError( "WORLD: Enemy %s %u is friendly",(IS_PLAYER_GUID(guid) ? "player" : "creature"),GUID_LOPART(guid));
54
55        // stop attack state at client
56        SendAttackStop(pEnemy);
57        return;
58    }
59
60    if(!pEnemy->isAlive())
61    {
62        // client can generate swing to known dead target if autoswitch between autoshot and autohit is enabled in client options
63        // stop attack state at client
64        SendAttackStop(pEnemy);
65        return;
66    }
67
68    _player->Attack(pEnemy,true);
69}
70
71void WorldSession::HandleAttackStopOpcode( WorldPacket & /*recv_data*/ )
72{
73    GetPlayer()->AttackStop();
74}
75
76void WorldSession::HandleSetSheathedOpcode( WorldPacket & recv_data )
77{
78    CHECK_PACKET_SIZE(recv_data,4);
79
80    uint32 sheathed;
81    recv_data >> sheathed;
82
83    //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed );
84
85    GetPlayer()->SetSheath(sheathed);
86}
87
88void WorldSession::SendAttackStop(Unit const* enemy)
89{
90    WorldPacket data( SMSG_ATTACKSTOP, (4+20) );            // we guess size
91    data.append(GetPlayer()->GetPackGUID());
92    data.append(enemy ? enemy->GetPackGUID() : 0);          // must be packed guid
93    data << uint32(0);                                      // unk, can be 1 also
94    SendPacket(&data);
95}
Note: See TracBrowser for help on using the browser.