[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / TaxiHandler.cpp
blobb8aa614dbb44aa27fb6d752cedb19b0f4b9a4a30
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "Opcodes.h"
24 #include "Log.h"
25 #include "World.h"
26 #include "ObjectMgr.h"
27 #include "Player.h"
28 #include "UpdateMask.h"
29 #include "Path.h"
30 #include "WaypointMovementGenerator.h"
31 #include "DestinationHolderImp.h"
33 #include <cassert>
35 void WorldSession::HandleTaxiNodeStatusQueryOpcode( WorldPacket & recv_data )
37 CHECK_PACKET_SIZE(recv_data,8);
39 sLog.outDebug( "WORLD: Received CMSG_TAXINODE_STATUS_QUERY" );
41 uint64 guid;
43 recv_data >> guid;
44 SendTaxiStatus( guid );
47 void WorldSession::SendTaxiStatus( uint64 guid )
49 // cheating checks
50 Creature *unit = ObjectAccessor::GetCreature(*_player, guid);
51 if (!unit)
53 sLog.outDebug( "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)) );
54 return;
57 uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
59 // not found nearest
60 if(curloc == 0)
61 return;
63 sLog.outDebug( "WORLD: current location %u ",curloc);
65 WorldPacket data( SMSG_TAXINODE_STATUS, 9 );
66 data << guid;
67 data << uint8( GetPlayer( )->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0 );
68 SendPacket( &data );
69 sLog.outDebug( "WORLD: Sent SMSG_TAXINODE_STATUS" );
72 void WorldSession::HandleTaxiQueryAvailableNodes( WorldPacket & recv_data )
74 CHECK_PACKET_SIZE(recv_data,8);
76 sLog.outDebug( "WORLD: Received CMSG_TAXIQUERYAVAILABLENODES" );
78 uint64 guid;
79 recv_data >> guid;
81 // cheating checks
82 Creature *unit = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER);
83 if (!unit)
85 sLog.outDebug( "WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
86 return;
89 // remove fake death
90 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
91 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
93 // unknown taxi node case
94 if( SendLearnNewTaxiNode(unit) )
95 return;
97 // known taxi node case
98 SendTaxiMenu( unit );
101 void WorldSession::SendTaxiMenu( Creature* unit )
103 // find current node
104 uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
106 if ( curloc == 0 )
107 return;
109 sLog.outDebug( "WORLD: CMSG_TAXINODE_STATUS_QUERY %u ",curloc);
111 WorldPacket data( SMSG_SHOWTAXINODES, (4+8+4+8*4) );
112 data << uint32( 1 );
113 data << uint64( unit->GetGUID() );
114 data << uint32( curloc );
115 GetPlayer()->m_taxi.AppendTaximaskTo(data,GetPlayer()->isTaxiCheater());
116 SendPacket( &data );
118 sLog.outDebug( "WORLD: Sent SMSG_SHOWTAXINODES" );
121 void WorldSession::SendDoFlight( uint16 MountId, uint32 path, uint32 pathNode )
123 // remove fake death
124 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
125 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
127 while(GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType()==FLIGHT_MOTION_TYPE)
128 GetPlayer()->GetMotionMaster()->MovementExpired(false);
130 GetPlayer()->Mount( MountId );
131 GetPlayer()->GetMotionMaster()->MoveTaxiFlight(path,pathNode);
134 bool WorldSession::SendLearnNewTaxiNode( Creature* unit )
136 // find current node
137 uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
139 if ( curloc == 0 )
140 return true; // `true` send to avoid WorldSession::SendTaxiMenu call with one more curlock seartch with same false result.
142 if( GetPlayer()->m_taxi.SetTaximaskNode(curloc) )
144 WorldPacket msg(SMSG_NEW_TAXI_PATH, 0);
145 SendPacket( &msg );
147 WorldPacket update( SMSG_TAXINODE_STATUS, 9 );
148 update << uint64( unit->GetGUID() );
149 update << uint8( 1 );
150 SendPacket( &update );
152 return true;
154 else
155 return false;
158 void WorldSession::HandleActivateTaxiFarOpcode ( WorldPacket & recv_data )
160 CHECK_PACKET_SIZE(recv_data,8+4+4);
162 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXIEXPRESS" );
164 uint64 guid;
165 uint32 node_count, _totalcost;
167 recv_data >> guid >> _totalcost >> node_count;
169 Creature *npc = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER);
170 if (!npc)
172 sLog.outDebug( "WORLD: HandleActivateTaxiFarOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) );
173 return;
175 // recheck
176 CHECK_PACKET_SIZE(recv_data,8+4+4+node_count*4);
178 std::vector<uint32> nodes;
180 for(uint32 i = 0; i < node_count; ++i)
182 uint32 node;
183 recv_data >> node;
184 nodes.push_back(node);
187 if(nodes.empty())
188 return;
190 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXIEXPRESS from %d to %d" ,nodes.front(),nodes.back());
192 GetPlayer()->ActivateTaxiPathTo(nodes, 0, npc);
195 void WorldSession::HandleTaxiNextDestinationOpcode(WorldPacket& /*recv_data*/)
197 sLog.outDebug( "WORLD: Received CMSG_MOVE_SPLINE_DONE" );
199 // in taxi flight packet received in 2 case:
200 // 1) end taxi path in far (multi-node) flight
201 // 2) switch from one map to other in case multim-map taxi path
202 // we need proccess only (1)
203 uint32 curDest = GetPlayer()->m_taxi.GetTaxiDestination();
204 if(!curDest)
205 return;
207 TaxiNodesEntry const* curDestNode = sTaxiNodesStore.LookupEntry(curDest);
209 // far teleport case
210 if(curDestNode && curDestNode->map_id != GetPlayer()->GetMapId())
212 if(GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType()==FLIGHT_MOTION_TYPE)
214 // short preparations to continue flight
215 FlightPathMovementGenerator* flight = (FlightPathMovementGenerator*)(GetPlayer()->GetMotionMaster()->top());
217 flight->SetCurrentNodeAfterTeleport();
218 Path::PathNode const& node = flight->GetPath()[flight->GetCurrentNode()];
219 flight->SkipCurrentNode();
221 GetPlayer()->TeleportTo(curDestNode->map_id,node.x,node.y,node.z,GetPlayer()->GetOrientation());
223 return;
226 uint32 destinationnode = GetPlayer()->m_taxi.NextTaxiDestination();
227 if ( destinationnode > 0 ) // if more destinations to go
229 // current source node for next destination
230 uint32 sourcenode = GetPlayer()->m_taxi.GetTaxiSource();
232 // Add to taximask middle hubs in taxicheat mode (to prevent having player with disabled taxicheat and not having back flight path)
233 if (GetPlayer()->isTaxiCheater())
235 if(GetPlayer()->m_taxi.SetTaximaskNode(sourcenode))
237 WorldPacket data(SMSG_NEW_TAXI_PATH, 0);
238 _player->GetSession()->SendPacket( &data );
242 sLog.outDebug( "WORLD: Taxi has to go from %u to %u", sourcenode, destinationnode );
244 uint16 MountId = objmgr.GetTaxiMount(sourcenode, GetPlayer()->GetTeam());
246 uint32 path, cost;
247 objmgr.GetTaxiPath( sourcenode, destinationnode, path, cost);
249 if(path && MountId)
250 SendDoFlight( MountId, path, 1 ); // skip start fly node
251 else
252 GetPlayer()->m_taxi.ClearTaxiDestinations(); // clear problematic path and next
254 else
255 GetPlayer()->m_taxi.ClearTaxiDestinations(); // not destinations, clear source node
258 void WorldSession::HandleActivateTaxiOpcode( WorldPacket & recv_data )
260 CHECK_PACKET_SIZE(recv_data,8+4+4);
262 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXI" );
264 uint64 guid;
265 std::vector<uint32> nodes;
266 nodes.resize(2);
268 recv_data >> guid >> nodes[0] >> nodes[1];
269 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXI from %d to %d" ,nodes[0],nodes[1]);
270 Creature *npc = ObjectAccessor::GetNPCIfCanInteractWith(*_player, guid, UNIT_NPC_FLAG_FLIGHTMASTER);
271 if (!npc)
273 sLog.outDebug( "WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) );
274 return;
277 GetPlayer()->ActivateTaxiPathTo(nodes, 0, npc);