/* This function handles the packet from the client which is sent when we click on an npc with the flag UNIT_FLAG_SPELLCLICK and checks if there is room for us then adds us as a passenger to that vehicle*/ void WorldSession::HandleSpellClick( WorldPacket & recv_data ) { if (GetPlayer() == NULL || GetPlayer()->m_CurrentVehicle) return; CHECK_PACKET_SIZE(recv_data, 8); uint64 guid; recv_data >> guid; Vehicle* pVehicle = NULL; Unit* unit = GetPlayer()->GetMapMgr()->GetUnit(guid); Unit* pPlayer = TO_UNIT(GetPlayer()); if(!unit) return; if(!unit->IsVehicle()) { if(unit->IsCreature()) { Creature* ctr = TO_CREATURE(unit); if(ctr->GetProto()->SpellClickid) ctr->CastSpell(pPlayer, ctr->GetProto()->SpellClickid, true); else OUT_DEBUG("[SPELL][CLICK]: Unknown spell click spell on creature %u", ctr->GetEntry()); } return; } else { pVehicle = TO_VEHICLE(unit); } if(!pVehicle->GetMaxPassengerCount()) return; if(!pVehicle->GetMaxSeat()) return; // just in case. if( sEventMgr.HasEvent( pVehicle, EVENT_VEHICLE_SAFE_DELETE ) ) return; if(pVehicle->HasPassenger(pPlayer)) pVehicle->RemovePassenger(pPlayer); pVehicle->AddPassenger(pPlayer); }
bool ChatHandler::HandleVehiclePossess(const char * args, WorldSession * m_session) { Creature * creature = this->getSelectedCreature(m_session); if (!creature || !creature->IsVehicle()) { SystemMessage(m_session, "Select a vehicle first"); return true; } Vehicle * vehicle = (Vehicle *)creature; Player * player = m_session->GetPlayer(); vehicle->AddPassenger(player); player->Possess(vehicle); GreenSystemMessage(m_session, "Possessing Selected Vehicle..."); return true; }