[9232] Replace list bool fields with exclusive true values by subtype field in Creature.
[getmangos.git] / src / game / TaxiHandler.cpp
blob034d23c5cebef2f998e56a7d4b65b91b87b97720
1 /*
2 * Copyright (C) 2005-2010 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 void WorldSession::HandleTaxiNodeStatusQueryOpcode( WorldPacket & recv_data )
34 sLog.outDebug( "WORLD: Received CMSG_TAXINODE_STATUS_QUERY" );
36 uint64 guid;
38 recv_data >> guid;
39 SendTaxiStatus( guid );
42 void WorldSession::SendTaxiStatus( uint64 guid )
44 // cheating checks
45 Creature *unit = GetPlayer()->GetMap()->GetCreature(guid);
46 if (!unit)
48 sLog.outDebug( "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid)) );
49 return;
52 uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
54 // not found nearest
55 if(curloc == 0)
56 return;
58 sLog.outDebug( "WORLD: current location %u ",curloc);
60 WorldPacket data( SMSG_TAXINODE_STATUS, 9 );
61 data << guid;
62 data << uint8( GetPlayer( )->m_taxi.IsTaximaskNodeKnown(curloc) ? 1 : 0 );
63 SendPacket( &data );
64 sLog.outDebug( "WORLD: Sent SMSG_TAXINODE_STATUS" );
67 void WorldSession::HandleTaxiQueryAvailableNodes( WorldPacket & recv_data )
69 sLog.outDebug( "WORLD: Received CMSG_TAXIQUERYAVAILABLENODES" );
71 uint64 guid;
72 recv_data >> guid;
74 // cheating checks
75 Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
76 if (!unit)
78 sLog.outDebug( "WORLD: HandleTaxiQueryAvailableNodes - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) );
79 return;
82 // remove fake death
83 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED))
84 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
86 // unknown taxi node case
87 if( SendLearnNewTaxiNode(unit) )
88 return;
90 // known taxi node case
91 SendTaxiMenu( unit );
94 void WorldSession::SendTaxiMenu( Creature* unit )
96 // find current node
97 uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
99 if ( curloc == 0 )
100 return;
102 sLog.outDebug( "WORLD: CMSG_TAXINODE_STATUS_QUERY %u ",curloc);
104 WorldPacket data( SMSG_SHOWTAXINODES, (4+8+4+8*4) );
105 data << uint32( 1 );
106 data << uint64( unit->GetGUID() );
107 data << uint32( curloc );
108 GetPlayer()->m_taxi.AppendTaximaskTo(data,GetPlayer()->isTaxiCheater());
109 SendPacket( &data );
111 sLog.outDebug( "WORLD: Sent SMSG_SHOWTAXINODES" );
114 void WorldSession::SendDoFlight( uint32 mountDisplayId, uint32 path, uint32 pathNode )
116 // remove fake death
117 if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
118 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH);
120 while(GetPlayer()->GetMotionMaster()->GetCurrentMovementGeneratorType()==FLIGHT_MOTION_TYPE)
121 GetPlayer()->GetMotionMaster()->MovementExpired(false);
123 if (mountDisplayId)
124 GetPlayer()->Mount( mountDisplayId );
126 GetPlayer()->GetMotionMaster()->MoveTaxiFlight(path,pathNode);
129 bool WorldSession::SendLearnNewTaxiNode( Creature* unit )
131 // find current node
132 uint32 curloc = sObjectMgr.GetNearestTaxiNode(unit->GetPositionX(),unit->GetPositionY(),unit->GetPositionZ(),unit->GetMapId(),GetPlayer( )->GetTeam());
134 if ( curloc == 0 )
135 return true; // `true` send to avoid WorldSession::SendTaxiMenu call with one more curlock seartch with same false result.
137 if( GetPlayer()->m_taxi.SetTaximaskNode(curloc) )
139 WorldPacket msg(SMSG_NEW_TAXI_PATH, 0);
140 SendPacket( &msg );
142 WorldPacket update( SMSG_TAXINODE_STATUS, 9 );
143 update << uint64( unit->GetGUID() );
144 update << uint8( 1 );
145 SendPacket( &update );
147 return true;
149 else
150 return false;
153 void WorldSession::HandleActivateTaxiExpressOpcode ( WorldPacket & recv_data )
155 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXIEXPRESS" );
157 uint64 guid;
158 uint32 node_count;
160 recv_data >> guid >> node_count;
162 Creature *npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
163 if (!npc)
165 sLog.outDebug( "WORLD: HandleActivateTaxiExpressOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) );
166 return;
168 std::vector<uint32> nodes;
170 for(uint32 i = 0; i < node_count; ++i)
172 uint32 node;
173 recv_data >> node;
174 nodes.push_back(node);
177 if(nodes.empty())
178 return;
180 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXIEXPRESS from %d to %d" ,nodes.front(),nodes.back());
182 GetPlayer()->ActivateTaxiPathTo(nodes, npc);
185 void WorldSession::HandleMoveSplineDoneOpcode(WorldPacket& recv_data)
187 sLog.outDebug( "WORLD: Received CMSG_MOVE_SPLINE_DONE" );
189 uint64 guid; // used only for proper packet read
190 if(!recv_data.readPackGUID(guid))
191 return;
193 MovementInfo movementInfo; // used only for proper packet read
194 ReadMovementInfo(recv_data, &movementInfo);
196 recv_data.read_skip<uint32>(); // unk
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 uint32 mountDisplayId = sObjectMgr.GetTaxiMountDisplayId(sourcenode, GetPlayer()->GetTeam());
246 uint32 path, cost;
247 sObjectMgr.GetTaxiPath( sourcenode, destinationnode, path, cost);
249 if(path && mountDisplayId)
250 SendDoFlight( mountDisplayId, 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 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXI" );
262 uint64 guid;
263 std::vector<uint32> nodes;
264 nodes.resize(2);
266 recv_data >> guid >> nodes[0] >> nodes[1];
267 sLog.outDebug( "WORLD: Received CMSG_ACTIVATETAXI from %d to %d" ,nodes[0],nodes[1]);
268 Creature *npc = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_FLIGHTMASTER);
269 if (!npc)
271 sLog.outDebug( "WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid)) );
272 return;
275 GetPlayer()->ActivateTaxiPathTo(nodes, npc);