Files
TCPlayerbotCore/src/server/game/Handlers/CombatHandler.cpp
T

104 lines
3.0 KiB
C++
Raw Normal View History

/*
2014-01-01 00:07:53 +01:00
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Common.h"
#include "Log.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "ObjectAccessor.h"
#include "CreatureAI.h"
#include "ObjectDefines.h"
#include "Vehicle.h"
#include "VehicleDefines.h"
#include "Player.h"
#include "Opcodes.h"
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession::HandleAttackSwingOpcode(WorldPacket& recvData)
2008-10-02 16:23:55 -05:00
{
uint64 guid;
2012-11-02 22:23:14 +01:00
recvData >> guid;
2009-10-17 15:51:44 -07:00
TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_ATTACKSWING Message guidlow:%u guidhigh:%u", GUID_LOPART(guid), GUID_HIPART(guid));
2009-10-17 15:51:44 -07:00
Unit* pEnemy = ObjectAccessor::GetUnit(*_player, guid);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (!pEnemy)
2008-10-02 16:23:55 -05:00
{
// stop attack state at client
SendAttackStop(NULL);
return;
}
2009-10-17 15:51:44 -07:00
if (!_player->IsValidAttackTarget(pEnemy))
2008-10-02 16:23:55 -05:00
{
// stop attack state at client
SendAttackStop(pEnemy);
return;
}
2009-10-17 15:51:44 -07:00
//! Client explicitly checks the following before sending CMSG_ATTACKSWING packet,
//! so we'll place the same check here. Note that it might be possible to reuse this snippet
//! in other places as well.
if (Vehicle* vehicle = _player->GetVehicle())
{
VehicleSeatEntry const* seat = vehicle->GetSeatForPassenger(_player);
ASSERT(seat);
if (!(seat->m_flags & VEHICLE_SEAT_FLAG_CAN_ATTACK))
{
SendAttackStop(pEnemy);
return;
}
}
2011-04-29 20:47:02 +02:00
_player->Attack(pEnemy, true);
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession::HandleAttackStopOpcode(WorldPacket & /*recvData*/)
2008-10-02 16:23:55 -05:00
{
GetPlayer()->AttackStop();
}
2009-10-17 15:51:44 -07:00
2012-11-02 22:23:14 +01:00
void WorldSession::HandleSetSheathedOpcode(WorldPacket& recvData)
2008-10-02 16:23:55 -05:00
{
uint32 sheathed;
2012-11-02 22:23:14 +01:00
recvData >> sheathed;
2009-10-17 15:51:44 -07:00
//TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_SETSHEATHED Message guidlow:%u value1:%u", GetPlayer()->GetGUIDLow(), sheathed);
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if (sheathed >= MAX_SHEATH_STATE)
{
TC_LOG_ERROR("network", "Unknown sheath state %u ??", sheathed);
return;
}
2009-10-17 15:51:44 -07:00
GetPlayer()->SetSheath(SheathState(sheathed));
2008-10-02 16:23:55 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
void WorldSession::SendAttackStop(Unit const* enemy)
{
WorldPacket data(SMSG_ATTACKSTOP, (8+8+4)); // we guess size
2008-10-02 16:23:55 -05:00
data.append(GetPlayer()->GetPackGUID());
if (enemy)
data.append(enemy->GetPackGUID());
else
data << uint8(0);
2008-10-02 16:23:55 -05:00
data << uint32(0); // unk, can be 1 also
SendPacket(&data);
}