TrinityCore
Loading...
Searching...
No Matches
CombatHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 "WorldSession.h"
19#include "CombatPackets.h"
20#include "Common.h"
21#include "CreatureAI.h"
22#include "DBCStructure.h"
23#include "Log.h"
24#include "ObjectAccessor.h"
25#include "Player.h"
26#include "Vehicle.h"
27#include "WorldPacket.h"
28
30{
31 Unit* enemy = ObjectAccessor::GetUnit(*_player, packet.Victim);
32
33 if (!enemy)
34 {
35 // stop attack state at client
36 SendAttackStop(nullptr);
37 return;
38 }
39
40 if (!_player->IsValidAttackTarget(enemy))
41 {
42 // stop attack state at client
43 SendAttackStop(enemy);
44 return;
45 }
46
50 if (Vehicle* vehicle = _player->GetVehicle())
51 {
52 VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(_player);
53 ASSERT(seat);
55 {
56 SendAttackStop(enemy);
57 return;
58 }
59 }
60
61 _player->Attack(enemy, true);
62}
63
68
70{
72 {
73 TC_LOG_ERROR("network", "Unknown sheath state {} ??", packet.CurrentSheathState);
74 return;
75 }
76
78}
79
@ VEHICLE_SEAT_FLAG_CAN_ATTACK
Definition DBCEnums.h:483
#define ASSERT
Definition Errors.h:68
#define TC_LOG_ERROR(filterType__,...)
Definition Log.h:165
SheathState
Definition UnitDefines.h:97
@ MAX_SHEATH_STATE
void SetSheath(SheathState sheathed) override
Definition Player.cpp:9206
Definition Unit.h:769
Vehicle * GetVehicle() const
Definition Unit.h:1737
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5535
bool AttackStop()
Definition Unit.cpp:5645
bool IsValidAttackTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition Object.cpp:2856
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Player * GetPlayer() const
void HandleAttackStopOpcode(WorldPackets::Combat::AttackStop &packet)
void HandleSetSheathedOpcode(WorldPackets::Combat::SetSheathed &packet)
Player * _player
void HandleAttackSwingOpcode(WorldPackets::Combat::AttackSwing &packet)
void SendAttackStop(Unit const *enemy)
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)