OregonCore  revision fb2a440-git
Your Favourite TBC server
CombatHandler.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "Log.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "ObjectAccessor.h"
23 #include "CreatureAI.h"
24 #include "ObjectGuid.h"
25 
27 {
28  ObjectGuid guid;
29  recv_data >> guid;
30 
31  DEBUG_LOG("WORLD: Recvd CMSG_ATTACKSWING Message %s", guid.GetString().c_str());
32 
33  Unit* pEnemy = ObjectAccessor::GetUnit(*_player, guid.GetRawValue());
34 
35  if (!pEnemy)
36  {
37  if (!guid.IsUnit())
38  sLog.outError("WORLD: %s isn't player, pet or creature", guid.GetString().c_str());
39  else
40  sLog.outError("WORLD: Enemy %s not found", guid.GetString().c_str());
41 
42  // stop attack state at client
43  SendAttackStop(NULL);
44  return;
45  }
46 
47  if (!_player->IsValidAttackTarget(pEnemy))
48  {
49  // stop attack state at client
50  SendAttackStop(pEnemy);
51  return;
52  }
53 
54  _player->Attack(pEnemy, true);
55 }
56 
58 {
59  GetPlayer()->AttackStop();
60 }
61 
63 {
64  uint32 sheathed;
65  recv_data >> sheathed;
66 
67  if (sheathed >= MAX_SHEATH_STATE)
68  {
69  sLog.outError("Unknown sheath state %u ??", sheathed);
70  return;
71  }
72 
73  GetPlayer()->SetSheath(SheathState(sheathed));
74 }
75 
77 {
78  WorldPacket data(SMSG_ATTACKSTOP, (4 + 20)); // we guess size
79  data << GetPlayer()->GetPackGUID();
80  data << (enemy ? enemy->GetPackGUID() : PackedGuid()); // must be packed guid
81  data << uint32(0); // unk, can be 1 also
82  SendPacket(&data);
83 }
84 
bool AttackStop()
Definition: Unit.cpp:7484
void SendAttackStop(Unit const *enemy)
bool Attack(Unit *victim, bool meleeAttack)
Definition: Unit.cpp:7390
bool IsValidAttackTarget(Unit const *target) const
Definition: Unit.cpp:9510
#define sLog
Log class singleton.
Definition: Log.h:187
void HandleAttackSwingOpcode(WorldPacket &recvPacket)
void HandleAttackStopOpcode(WorldPacket &recvPacket)
Player * GetPlayer() const
Definition: WorldSession.h:104
void SetSheath(SheathState sheathed) override
Definition: Player.cpp:8241
void SendPacket(WorldPacket const *packet)
SheathState
Definition: Unit.h:220
#define MAX_SHEATH_STATE
Definition: Unit.h:227
PackedGuid const & GetPackGUID() const
Definition: Object.h:178
#define DEBUG_LOG(...)
Definition: Log.h:194
Player * _player
Definition: WorldSession.h:730
static Unit * GetUnit(WorldObject const &, uint64 guid)
ACE_UINT32 uint32
Definition: Define.h:71
void HandleSetSheathedOpcode(WorldPacket &recvPacket)
Definition: Unit.h:908