2 * Copyright (C) 2005-2008 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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
26 #include "ObjectMgr.h"
28 #include "UpdateMask.h"
30 #include "WaypointMovementGenerator.h"
31 #include "DestinationHolderImp.h"
35 void WorldSession::HandleTaxiNodeStatusQueryOpcode( WorldPacket
& recv_data
)
37 CHECK_PACKET_SIZE(recv_data
,8);
39 sLog
.outDebug( "WORLD: Received CMSG_TAXINODE_STATUS_QUERY" );
44 SendTaxiStatus( guid
);
47 void WorldSession::SendTaxiStatus( uint64 guid
)
50 Creature
*unit
= ObjectAccessor::GetCreature(*_player
, guid
);
53 sLog
.outDebug( "WorldSession::SendTaxiStatus - Unit (GUID: %u) not found.", uint32(GUID_LOPART(guid
)) );
57 uint32 curloc
= objmgr
.GetNearestTaxiNode(unit
->GetPositionX(),unit
->GetPositionY(),unit
->GetPositionZ(),unit
->GetMapId());
63 sLog
.outDebug( "WORLD: current location %u ",curloc
);
65 WorldPacket
data( SMSG_TAXINODE_STATUS
, 9 );
67 data
<< uint8( GetPlayer( )->m_taxi
.IsTaximaskNodeKnown(curloc
) ? 1 : 0 );
69 sLog
.outDebug( "WORLD: Sent SMSG_TAXINODE_STATUS" );
72 void WorldSession::HandleTaxiQueryAvailableNodesOpcode( WorldPacket
& recv_data
)
74 CHECK_PACKET_SIZE(recv_data
,8);
76 sLog
.outDebug( "WORLD: Received CMSG_TAXIQUERYAVAILABLENODES" );
82 Creature
*unit
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_FLIGHTMASTER
);
85 sLog
.outDebug( "WORLD: HandleTaxiQueryAvailableNodesOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid
)) );
90 if(GetPlayer()->hasUnitState(UNIT_STAT_DIED
))
91 GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
93 // unknown taxi node case
94 if( SendLearnNewTaxiNode(unit
) )
97 // known taxi node case
101 void WorldSession::SendTaxiMenu( Creature
* unit
)
104 uint32 curloc
= objmgr
.GetNearestTaxiNode(unit
->GetPositionX(),unit
->GetPositionY(),unit
->GetPositionZ(),unit
->GetMapId());
109 sLog
.outDebug( "WORLD: CMSG_TAXINODE_STATUS_QUERY %u ",curloc
);
111 WorldPacket
data( SMSG_SHOWTAXINODES
, (4+8+4+8*4) );
113 data
<< uint64( unit
->GetGUID() );
114 data
<< uint32( curloc
);
115 GetPlayer()->m_taxi
.AppendTaximaskTo(data
,GetPlayer()->isTaxiCheater());
118 sLog
.outDebug( "WORLD: Sent SMSG_SHOWTAXINODES" );
121 void WorldSession::SendDoFlight( uint16 MountId
, uint32 path
, uint32 pathNode
)
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
)
137 uint32 curloc
= objmgr
.GetNearestTaxiNode(unit
->GetPositionX(),unit
->GetPositionY(),unit
->GetPositionZ(),unit
->GetMapId());
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);
147 WorldPacket
update( SMSG_TAXINODE_STATUS
, 9 );
148 update
<< uint64( unit
->GetGUID() );
149 update
<< uint8( 1 );
150 SendPacket( &update
);
158 void WorldSession::HandleActivateTaxiFarOpcode ( WorldPacket
& recv_data
)
160 CHECK_PACKET_SIZE(recv_data
,8+4+4);
162 sLog
.outDebug( "WORLD: Received CMSG_ACTIVATETAXIEXPRESS" );
165 uint32 node_count
, _totalcost
;
167 recv_data
>> guid
>> _totalcost
>> node_count
;
169 Creature
*npc
= ObjectAccessor::GetNPCIfCanInteractWith(*_player
, guid
, UNIT_NPC_FLAG_FLIGHTMASTER
);
172 sLog
.outDebug( "WORLD: HandleActivateTaxiFarOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid
)) );
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
)
184 nodes
.push_back(node
);
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();
207 TaxiNodesEntry
const* curDestNode
= sTaxiNodesStore
.LookupEntry(curDest
);
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());
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());
247 objmgr
.GetTaxiPath( sourcenode
, destinationnode
, path
, cost
);
250 SendDoFlight( MountId
, path
, 1 ); // skip start fly node
252 GetPlayer()->m_taxi
.ClearTaxiDestinations(); // clear problematic path and next
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" );
265 std::vector
<uint32
> nodes
;
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
);
273 sLog
.outDebug( "WORLD: HandleActivateTaxiOpcode - Unit (GUID: %u) not found or you can't interact with it.", uint32(GUID_LOPART(guid
)) );
277 GetPlayer()->ActivateTaxiPathTo(nodes
, 0, npc
);