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 "DB2Structure.h"
23#include "Log.h"
24#include "ObjectAccessor.h"
25#include "Player.h"
26#include "Vehicle.h"
27
29{
30 Unit* enemy = ObjectAccessor::GetUnit(*_player, packet.Victim);
31
32 if (!enemy)
33 {
34 // stop attack state at client
35 SendAttackStop(nullptr);
36 return;
37 }
38
39 if (!_player->IsValidAttackTarget(enemy))
40 {
41 // stop attack state at client
42 SendAttackStop(enemy);
43 return;
44 }
45
49 if (Vehicle* vehicle = _player->GetVehicle())
50 {
51 VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(_player);
52 ASSERT(seat);
54 {
55 SendAttackStop(enemy);
56 return;
57 }
58 }
59
60 _player->Attack(enemy, true);
61}
62
67
69{
71 {
72 TC_LOG_ERROR("network", "Unknown sheath state {} ??", packet.CurrentSheathState);
73 return;
74 }
75
77}
78
80{
82 attackStop.Attacker = _player->GetGUID();
83 if (enemy)
84 {
85 attackStop.Victim = enemy->GetGUID();
86 attackStop.NowDead = !enemy->IsAlive();
87 }
88
89 SendPacket(attackStop.Write());
90}
@ VEHICLE_SEAT_FLAG_CAN_ATTACK
Definition DBCEnums.h:3106
#define ASSERT
Definition Errors.h:80
#define TC_LOG_ERROR(filterType__, message__,...)
Definition Log.h:190
SheathState
Definition UnitDefines.h:81
@ MAX_SHEATH_STATE
Definition UnitDefines.h:86
ObjectGuid const & GetGUID() const
Definition BaseEntity.h:163
Definition Unit.h:635
Vehicle * GetVehicle() const
Definition Unit.h:1784
bool IsAlive() const
Definition Unit.h:1185
void SetSheath(SheathState sheathed)
Definition Unit.cpp:5813
bool Attack(Unit *victim, bool meleeAttack)
Definition Unit.cpp:5853
bool AttackStop()
Definition Unit.cpp:5965
bool IsValidAttackTarget(WorldObject const *target, SpellInfo const *bySpell=nullptr) const
Definition Object.cpp:2324
WorldPacket const * Write() override
Player * GetPlayer() const
void HandleAttackStopOpcode(WorldPackets::Combat::AttackStop &packet)
void HandleSetSheathedOpcode(WorldPackets::Combat::SetSheathed &packet)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Player * _player
void HandleAttackSwingOpcode(WorldPackets::Combat::AttackSwing &packet)
void SendAttackStop(Unit const *enemy)
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)