mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
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:
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user