Core/Vehicle: Change vehicle accessories' phase according to the player on the vehicle (#23646)

* Core/Vehicle: Change vehicle accessories' phase according to the player on the vehicle

* Get the root vehicle to set the phase to all accessories. Attempt to get the accessories to stay mounted on the vehicle.

* Fix the accessories to stay mounted on the vehicle

(cherry picked from commit 15e85f882f)
This commit is contained in:
Giacomo Pozzoni
2019-08-04 11:33:29 +02:00
committed by Shauren
parent a90073dadd
commit 6d5086da17
3 changed files with 29 additions and 4 deletions

View File

@@ -11160,6 +11160,22 @@ Unit* Unit::GetVehicleBase() const
return m_vehicle ? m_vehicle->GetBase() : nullptr;
}
Unit* Unit::GetVehicleRoot() const
{
Unit* vehicleRoot = GetVehicleBase();
if (!vehicleRoot)
return nullptr;
for (;;)
{
if (!vehicleRoot->GetVehicleBase())
return vehicleRoot;
vehicleRoot = vehicleRoot->GetVehicleBase();
}
}
Creature* Unit::GetVehicleCreatureBase() const
{
if (Unit* veh = GetVehicleBase())

View File

@@ -1761,11 +1761,12 @@ class TC_GAME_API Unit : public WorldObject
ObjectGuid LastCharmerGUID;
bool CreateVehicleKit(uint32 id, uint32 creatureEntry, bool loading = false);
void RemoveVehicleKit(bool onRemoveFromWorld = false);
Vehicle* GetVehicleKit()const { return m_vehicleKit; }
Vehicle* GetVehicle() const { return m_vehicle; }
Vehicle* GetVehicleKit() const { return m_vehicleKit; }
Vehicle* GetVehicle() const { return m_vehicle; }
void SetVehicle(Vehicle* vehicle) { m_vehicle = vehicle; }
bool IsOnVehicle(Unit const* vehicle) const;
Unit* GetVehicleBase() const;
Unit* GetVehicleBase() const;
Unit* GetVehicleRoot() const;
Creature* GetVehicleCreatureBase() const;
ObjectGuid GetTransGUID() const override;
/// Returns the transport this unit is on directly (if on vehicle and transport, return vehicle)

View File

@@ -23,11 +23,13 @@
#include "Language.h"
#include "Map.h"
#include "MiscPackets.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "PartyPackets.h"
#include "PhaseShift.h"
#include "Player.h"
#include "SpellAuraEffects.h"
#include "Vehicle.h"
#include <sstream>
namespace
@@ -52,13 +54,19 @@ template<typename Func>
inline void ForAllControlled(Unit* unit, Func&& func)
{
for (Unit* controlled : unit->m_Controlled)
if (controlled->GetTypeId() != TYPEID_PLAYER)
if (controlled->GetTypeId() != TYPEID_PLAYER
&& !controlled->GetVehicle()) // Player inside nested vehicle should not phase the root vehicle and its accessories (only direct root vehicle control does)
func(controlled);
for (ObjectGuid summonGuid : unit->m_SummonSlot)
if (!summonGuid.IsEmpty())
if (Creature* summon = unit->GetMap()->GetCreature(summonGuid))
func(summon);
if (Vehicle const* vehicle = unit->GetVehicleKit())
for (auto seat = vehicle->Seats.begin(); seat != vehicle->Seats.end(); ++seat)
if (Unit* passenger = ObjectAccessor::GetUnit(*unit, seat->second.Passenger.Guid))
func(passenger);
}
}