2010-10-07 15:35:36 +02:00
|
|
|
/*
|
2020-01-02 06:44:10 +01:00
|
|
|
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
|
2010-10-07 15:35:36 +02:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "WorldSession.h"
|
|
|
|
|
#include "CombatPackets.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Common.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "CreatureAI.h"
|
|
|
|
|
#include "DB2Structure.h"
|
2008-10-02 16:23:55 -05:00
|
|
|
#include "Log.h"
|
|
|
|
|
#include "ObjectAccessor.h"
|
2012-11-17 05:18:37 +01:00
|
|
|
#include "Player.h"
|
2017-06-04 01:00:45 +02:00
|
|
|
#include "Vehicle.h"
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2014-11-15 22:00:31 +02:00
|
|
|
void WorldSession::HandleAttackSwingOpcode(WorldPackets::Combat::AttackSwing& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-02-17 21:08:28 +01:00
|
|
|
Unit* enemy = ObjectAccessor::GetUnit(*_player, packet.Victim);
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-02-17 21:08:28 +01:00
|
|
|
if (!enemy)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
// stop attack state at client
|
2015-02-17 21:08:28 +01:00
|
|
|
SendAttackStop(nullptr);
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-02-17 21:08:28 +01:00
|
|
|
if (!_player->IsValidAttackTarget(enemy))
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
// stop attack state at client
|
2015-02-17 21:08:28 +01:00
|
|
|
SendAttackStop(enemy);
|
2008-10-02 16:23:55 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2020-03-12 20:06:15 +04:00
|
|
|
//! Client explicitly checks the following before sending CMSG_ATTACK_SWING packet,
|
2011-12-11 14:40:01 +01:00
|
|
|
//! 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);
|
2018-03-12 18:20:26 +01:00
|
|
|
if (!(seat->Flags & VEHICLE_SEAT_FLAG_CAN_ATTACK))
|
2011-12-11 14:40:01 +01:00
|
|
|
{
|
2015-02-17 21:08:28 +01:00
|
|
|
SendAttackStop(enemy);
|
2011-12-11 14:40:01 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 21:08:28 +01:00
|
|
|
_player->Attack(enemy, true);
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2020-03-12 20:06:15 +04:00
|
|
|
void WorldSession::HandleAttackStopOpcode(WorldPackets::Combat::AttackStop& /*packet*/)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
|
|
|
|
GetPlayer()->AttackStop();
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-02-14 15:09:09 +01:00
|
|
|
void WorldSession::HandleSetSheathedOpcode(WorldPackets::Combat::SetSheathed& packet)
|
2008-10-02 16:23:55 -05:00
|
|
|
{
|
2015-02-14 15:09:09 +01:00
|
|
|
if (packet.CurrentSheathState >= MAX_SHEATH_STATE)
|
2009-05-28 18:43:57 -05:00
|
|
|
{
|
2015-02-14 15:09:09 +01:00
|
|
|
TC_LOG_ERROR("network", "Unknown sheath state %u ??", packet.CurrentSheathState);
|
2009-05-28 18:43:57 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2009-10-17 15:51:44 -07:00
|
|
|
|
2015-02-14 15:09:09 +01:00
|
|
|
GetPlayer()->SetSheath(SheathState(packet.CurrentSheathState));
|
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)
|
|
|
|
|
{
|
2015-02-17 21:08:28 +01:00
|
|
|
SendPacket(WorldPackets::Combat::SAttackStop(GetPlayer(), enemy).Write());
|
2008-10-02 16:23:55 -05:00
|
|
|
}
|