2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2014-01-01 00:07:53 +01:00
|
|
|
* Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
|
2010-10-07 15:35:36 +02:00
|
|
|
* 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"
|
2011-12-11 14:40:01 +01:00
|
|
|
#include "Vehicle.h"
|
|
|
|
|
#include "VehicleDefines.h"
|
2012-11-17 05:18:37 +01:00
|
|
|
#include "Player.h"
|
2012-11-20 14:54:33 +01:00
|
|
|
#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
|
|
|
|
2013-11-08 10:50:51 +01: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
|
|
|
|
2011-09-15 14:08:17 +02: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
|
|
|
|
2011-09-16 23:49:31 +02: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
|
|
|
|
2011-12-11 14:40:01 +01: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
|
|
|
|
2013-11-08 10:50:51 +01: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)
|
2009-05-28 18:43:57 -05:00
|
|
|
{
|
2013-11-08 10:50:51 +01:00
|
|
|
TC_LOG_ERROR("network", "Unknown sheath state %u ??", sheathed);
|
2009-05-28 18:43:57 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2009-05-28 18:43:57 -05: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)
|
|
|
|
|
{
|
2010-09-16 18:05:50 +02:00
|
|
|
WorldPacket data(SMSG_ATTACKSTOP, (8+8+4)); // we guess size
|
2008-10-02 16:23:55 -05:00
|
|
|
data.append(GetPlayer()->GetPackGUID());
|
2014-07-27 17:46:46 +02:00
|
|
|
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);
|
|
|
|
|
}
|