[7607] Improvements in support some generic achievement classes
[AHbot.git] / src / game / CombatHandler.cpp
blob12fedd89a38bca2a1aea9a1f7acacbb6d30d5acb
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 "Log.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "ObjectAccessor.h"
24 #include "CreatureAI.h"
25 #include "ObjectDefines.h"
27 void WorldSession::HandleAttackSwingOpcode( WorldPacket & recv_data )
29 CHECK_PACKET_SIZE(recv_data,8);
31 uint64 guid;
32 recv_data >> guid;
34 DEBUG_LOG( "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid), GUID_HIPART(guid) );
36 Unit *pEnemy = ObjectAccessor::GetUnit(*_player, guid);
38 if(!pEnemy)
40 if(!IS_UNIT_GUID(guid))
41 sLog.outError("WORLD: Object %u (TypeID: %u) isn't player, pet or creature",GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)));
42 else
43 sLog.outError( "WORLD: Enemy %s %u not found",GetLogNameForGuid(guid),GUID_LOPART(guid));
45 // stop attack state at client
46 SendAttackStop(NULL);
47 return;
50 if(_player->IsFriendlyTo(pEnemy) || pEnemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
52 sLog.outError( "WORLD: Enemy %s %u is friendly",(IS_PLAYER_GUID(guid) ? "player" : "creature"),GUID_LOPART(guid));
54 // stop attack state at client
55 SendAttackStop(pEnemy);
56 return;
59 if(!pEnemy->isAlive())
61 // client can generate swing to known dead target if autoswitch between autoshot and autohit is enabled in client options
62 // stop attack state at client
63 SendAttackStop(pEnemy);
64 return;
67 _player->Attack(pEnemy,true);
70 void WorldSession::HandleAttackStopOpcode( WorldPacket & /*recv_data*/ )
72 GetPlayer()->AttackStop();
75 void WorldSession::HandleSetSheathedOpcode( WorldPacket & recv_data )
77 CHECK_PACKET_SIZE(recv_data,4);
79 uint32 sheathed;
80 recv_data >> sheathed;
82 //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed );
84 GetPlayer()->SetSheath(sheathed);
87 void WorldSession::SendAttackStop(Unit const* enemy)
89 WorldPacket data( SMSG_ATTACKSTOP, (4+20) ); // we guess size
90 data.append(GetPlayer()->GetPackGUID());
91 data.append(enemy ? enemy->GetPackGUID() : 0); // must be packed guid
92 data << uint32(0); // unk, can be 1 also
93 SendPacket(&data);