Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
CombatHandler.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "Common.h"
7#include "CreatureAI.h"
8#include "Log.h"
9#include "ObjectAccessor.h"
10#include "ObjectDefines.h"
11#include "Opcodes.h"
12#include "Player.h"
13#include "Vehicle.h"
14#include "VehicleDefines.h"
15#include "WorldPacket.h"
16#include "WorldSession.h"
17
19{
20 ObjectGuid guid;
21
22 recvData.ReadGuidMask(guid, 6, 5, 7, 0, 3, 1, 4, 2);
23 recvData.ReadGuidBytes(guid, 6, 7, 1, 3, 2, 0, 4, 5);
24
25 SF_LOG_DEBUG("network", "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid), GUID_HIPART(guid));
26
27 Unit* pEnemy = ObjectAccessor::GetUnit(*_player, guid);
28
29 if (!pEnemy)
30 {
31 // stop attack state at client
32 SendAttackStop(NULL);
33 return;
34 }
35
36 if (!_player->IsValidAttackTarget(pEnemy))
37 {
38 // stop attack state at client
39 SendAttackStop(pEnemy);
40 return;
41 }
42
46 if (Vehicle* vehicle = _player->GetVehicle())
47 {
48 VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(_player);
49 ASSERT(seat);
51 {
52 SendAttackStop(pEnemy);
53 return;
54 }
55 }
56
57 _player->Attack(pEnemy, true);
58}
59
64
66{
67 uint32 sheathed;
68 bool hasData = false;
69
70 recvData >> sheathed;
71 hasData = recvData.ReadBit();
72
73 //SF_LOG_DEBUG("network", "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed);
74
75 if (hasData)
76 {
77 if (sheathed >= MAX_SHEATH_STATE)
78 {
79 SF_LOG_ERROR("network", "Unknown sheath state %u ??", sheathed);
80 return;
81 }
82
83 GetPlayer()->SetSheath(SheathState(sheathed));
84 }
85}
86
88{
89 WorldPacket data(SMSG_ATTACKSTOP, (8 + 8 + 4)); // 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);
94}
@ VEHICLE_SEAT_FLAG_CAN_ATTACK
Definition DBCEnums.h:532
std::uint32_t uint32
Definition Define.h:77
#define ASSERT
Definition Errors.h:29
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
uint32 GUID_LOPART(uint64 x)
uint32 GUID_HIPART(uint64 guid)
SheathState
Definition Unit.h:244
#define MAX_SHEATH_STATE
Definition Unit.h:250
void ReadGuidBytes(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:256
void append(T value)
Definition ByteBuffer.h:147
void ReadGuidMask(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:240
bool ReadBit()
Definition ByteBuffer.h:180
static Unit * GetUnit(WorldObject const &, uint64 guid)
const ByteBuffer & GetPackGUID() const
Definition Object.h:124
void SetSheath(SheathState sheathed) override
Definition Player.cpp:10471
Definition Unit.h:1367
bool AttackStop()
Player * GetPlayer() const
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Player * _player
void HandleAttackSwingOpcode(WorldPacket &recvPacket)
void SendAttackStop(Unit const *enemy)
void HandleSetSheathedOpcode(WorldPacket &recvPacket)
void HandleAttackStopOpcode(WorldPacket &recvPacket)
@ SMSG_ATTACKSTOP
Definition Opcodes.h:520
uint32 m_flags