OregonCore  revision fb2a440-git
Your Favourite TBC server
TaxiHandler.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 "Common.h"
19 #include "Database/DatabaseEnv.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "Opcodes.h"
23 #include "Log.h"
24 #include "World.h"
25 #include "ObjectMgr.h"
26 #include "Player.h"
27 #include "Path.h"
29 
31 {
32  DEBUG_LOG("WORLD: Received CMSG_TAXINODE_STATUS_QUERY");
33 
34  uint64 guid;
35 
36  recv_data >> guid;
37  SendTaxiStatus(guid);
38 }
39 
41 {
42  // cheating checks
43  Creature* unit = GetPlayer()->GetMap()->GetCreature(guid);
44  if (!unit)
45  {
46  sLog.outDebug("WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)));
47  return;
48  }
49 
50  uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId());
51 
52  // not found nearest
53  if (curloc == 0)
54  return;
55 
56  DEBUG_LOG("WORLD: current location %u ", curloc);
57 
59  data << guid;
60  data << uint8(GetPlayer()->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0);
61  SendPacket(&data);
62  DEBUG_LOG("WORLD: Sent SMSG_TAXINODE_STATUS");
63 }
64 
66 {
67  DEBUG_LOG("WORLD: Received CMSG_TAXIQUERYAVAILABLENODES");
68 
69  uint64 guid;
70  recv_data >> guid;
71 
72  // cheating checks
74  if (!unit)
75  {
76  sLog.outDebug("WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
77  return;
78  }
79 
80  // remove fake death
81  if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
83 
84  // unknown taxi node case
85  if (SendLearnNewTaxiNode(unit))
86  return;
87 
88  // known taxi node case
89  SendTaxiMenu(unit);
90 }
91 
93 {
94  // find current node
95  uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId());
96 
97  if (curloc == 0)
98  return;
99 
100  DEBUG_LOG("WORLD: CMSG_TAXINODE_STATUS_QUERY %u ", curloc);
101 
102  WorldPacket data(SMSG_SHOWTAXINODES, (4 + 8 + 4 + 8 * 4));
103  data << uint32(1);
104  data << uint64(unit->GetGUID());
105  data << uint32(curloc);
106  GetPlayer()->m_taxi.AppendTaximaskTo(data, GetPlayer()->isTaxiCheater());
107  SendPacket(&data);
108 
109  DEBUG_LOG("WORLD: Sent SMSG_SHOWTAXINODES");
110 }
111 
112 void WorldSession::SendDoFlight(uint16 MountId, uint32 path, uint32 pathNode)
113 {
114  // remove fake death
115  if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
117 
118  while (GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE)
120  GetPlayer()->Mount(MountId);
121  GetPlayer()->GetMotionMaster()->MoveTaxiFlight(path, pathNode);
122 }
123 
125 {
126  // find current node
127  uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(), unit->GetPositionY(), unit->GetPositionZ(), unit->GetMapId());
128 
129  if (curloc == 0)
130  return true; // `true` send to avoid WorldSession::SendTaxiMenu call with one more curlock seartch with same false result.
131 
132  if (GetPlayer()->m_taxi.SetTaximaskNode(curloc))
133  {
135  SendPacket(&msg);
136 
138  update << uint64(unit->GetGUID());
139  update << uint8(1);
140  SendPacket(&update);
141 
142  return true;
143  }
144  else
145  return false;
146 }
147 
149 {
150  DEBUG_LOG("WORLD: Received CMSG_ACTIVATETAXIEXPRESS");
151 
152  uint64 guid;
153  uint32 node_count, _totalcost;
154 
155  recv_data >> guid >> _totalcost >> node_count;
156 
158  if (!npc)
159  {
160  sLog.outDebug("WORLD: HandleActivateTaxiFarOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)));
161  return;
162  }
163  std::vector<uint32> nodes;
164 
165  for (uint32 i = 0; i < node_count; ++i)
166  {
167  uint32 node;
168  recv_data >> node;
169  nodes.push_back(node);
170  }
171 
172  if (nodes.empty())
173  return;
174 
175  DEBUG_LOG("WORLD: Received CMSG_ACTIVATETAXIEXPRESS from %d to %d" , nodes.front(), nodes.back());
176 
177  GetPlayer()->ActivateTaxiPathTo(nodes, 0, npc);
178 }
179 
181 {
182  DEBUG_LOG("WORLD: Received CMSG_MOVE_SPLINE_DONE");
183 
184  MovementInfo movementInfo; // used only for proper packet read
185 
186  recv_data >> movementInfo;
187  recv_data >> Unused<uint32>(); // unk
188 
189  // in taxi flight packet received at the end of current path in far (multi-node) flight
190 
191  uint32 curDest = GetPlayer()->m_taxi.GetTaxiDestination();
192  if (!curDest)
193  return;
194 
195  uint32 destinationnode = GetPlayer()->m_taxi.NextTaxiDestination();
196  if (destinationnode > 0) // if more destinations to go
197  {
198  // current source node for next destination
199  uint32 sourcenode = GetPlayer()->m_taxi.GetTaxiSource();
200 
201  // Add to taximask middle hubs in taxicheat mode (to prevent having player with disabled taxicheat and not having back flight path)
202  if (GetPlayer()->isTaxiCheater())
203  {
204  if (GetPlayer()->m_taxi.SetTaximaskNode(sourcenode))
205  {
207  _player->GetSession()->SendPacket(&data);
208  }
209  }
210 
211  DEBUG_LOG("WORLD: Taxi has to go from %u to %u", sourcenode, destinationnode);
212 
213  uint16 MountId = sObjectMgr.GetTaxiMount(sourcenode, GetPlayer()->GetTeam());
214 
215  uint32 path, cost;
216  sObjectMgr.GetTaxiPath(sourcenode, destinationnode, path, cost);
217 
218  if (path && MountId)
219  SendDoFlight(MountId, path, 1); // skip start fly node
220  else
221  GetPlayer()->m_taxi.ClearTaxiDestinations(); // clear problematic path and next
222 
223  return;
224  }
225  else
226  {
227  GetPlayer()->m_taxi.ClearTaxiDestinations(); // not destinations, clear source node
228 
229  // has taxi flight just finished reset fall information to avoid receiving fall damage
230  GetPlayer()->SetFallInformation(0, movementInfo.GetPos()->GetPositionZ());
231  }
233 }
234 
236 {
237  DEBUG_LOG("WORLD: Received CMSG_ACTIVATETAXI");
238 
239  uint64 guid;
240  std::vector<uint32> nodes;
241  nodes.resize(2);
242 
243  recv_data >> guid >> nodes[0] >> nodes[1];
244  DEBUG_LOG("WORLD: Received CMSG_ACTIVATETAXI from %d to %d" , nodes[0], nodes[1]);
246  if (!npc)
247  {
248  sLog.outDebug("WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)));
249  return;
250  }
251 
252  GetPlayer()->ActivateTaxiPathTo(nodes, 0, npc);
253 }
254 
void MoveTaxiFlight(uint32 path, uint32 pathnode)
void HandleActivateTaxiOpcode(WorldPacket &recvPacket)
void HandleTaxiNextDestinationOpcode(WorldPacket &recvPacket)
bool ActivateTaxiPathTo(std::vector< uint32 > const &nodes, uint32 mount_id=0, Creature *npc=NULL)
Definition: Player.cpp:17734
void SendTaxiMenu(Creature *unit)
Definition: TaxiHandler.cpp:92
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
void Mount(uint32 mount, uint32 spellId=0)
Definition: Unit.cpp:9270
PlayerTaxi m_taxi
Definition: Player.h:990
uint32 NextTaxiDestination()
Definition: Player.h:874
bool SetTaximaskNode(uint32 nodeidx)
Definition: Player.h:839
Map * GetMap() const
Definition: Object.h:841
void AppendTaximaskTo(ByteBuffer &data, bool all)
Definition: Player.cpp:179
uint32 GetTaxiSource() const
Definition: Player.h:865
bool SendLearnNewTaxiNode(Creature *unit)
MotionMaster * GetMotionMaster()
Definition: Unit.h:1890
void RemoveSpellsCausingAura(AuraType auraType)
Definition: Unit.cpp:697
#define sLog
Log class singleton.
Definition: Log.h:187
void SendDoFlight(uint16 MountId, uint32 path, uint32 pathNode=0)
Player * GetPlayer() const
Definition: WorldSession.h:104
void HandleTaxiQueryAvailableNodesOpcode(WorldPacket &recvPacket)
Definition: TaxiHandler.cpp:65
#define sObjectMgr
Definition: ObjectMgr.h:1285
void SendPacket(WorldPacket const *packet)
void ClearTaxiDestinations()
Definition: Player.h:857
Creature * GetCreature(uint64 guid)
Definition: Map.cpp:2630
ACE_UINT8 uint8
Definition: Define.h:73
void HandleTaxiNodeStatusQueryOpcode(WorldPacket &recvPacket)
Definition: TaxiHandler.cpp:30
uint32 GetTaxiDestination() const
Definition: Player.h:869
float GetPositionY() const
Definition: Position.h:98
float GetPositionZ() const
Definition: Position.h:99
#define DEBUG_LOG(...)
Definition: Log.h:194
uint32 GetMapId() const
Definition: Object.h:591
void CleanupAfterTaxiFlight()
Definition: Player.cpp:17910
ACE_UINT64 uint64
Definition: Define.h:70
Player * _player
Definition: WorldSession.h:730
void SendTaxiStatus(uint64 guid)
Definition: TaxiHandler.cpp:40
Creature * GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
Definition: Player.cpp:2130
void SetFallInformation(uint32 time, float z)
Definition: Player.h:2352
WorldSession * GetSession() const
Definition: Player.h:1944
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
float GetPositionX() const
Definition: Position.h:97
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:158
void HandleActivateTaxiFarOpcode(WorldPacket &recvPacket)
const uint64 & GetGUID() const
Definition: Object.h:162