Skip to content

Commit a3ada79

Browse files
authored
Core/Movement: Make it possible to get exact player position in scripts triggered directly by player movement (TrinityCore#29824)
Examples: PlayerScript on death by falling, AuraScript remove by interrupt flags (turning on vehicle, landing)
1 parent bcc9a60 commit a3ada79

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

src/server/game/Entities/Player/Player.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24835,10 +24835,10 @@ void Player::SetFallInformation(uint32 time, float z)
2483524835
m_lastFallZ = z;
2483624836
}
2483724837

24838-
void Player::HandleFall(MovementInfo const& movementInfo)
24838+
void Player::HandleFall()
2483924839
{
2484024840
// calculate total z distance of the fall
24841-
float z_diff = m_lastFallZ - movementInfo.pos.GetPositionZ();
24841+
float z_diff = m_lastFallZ - m_movementInfo.pos.GetPositionZ();
2484224842
//TC_LOG_DEBUG("zDiff = {}", z_diff);
2484324843

2484424844
//Players with low fall distance, Feather Fall or physical immunity (charges used) are ignored
@@ -24859,8 +24859,8 @@ void Player::HandleFall(MovementInfo const& movementInfo)
2485924859
if (GetCommandStatus(CHEAT_GOD))
2486024860
damage = 0;
2486124861

24862-
float height = movementInfo.pos.m_positionZ;
24863-
UpdateGroundPositionZ(movementInfo.pos.m_positionX, movementInfo.pos.m_positionY, height);
24862+
float height = m_movementInfo.pos.m_positionZ;
24863+
UpdateGroundPositionZ(m_movementInfo.pos.m_positionX, m_movementInfo.pos.m_positionY, height);
2486424864

2486524865
if (damage > 0)
2486624866
{
@@ -24881,7 +24881,7 @@ void Player::HandleFall(MovementInfo const& movementInfo)
2488124881
}
2488224882

2488324883
//Z given by moveinfo, LastZ, FallTime, WaterZ, MapZ, Damage, Safefall reduction
24884-
TC_LOG_DEBUG("entities.player.falldamage", "FALLDAMAGE z={} sz={} pZ={} FallTime={} mZ={} damage={} SF={}\nPlayer debug info:\n{}", movementInfo.pos.GetPositionZ(), height, GetPositionZ(), movementInfo.fallTime, height, damage, safe_fall, GetDebugInfo());
24884+
TC_LOG_DEBUG("entities.player.falldamage", "FALLDAMAGE z={} sz={} pZ={} FallTime={} mZ={} damage={} SF={}\nPlayer debug info:\n{}", m_movementInfo.pos.GetPositionZ(), height, GetPositionZ(), m_movementInfo.fallTime, height, damage, safe_fall, GetDebugInfo());
2488524885
}
2488624886
}
2488724887
}

src/server/game/Entities/Player/Player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
20402040
// only changed for direct client control (possess, vehicle etc.), not stuff you control using pet commands
20412041
WorldObject* m_seer;
20422042
void SetFallInformation(uint32 time, float z);
2043-
void HandleFall(MovementInfo const& movementInfo);
2043+
void HandleFall();
20442044

20452045
bool CanFlyInZone(uint32 mapid, uint32 zone, SpellInfo const* bySpell) const;
20462046

src/server/game/Handlers/MovementHandler.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,14 +469,6 @@ void WorldSession::HandleMovementOpcode(OpcodeClient opcode, MovementInfo& movem
469469
movementInfo.transport.Reset();
470470
}
471471

472-
// fall damage generation (ignore in flight case that can be triggered also at lags in moment teleportation to another map).
473-
if (opcode == MSG_MOVE_FALL_LAND && plrMover && !plrMover->IsInFlight())
474-
plrMover->HandleFall(movementInfo);
475-
476-
// interrupt parachutes upon falling or landing in water
477-
if (opcode == MSG_MOVE_FALL_LAND || opcode == MSG_MOVE_START_SWIM)
478-
mover->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LANDING); // Parachutes
479-
480472
/* process position-change */
481473
movementInfo.guid = mover->GetGUID();
482474
movementInfo.time = AdjustClientMovementTime(movementInfo.time);
@@ -505,6 +497,14 @@ void WorldSession::HandleMovementOpcode(OpcodeClient opcode, MovementInfo& movem
505497

506498
mover->UpdatePosition(movementInfo.pos);
507499

500+
// fall damage generation (ignore in flight case that can be triggered also at lags in moment teleportation to another map).
501+
if (opcode == MSG_MOVE_FALL_LAND && plrMover && !plrMover->IsInFlight())
502+
plrMover->HandleFall();
503+
504+
// interrupt parachutes upon falling or landing in water
505+
if (opcode == MSG_MOVE_FALL_LAND || opcode == MSG_MOVE_START_SWIM)
506+
mover->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_LANDING); // Parachutes
507+
508508
if (plrMover) // nothing is charmed, or player charmed
509509
{
510510
if (plrMover->IsSitState() && (movementInfo.flags & (MOVEMENTFLAG_MASK_MOVING | MOVEMENTFLAG_MASK_TURNING)))

0 commit comments

Comments
 (0)