[9547] Implement ObjectGuid wrapper for guid value
[getmangos.git] / src / game / CombatHandler.cpp
blob7aef031e14845e0bf05126ff846f12a67f617894
1 /*
2 * Copyright (C) 2005-2010 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 "ObjectGuid.h"
27 void WorldSession::HandleAttackSwingOpcode( WorldPacket & recv_data )
29 ObjectGuid guid;
30 recv_data >> guid;
32 DEBUG_LOG("WORLD: Recvd CMSG_ATTACKSWING Message %s", guid.GetString().c_str());
34 Unit *pEnemy = ObjectAccessor::GetUnit(*_player, guid.GetRawValue());
36 if(!pEnemy)
38 if(!guid.IsUnit())
39 sLog.outError("WORLD: %u isn't player, pet or creature", guid.GetString().c_str());
40 else
41 sLog.outError( "WORLD: Enemy %s not found", guid.GetString().c_str());
43 // stop attack state at client
44 SendAttackStop(NULL);
45 return;
48 if(_player->IsFriendlyTo(pEnemy) || pEnemy->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE))
50 sLog.outError( "WORLD: Enemy %s is friendly",guid.GetString().c_str());
52 // stop attack state at client
53 SendAttackStop(pEnemy);
54 return;
57 if(!pEnemy->isAlive())
59 // client can generate swing to known dead target if autoswitch between autoshot and autohit is enabled in client options
60 // stop attack state at client
61 SendAttackStop(pEnemy);
62 return;
65 _player->Attack(pEnemy,true);
68 void WorldSession::HandleAttackStopOpcode( WorldPacket & /*recv_data*/ )
70 GetPlayer()->AttackStop();
73 void WorldSession::HandleSetSheathedOpcode( WorldPacket & recv_data )
75 uint32 sheathed;
76 recv_data >> sheathed;
78 //sLog.outDebug( "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed );
80 if(sheathed >= MAX_SHEATH_STATE)
82 sLog.outError("Unknown sheath state %u ??",sheathed);
83 return;
86 GetPlayer()->SetSheath(SheathState(sheathed));
89 void WorldSession::SendAttackStop(Unit const* enemy)
91 WorldPacket data( SMSG_ATTACKSTOP, (4+20) ); // we guess size
92 data.append(GetPlayer()->GetPackGUID());
93 data.append(enemy ? enemy->GetPackGUID() : 0); // must be packed guid
94 data << uint32(0); // unk, can be 1 also
95 SendPacket(&data);