2 * Copyright (C) 2005-2008 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
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectAccessor.h"
25 #include "CreatureAI.h"
26 #include "ObjectDefines.h"
28 void WorldSession::HandleAttackSwingOpcode( WorldPacket
& recv_data
)
30 CHECK_PACKET_SIZE(recv_data
,8);
35 DEBUG_LOG( "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid
), GUID_HIPART(guid
) );
37 Unit
*pEnemy
= ObjectAccessor::GetUnit(*_player
, guid
);
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
)));
44 sLog
.outError( "WORLD: Enemy %s %u not found",GetLogNameForGuid(guid
),GUID_LOPART(guid
));
46 // stop attack state at client
51 if(_player
->IsFriendlyTo(pEnemy
) || pEnemy
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
| UNIT_FLAG_NOT_SELECTABLE
))
53 sLog
.outError( "WORLD: Enemy %s %u is friendly",(IS_PLAYER_GUID(guid
) ? "player" : "creature"),GUID_LOPART(guid
));
55 // stop attack state at client
56 SendAttackStop(pEnemy
);
60 if(!pEnemy
->isAlive())
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
);
68 _player
->Attack(pEnemy
,true);
71 void WorldSession::HandleAttackStopOpcode( WorldPacket
& /*recv_data*/ )
73 GetPlayer()->AttackStop();
76 void WorldSession::HandleSetSheathedOpcode( WorldPacket
& recv_data
)
78 CHECK_PACKET_SIZE(recv_data
,4);
81 recv_data
>> sheathed
;
83 //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed );
85 GetPlayer()->SetSheath(sheathed
);
88 void WorldSession::SendAttackStop(Unit
const* enemy
)
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