mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-26 15:16:24 +00:00
Using TC structure allowing easier patches importing
This commit is contained in:
275
src/server/game/Handlers/TaxiHandler.cpp
Normal file
275
src/server/game/Handlers/TaxiHandler.cpp
Normal file
@@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "WorldPacket.h"
|
||||
#include "WorldSession.h"
|
||||
#include "Opcodes.h"
|
||||
#include "Log.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "Player.h"
|
||||
#include "UpdateMask.h"
|
||||
#include "WaypointMovementGenerator.h"
|
||||
|
||||
void WorldSession::HandleTaxiNodeStatusQueryOpcode(WorldPacket & recvData)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_TAXINODE_STATUS_QUERY");
|
||||
#endif
|
||||
|
||||
uint64 guid;
|
||||
|
||||
recvData >> guid;
|
||||
SendTaxiStatus(guid);
|
||||
}
|
||||
|
||||
void WorldSession::SendTaxiStatus(uint64 guid)
|
||||
{
|
||||
// cheating checks
|
||||
Creature* unit = GetPlayer()->GetMap()->GetCreature(guid);
|
||||
if (!unit)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeamId());
|
||||
|
||||
// not found nearest
|
||||
if (curloc == 0)
|
||||
return;
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: current location %u ", curloc);
|
||||
#endif
|
||||
|
||||
WorldPacket data(SMSG_TAXINODE_STATUS, 9);
|
||||
data << guid;
|
||||
data << uint8(GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0);
|
||||
SendPacket(&data);
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_TAXINODE_STATUS");
|
||||
#endif
|
||||
}
|
||||
|
||||
void WorldSession::HandleTaxiQueryAvailableNodes(WorldPacket & recvData)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_TAXIQUERYAVAILABLENODES");
|
||||
#endif
|
||||
|
||||
uint64 guid;
|
||||
recvData >> guid;
|
||||
|
||||
// cheating checks
|
||||
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
|
||||
if (!unit)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// remove fake death
|
||||
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
||||
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
||||
|
||||
// unknown taxi node case
|
||||
if (SendLearnNewTaxiNode(unit))
|
||||
return;
|
||||
|
||||
// known taxi node case
|
||||
SendTaxiMenu(unit);
|
||||
}
|
||||
|
||||
void WorldSession::SendTaxiMenu(Creature* unit)
|
||||
{
|
||||
// find current node
|
||||
uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeamId());
|
||||
|
||||
if (curloc == 0)
|
||||
return;
|
||||
|
||||
bool lastTaxiCheaterState = GetPlayer()->isTaxiCheater();
|
||||
if (unit->GetEntry() == 29480) GetPlayer()->SetTaxiCheater(true); // Grimwing in Ebon Hold, special case. NOTE: Not perfect, Zul'Aman should not be included according to WoWhead, and I think taxicheat includes it.
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_TAXINODE_STATUS_QUERY %u ", curloc);
|
||||
#endif
|
||||
|
||||
WorldPacket data(SMSG_SHOWTAXINODES, (4 + 8 + 4 + 8 * 4));
|
||||
data << uint32(1);
|
||||
data << uint64(unit->GetGUID());
|
||||
data << uint32(curloc);
|
||||
GetPlayer()->m_taxi.AppendTaximaskTo(data, GetPlayer()->isTaxiCheater());
|
||||
SendPacket(&data);
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_SHOWTAXINODES");
|
||||
#endif
|
||||
|
||||
GetPlayer()->SetTaxiCheater(lastTaxiCheaterState);
|
||||
}
|
||||
|
||||
void WorldSession::SendDoFlight(uint32 mountDisplayId, uint32 path, uint32 pathNode)
|
||||
{
|
||||
// remove fake death
|
||||
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
|
||||
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
|
||||
|
||||
while (GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE)
|
||||
GetPlayer()->GetMotionMaster()->MovementExpired(false);
|
||||
|
||||
if (mountDisplayId)
|
||||
GetPlayer()->Mount(mountDisplayId);
|
||||
|
||||
GetPlayer()->GetMotionMaster()->MoveTaxiFlight(path, pathNode);
|
||||
}
|
||||
|
||||
bool WorldSession::SendLearnNewTaxiNode(Creature* unit)
|
||||
{
|
||||
// find current node
|
||||
uint32 curloc = sObjectMgr->GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId(), GetPlayer()->GetTeamId());
|
||||
|
||||
if (curloc == 0)
|
||||
return true; // `true` send to avoid WorldSession::SendTaxiMenu call with one more curlock seartch with same false result.
|
||||
|
||||
if (GetPlayer()->m_taxi.SetTaximaskNode(curloc))
|
||||
{
|
||||
WorldPacket msg(SMSG_NEW_TAXI_PATH, 0);
|
||||
SendPacket(&msg);
|
||||
|
||||
WorldPacket update(SMSG_TAXINODE_STATUS, 9);
|
||||
update << uint64(unit->GetGUID());
|
||||
update << uint8(1);
|
||||
SendPacket(&update);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void WorldSession::SendDiscoverNewTaxiNode(uint32 nodeid)
|
||||
{
|
||||
if (GetPlayer()->m_taxi.SetTaximaskNode(nodeid))
|
||||
{
|
||||
WorldPacket msg(SMSG_NEW_TAXI_PATH, 0);
|
||||
SendPacket(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldSession::HandleActivateTaxiExpressOpcode (WorldPacket & recvData)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ACTIVATETAXIEXPRESS");
|
||||
#endif
|
||||
|
||||
uint64 guid;
|
||||
uint32 node_count;
|
||||
|
||||
recvData >> guid >> node_count;
|
||||
|
||||
Creature* npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
|
||||
if (!npc)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandleActivateTaxiExpressOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
std::vector<uint32> nodes;
|
||||
|
||||
for (uint32 i = 0; i < node_count; ++i)
|
||||
{
|
||||
uint32 node;
|
||||
recvData >> node;
|
||||
|
||||
if (!GetPlayer()->m_taxi.IsTaximaskNodeKnown(node) && !GetPlayer()->isTaxiCheater())
|
||||
{
|
||||
SendActivateTaxiReply(ERR_TAXINOTVISITED);
|
||||
recvData.rfinish();
|
||||
return;
|
||||
}
|
||||
|
||||
nodes.push_back(node);
|
||||
}
|
||||
|
||||
if (nodes.empty())
|
||||
return;
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ACTIVATETAXIEXPRESS from %d to %d", nodes.front(), nodes.back());
|
||||
#endif
|
||||
|
||||
GetPlayer()->ActivateTaxiPathTo(nodes, npc, 0);
|
||||
}
|
||||
|
||||
void WorldSession::HandleMoveSplineDoneOpcode(WorldPacket& recvData)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_MOVE_SPLINE_DONE");
|
||||
#endif
|
||||
|
||||
uint64 guid; // used only for proper packet read
|
||||
recvData.readPackGUID(guid);
|
||||
|
||||
MovementInfo movementInfo; // used only for proper packet read
|
||||
movementInfo.guid = guid;
|
||||
ReadMovementInfo(recvData, &movementInfo);
|
||||
|
||||
recvData.read_skip<uint32>(); // spline id
|
||||
}
|
||||
|
||||
void WorldSession::HandleActivateTaxiOpcode(WorldPacket & recvData)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ACTIVATETAXI");
|
||||
#endif
|
||||
|
||||
uint64 guid;
|
||||
std::vector<uint32> nodes;
|
||||
nodes.resize(2);
|
||||
|
||||
recvData >> guid >> nodes[0] >> nodes[1];
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_ACTIVATETAXI from %d to %d", nodes[0], nodes[1]);
|
||||
#endif
|
||||
Creature* npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
|
||||
if (!npc)
|
||||
{
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)));
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GetPlayer()->isTaxiCheater())
|
||||
{
|
||||
if (!GetPlayer()->m_taxi.IsTaximaskNodeKnown(nodes[0]) || !GetPlayer()->m_taxi.IsTaximaskNodeKnown(nodes[1]))
|
||||
{
|
||||
SendActivateTaxiReply(ERR_TAXINOTVISITED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
GetPlayer()->ActivateTaxiPathTo(nodes, npc, 0);
|
||||
}
|
||||
|
||||
void WorldSession::SendActivateTaxiReply(ActivateTaxiReply reply)
|
||||
{
|
||||
WorldPacket data(SMSG_ACTIVATETAXIREPLY, 4);
|
||||
data << uint32(reply);
|
||||
SendPacket(&data);
|
||||
|
||||
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
|
||||
sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_ACTIVATETAXIREPLY");
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user