Just a few renames.
[getmangos.git] / src / game / TaxiHandler.cpp
blobd493ef0641b5cf5b556941cdbad2fec91c0fc88b
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 "ObjectMgr.h"
26 #include "Player.h"
27 #include "UpdateMask.h"
28 #include "Path.h"
29 #include "WaypointMovementGenerator.h"
30 #include "DestinationHolderImp.h"
32 #include <cassert>
34 void WorldSession::HandleTaxiNodeStatusQueryOpcode( WorldPacket & recv_data )
36 CHECK_PACKET_SIZE(recv_data,8);
38 sLog.outDebug( "WORLD: Received CMSG_TAXINODE_STATUS_QUERY" );
40 uint64 guid;
42 recv_data >> guid;
43 SendTaxiStatus( guid );
46 void WorldSession::SendTaxiStatus( uint64 guid )
48 // cheating checks
49 Creature *unit = GetPlayer()->GetMap()->GetCreature(guid);
50 if (!unit)
52 sLog.outDebug( "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)) );
53 return;
56 uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
58 // not found nearest
59 if(curloc == 0)
60 return;
62 sLog.outDebug( "WORLD: current location %u ",curloc);
64 WorldPacket data( SMSG_TAXINODE_STATUS, 9 );
65 data << guid;
66 data << uint8( GetPlayer( )->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0 );
67 SendPacket( &data );
68 sLog.outDebug( "WORLD: Sent SMSG_TAXINODE_STATUS" );
71 void WorldSession::HandleTaxiQueryAvailableNodes( WorldPacket & recv_data )
73 CHECK_PACKET_SIZE(recv_data,8);
75 sLog.outDebug( "WORLD: Received CMSG_TAXIQUERYAVAILABLENODES" );
77 uint64 guid;
78 recv_data >> guid;
80 // cheating checks
81 Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
82 if (!unit)
84 sLog.outDebug( "WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
85 return;
88 // remove fake death
89 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
90 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
92 // unknown taxi node case
93 if( SendLearnNewTaxiNode(unit) )
94 return;
96 // known taxi node case
97 SendTaxiMenu( unit );
100 void WorldSession::SendTaxiMenu( Creature* unit )
102 // find current node
103 uint32 curloc = objmgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
105 if ( curloc == 0 )
106 return;
108 sLog.outDebug( "WORLD: CMSG_TAXINODE_STATUS_QUERY %u ",curloc);
110 WorldPacket data( SMSG_SHOWTAXINODES, (4+8+4+8*4) );
111 data << uint32( 1 );
112 data << uint64( unit->GetGUID() );
113 data << uint32( curloc );
114 GetPlayer()->m_taxi.AppendTaximaskTo(data,GetPlayer()->isTaxiCheater());
115 SendPacket( &data );
117 sLog.outDebug( "WORLD: Sent SMSG_SHOWTAXINODES" );
120 void WorldSession::SendDoFlight( uint16 MountId, uint32 path, uint32 pathNode )
122 // remove fake death
123 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
124 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
126 while(GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType()==FLIGHT_MOTION_TYPE)
127 GetPlayer()->GetMotionMaster()->MovementExpired(false);
129 if (MountId)
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::HandleActivateTaxiExpressOpcode ( 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 = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
170 if (!npc)
172 sLog.outDebug( "WORLD: HandleActivateTaxiExpressOpcode - 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, npc);
195 void WorldSession::HandleMoveSplineDoneOpcode(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 = GetPlayer()->GetNPCIfCanInteractWith(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, npc);