Core/Vehicles: Handle vehicle seat switches through aura effects.

This commit is contained in:
Shauren committed 2013-06-04 16:28:30 +02:00
1 parent f03f443150
commit eed1286a8c
5 files changed
+37 -31

No files matched your search

+23 -26
View File
@@ -16816,29 +16816,23 @@ void Unit::EnterVehicle(Unit* base, int8 seatId)
void Unit::_EnterVehicle(Vehicle* vehicle, int8 seatId, AuraApplication const* aurApp)
{
// Must be called only from aura handler
ASSERT(aurApp);
if (!isAlive() || GetVehicleKit() == vehicle || vehicle->GetBase()->IsOnVehicle(this))
return;
if (m_vehicle)
{
if (m_vehicle == vehicle)
{
if (seatId >= 0 && seatId != GetTransSeat())
{
TC_LOG_DEBUG(LOG_FILTER_VEHICLES, "EnterVehicle: %u leave vehicle %u seat %d and enter %d.", GetEntry(), m_vehicle->GetBase()->GetEntry(), GetTransSeat(), seatId);
ChangeSeat(seatId);
}
return;
}
else
if (m_vehicle != vehicle)
{
TC_LOG_DEBUG(LOG_FILTER_VEHICLES, "EnterVehicle: %u exit %u and enter %u.", GetEntry(), m_vehicle->GetBase()->GetEntry(), vehicle->GetBase()->GetEntry());
ExitVehicle();
}
else if (seatId >= 0 && seatId == GetTransSeat())
return;
}
if (!aurApp || aurApp->GetRemoveMode())
if (aurApp->GetRemoveMode())
return;
if (Player* player = ToPlayer())
@@ -16868,16 +16862,22 @@ void Unit::ChangeSeat(int8 seatId, bool next)
if (seat == m_vehicle->Seats.end() || seat->second.Passenger)
return;
// Todo: the functions below could be consolidated and refactored to take
// SeatMap::const_iterator as parameter, to save redundant map lookups.
m_vehicle->RemovePassenger(this);
AuraEffect* rideVehicleEffect = NULL;
AuraEffectList const& vehicleAuras = m_vehicle->GetBase()->GetAuraEffectsByType(SPELL_AURA_CONTROL_VEHICLE);
for (AuraEffectList::const_iterator itr = vehicleAuras.begin(); itr != vehicleAuras.end(); ++itr)
{
if ((*itr)->GetCasterGUID() != GetGUID())
continue;
// Set m_vehicle to NULL before adding passenger as adding new passengers is handled asynchronously
// and someone may call ExitVehicle again before passenger is added to new seat
Vehicle* veh = m_vehicle;
m_vehicle = NULL;
if (!veh->AddPassenger(this, seatId))
ASSERT(false);
// Make sure there is only one ride vehicle aura on target cast by the unit changing seat
ASSERT(!rideVehicleEffect);
rideVehicleEffect = *itr;
}
// Unit riding a vehicle must always have control vehicle aura on target
ASSERT(rideVehicleEffect);
rideVehicleEffect->ChangeAmount(seat->first + 1);
}
void Unit::ExitVehicle(Position const* /*exitPosition*/)
@@ -16907,7 +16907,8 @@ void Unit::_ExitVehicle(Position const* exitPosition)
if (!m_vehicle)
return;
m_vehicle->RemovePassenger(this);
// This should be done before dismiss, because there may be some aura removal
Vehicle* vehicle = m_vehicle->RemovePassenger(this);
Player* player = ToPlayer();
@@ -16915,10 +16916,6 @@ void Unit::_ExitVehicle(Position const* exitPosition)
if (player && player->duel && player->duel->isMounted)
player->DuelComplete(DUEL_FLED);
// This should be done before dismiss, because there may be some aura removal
Vehicle* vehicle = m_vehicle;
m_vehicle = NULL;
SetControlled(false, UNIT_STATE_ROOT); // SMSG_MOVE_FORCE_UNROOT, ~MOVEMENTFLAG_ROOT
Position pos;