Skip to content

Commit

Permalink
GameObject: Fix sitting on chairs on a transport
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Nov 1, 2023
1 parent d28db40 commit a6fca96
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/game/Entities/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2930,29 +2930,30 @@ SpellEntry const* GameObject::GetSpellForLock(Player const* player) const

std::pair<float, float> GameObject::GetClosestChairSlotPosition(Unit* user) const
{
Position pos = GetPosition(GetTransport());
float outX, outY;
// check if the db is sane
if (GetGOInfo()->chair.slots > 0)
{
float lowestDist = DEFAULT_VISIBILITY_DISTANCE;

float x_lowest = GetPositionX();
float y_lowest = GetPositionY();
float x_lowest = pos.GetPositionX();
float y_lowest = pos.GetPositionY();

// the object orientation + 1/2 pi
// every slot will be on that straight line
float orthogonalOrientation = GetOrientation() + M_PI_F * 0.5f;
float orthogonalOrientation = pos.GetPositionO() + M_PI_F * 0.5f;
// find nearest slot
for (uint32 i = 0; i < GetGOInfo()->chair.slots; ++i)
{
// the distance between this slot and the center of the go - imagine a 1D space
float relativeDistance = (GetGOInfo()->size * i) - (GetGOInfo()->size * (GetGOInfo()->chair.slots - 1) / 2.0f);

float slotX = GetPositionX() + relativeDistance * cos(orthogonalOrientation);
float slotY = GetPositionY() + relativeDistance * sin(orthogonalOrientation);
float slotX = pos.GetPositionX() + relativeDistance * cos(orthogonalOrientation);
float slotY = pos.GetPositionY() + relativeDistance * sin(orthogonalOrientation);

// calculate the distance between the user and this slot
float thisDistance = user->GetDistance2d(slotX, slotY, DIST_CALC_NONE);
float thisDistance = user->GetDistance2d(slotX, slotY, DIST_CALC_NONE, GetTransport());

if (thisDistance <= lowestDist)
{
Expand All @@ -2966,8 +2967,8 @@ std::pair<float, float> GameObject::GetClosestChairSlotPosition(Unit* user) cons
}
else
{
outX = GetPositionX();
outY = GetPositionY();
outX = pos.GetPositionX();
outY = pos.GetPositionY();
}

return {outX, outY};
Expand Down
7 changes: 4 additions & 3 deletions src/game/Entities/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1471,10 +1471,11 @@ float WorldObject::GetDistance(float x, float y, float z, DistanceCalculation di
}
}

float WorldObject::GetDistance2d(float x, float y, DistanceCalculation distcalc) const
float WorldObject::GetDistance2d(float x, float y, DistanceCalculation distcalc, bool transport) const
{
float dx = GetPositionX() - x;
float dy = GetPositionY() - y;
Position const& pos = GetPosition(transport ? GetTransport() : nullptr);
float dx = pos.x - x;
float dy = pos.y - y;
float dist = dx * dx + dy * dy;

switch (distcalc)
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ class WorldObject : public Object

float GetDistance(const WorldObject* obj, bool is3D = true, DistanceCalculation distcalc = DIST_CALC_BOUNDING_RADIUS) const;
float GetDistance(float x, float y, float z, DistanceCalculation distcalc = DIST_CALC_BOUNDING_RADIUS, bool transport = false) const;
float GetDistance2d(float x, float y, DistanceCalculation distcalc = DIST_CALC_BOUNDING_RADIUS) const;
float GetDistance2d(float x, float y, DistanceCalculation distcalc = DIST_CALC_BOUNDING_RADIUS, bool transport = false) const;
float GetDistanceZ(const WorldObject* obj) const;
bool IsInMapIgnorePhase(const WorldObject* obj) const // only to be used by spells which ignore phase during search and similar
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/Entities/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11796,7 +11796,7 @@ void Unit::NearTeleportTo(float x, float y, float z, float orientation, bool cas
uint32 options = (transportLeave ? 0 : TELE_TO_NOT_LEAVE_TRANSPORT) | (casting ? TELE_TO_SPELL : 0);
if (GetDistance(x, y, z, DIST_CALC_NONE) < 100.f * 100.f)
options |= TELE_TO_NOT_LEAVE_COMBAT;
static_cast<Player*>(this)->TeleportTo(GetMapId(), x, y, z, orientation, options);
static_cast<Player*>(this)->TeleportTo(GetMapId(), x, y, z, orientation, options, nullptr, !transportLeave ? GetTransport() : nullptr);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/Spells/SpellHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ void WorldSession::HandleGameObjectUseOpcode(WorldPacket& recv_data)
{
float x, y;
std::tie(x, y) = obj->GetClosestChairSlotPosition(_player);
if (_player->GetDistance(x, y, obj->GetPositionZ(), DIST_CALC_NONE) > 3.f * 3.f)
if (_player->GetDistance(x, y, obj->GetPositionZ(), DIST_CALC_NONE, obj->GetTransport()) > 3.f * 3.f)
return;
}

Expand Down

1 comment on commit a6fca96

@al3xc1985
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we have the only core that has this implemented

Please sign in to comment.