diff options
| author | Shauren <shauren.trinity@gmail.com> | 2025-10-26 11:00:25 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2025-10-26 11:00:25 +0100 |
| commit | cc908c7eff3a6a01454100316662f2f271327dda (patch) | |
| tree | 5bea99e65f0f6a96906eea78f8a657f72d848ce5 /src | |
| parent | 858f8c12d7d97c5094347c753f1fc905135034f4 (diff) | |
Core/Units: Port movement status altering functions from master branch
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 122 | ||||
| -rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 8 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 90 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.h | 5 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 196 | ||||
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.h | 14 |
6 files changed, 188 insertions, 247 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index c91cdd11b51..cf2ee4acc5b 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2007,8 +2007,8 @@ void Creature::setDeathState(DeathState s) m_formation->FormationReset(true); bool needsFalling = (IsFlying() || IsHovering()) && !IsUnderWater(); - SetHover(false, false); - SetDisableGravity(false, false); + SetHover(false); + SetDisableGravity(false); if (needsFalling) GetMotionMaster()->MoveFall(); @@ -2932,124 +2932,6 @@ void Creature::SetCannotReachTarget(bool cannotReach) TC_LOG_DEBUG("entities.unit.chase", "Creature::SetCannotReachTarget() called with true. Details: {}", GetDebugInfo()); } -bool Creature::SetWalk(bool enable) -{ - if (!Unit::SetWalk(enable)) - return false; - - WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_WALK_MODE : SMSG_SPLINE_MOVE_SET_RUN_MODE, 9); - data << GetPackGUID(); - SendMessageToSet(&data, false); - return true; -} - -bool Creature::SetDisableGravity(bool disable, bool packetOnly /*=false*/, bool updateAnimTier /*= true*/) -{ - //! It's possible only a packet is sent but moveflags are not updated - //! Need more research on this - if (!packetOnly && !Unit::SetDisableGravity(disable, packetOnly, updateAnimTier)) - return false; - - if (updateAnimTier && IsAlive() && !HasUnitState(UNIT_STATE_ROOT) && !GetMovementTemplate().IsRooted()) - { - if (IsGravityDisabled()) - SetAnimTier(AnimTier::Fly); - else if (IsHovering()) - SetAnimTier(AnimTier::Hover); - else - SetAnimTier(AnimTier::Ground); - } - - if (!movespline->Initialized()) - return true; - - WorldPacket data(disable ? SMSG_SPLINE_MOVE_GRAVITY_DISABLE : SMSG_SPLINE_MOVE_GRAVITY_ENABLE, 9); - data << GetPackGUID(); - SendMessageToSet(&data, false); - return true; -} - -bool Creature::SetSwim(bool enable) -{ - if (!Unit::SetSwim(enable)) - return false; - - if (!movespline->Initialized()) - return true; - - WorldPacket data(enable ? SMSG_SPLINE_MOVE_START_SWIM : SMSG_SPLINE_MOVE_STOP_SWIM); - data << GetPackGUID(); - SendMessageToSet(&data, true); - return true; -} - -bool Creature::SetCanFly(bool enable, bool /*packetOnly = false */) -{ - if (!Unit::SetCanFly(enable)) - return false; - - if (!movespline->Initialized()) - return true; - - WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_FLYING : SMSG_SPLINE_MOVE_UNSET_FLYING, 9); - data << GetPackGUID(); - SendMessageToSet(&data, false); - return true; -} - -bool Creature::SetWaterWalking(bool enable, bool packetOnly /* = false */) -{ - if (!packetOnly && !Unit::SetWaterWalking(enable)) - return false; - - if (!movespline->Initialized()) - return true; - - WorldPacket data(enable ? SMSG_SPLINE_MOVE_WATER_WALK : SMSG_SPLINE_MOVE_LAND_WALK); - data << GetPackGUID(); - SendMessageToSet(&data, true); - return true; -} - -bool Creature::SetFeatherFall(bool enable, bool packetOnly /* = false */) -{ - if (!packetOnly && !Unit::SetFeatherFall(enable)) - return false; - - if (!movespline->Initialized()) - return true; - - WorldPacket data(enable ? SMSG_SPLINE_MOVE_FEATHER_FALL : SMSG_SPLINE_MOVE_NORMAL_FALL); - data << GetPackGUID(); - SendMessageToSet(&data, true); - return true; -} - -bool Creature::SetHover(bool enable, bool packetOnly /*= false*/, bool updateAnimTier /*= true*/) -{ - if (!packetOnly && !Unit::SetHover(enable, packetOnly, updateAnimTier)) - return false; - - if (updateAnimTier && IsAlive() && !HasUnitState(UNIT_STATE_ROOT) && !GetMovementTemplate().IsRooted()) - { - if (IsGravityDisabled()) - SetAnimTier(AnimTier::Fly); - else if (IsHovering()) - SetAnimTier(AnimTier::Hover); - else - SetAnimTier(AnimTier::Ground); - } - - if (!movespline->Initialized()) - return true; - - //! Not always a packet is sent - WorldPacket data(enable ? SMSG_SPLINE_MOVE_SET_HOVER : SMSG_SPLINE_MOVE_UNSET_HOVER, 9); - data << GetPackGUID(); - SendMessageToSet(&data, false); - return true; -} - float Creature::GetAggroRange(Unit const* target) const { // Determines the aggro range for creatures (usually pets), used mainly for aggressive pet target selection. diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 85823112dd4..e8c5a3e78e8 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -153,14 +153,6 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma CreatureAI* AI() const { return reinterpret_cast<CreatureAI*>(GetAI()); } - bool SetWalk(bool enable) override; - bool SetDisableGravity(bool disable, bool packetOnly = false, bool updateAnimTier = true) override; - bool SetSwim(bool enable) override; - bool SetCanFly(bool enable, bool packetOnly = false) override; - bool SetWaterWalking(bool enable, bool packetOnly = false) override; - bool SetFeatherFall(bool enable, bool packetOnly = false) override; - bool SetHover(bool enable, bool packetOnly = false, bool updateAnimTier = true) override; - uint32 GetShieldBlockValue() const override; SpellSchoolMask GetMeleeDamageSchoolMask(WeaponAttackType /*attackType*/ = BASE_ATTACK, uint8 /*damageIndex*/ = 0) const override { return m_meleeDamageSchoolMask; } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 456353f8019..afb6a1f7705 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -26380,96 +26380,6 @@ bool Player::IsInWhisperWhiteList(ObjectGuid guid) return false; } -bool Player::SetDisableGravity(bool disable, bool packetOnly /*= false*/, bool updateAnimTier /*= true*/) -{ - if (!packetOnly && !Unit::SetDisableGravity(disable, packetOnly, updateAnimTier)) - return false; - - WorldPacket data(disable ? SMSG_MOVE_GRAVITY_DISABLE : SMSG_MOVE_GRAVITY_ENABLE, 12); - data << GetPackGUID(); - data << uint32(0); //! movement counter - SendDirectMessage(&data); - - data.Initialize(MSG_MOVE_GRAVITY_CHNG, 64); - data << GetPackGUID(); - BuildMovementPacket(&data); - SendMessageToSet(&data, false); - return true; -} - -bool Player::SetCanFly(bool apply, bool packetOnly /*= false*/) -{ - if (!apply) - SetFallInformation(0, GetPositionZ()); - - WorldPacket data(apply ? SMSG_MOVE_SET_CAN_FLY : SMSG_MOVE_UNSET_CAN_FLY, 12); - data << GetPackGUID(); - data << uint32(0); //! movement counter - SendDirectMessage(&data); - - if (packetOnly || Unit::SetCanFly(apply)) - { - data.Initialize(MSG_MOVE_UPDATE_CAN_FLY, 64); - data << GetPackGUID(); - BuildMovementPacket(&data); - SendMessageToSet(&data, false); - return true; - } - else - return false; -} - -bool Player::SetHover(bool apply, bool packetOnly /*= false*/, bool updateAnimTier /*= true*/) -{ - if (!packetOnly && !Unit::SetHover(apply, packetOnly, updateAnimTier)) - return false; - - WorldPacket data(apply ? SMSG_MOVE_SET_HOVER : SMSG_MOVE_UNSET_HOVER, 12); - data << GetPackGUID(); - data << uint32(0); //! movement counter - SendDirectMessage(&data); - - data.Initialize(MSG_MOVE_HOVER, 64); - data << GetPackGUID(); - BuildMovementPacket(&data); - SendMessageToSet(&data, false); - return true; -} - -bool Player::SetWaterWalking(bool apply, bool packetOnly /*= false*/) -{ - if (!packetOnly && !Unit::SetWaterWalking(apply)) - return false; - - WorldPacket data(apply ? SMSG_MOVE_WATER_WALK : SMSG_MOVE_LAND_WALK, 12); - data << GetPackGUID(); - data << uint32(0); //! movement counter - SendDirectMessage(&data); - - data.Initialize(MSG_MOVE_WATER_WALK, 64); - data << GetPackGUID(); - BuildMovementPacket(&data); - SendMessageToSet(&data, false); - return true; -} - -bool Player::SetFeatherFall(bool apply, bool packetOnly /*= false*/) -{ - if (!packetOnly && !Unit::SetFeatherFall(apply)) - return false; - - WorldPacket data(apply ? SMSG_MOVE_FEATHER_FALL : SMSG_MOVE_NORMAL_FALL, 12); - data << GetPackGUID(); - data << uint32(0); //! movement counter - SendDirectMessage(&data); - - data.Initialize(MSG_MOVE_FEATHER_FALL, 64); - data << GetPackGUID(); - BuildMovementPacket(&data); - SendMessageToSet(&data, false); - return true; -} - void Player::SendMovementSetCollisionHeight(float height) { WorldPacket data(SMSG_MOVE_SET_COLLISION_HGT, GetPackGUID().size() + 4 + 4); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index dd7d0cf12d3..4d8b0d01f2e 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2255,11 +2255,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player> bool IsInWhisperWhiteList(ObjectGuid guid); void RemoveFromWhisperWhiteList(ObjectGuid guid) { WhisperList.remove(guid); } - bool SetDisableGravity(bool disable, bool packetOnly /* = false */, bool updateAnimTier = true) override; - bool SetCanFly(bool apply, bool packetOnly = false) override; - bool SetWaterWalking(bool apply, bool packetOnly = false) override; - bool SetFeatherFall(bool apply, bool packetOnly = false) override; - bool SetHover(bool enable, bool packetOnly = false, bool updateAnimTier = true) override; void SendMovementSetCollisionHeight(float height); bool CanFly() const override { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_CAN_FLY); } diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index acf02eabc03..bf6132e5c5d 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -6101,10 +6101,7 @@ void Unit::SetCharm(Unit* charm, bool apply) _isWalkingBeforeCharm = charm->IsWalking(); if (_isWalkingBeforeCharm) - { charm->SetWalk(false); - charm->SendMovementFlagUpdate(); - } m_Controlled.insert(charm); } @@ -6143,10 +6140,7 @@ void Unit::SetCharm(Unit* charm, bool apply) } if (charm->IsWalking() != _isWalkingBeforeCharm) - { charm->SetWalk(_isWalkingBeforeCharm); - charm->SendMovementFlagUpdate(true); // send packet to self, to update movement state on player. - } if (charm->GetTypeId() == TYPEID_PLAYER || !charm->ToCreature()->HasUnitTypeMask(UNIT_MASK_MINION) @@ -13278,10 +13272,16 @@ bool Unit::SetWalk(bool enable) AddUnitMovementFlag(MOVEMENTFLAG_WALKING); else RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING); + + static OpcodeServer const walkModeTable[2] = { SMSG_SPLINE_MOVE_SET_RUN_MODE, SMSG_SPLINE_MOVE_SET_WALK_MODE }; + + WorldPacket data(walkModeTable[enable], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); return true; } -bool Unit::SetDisableGravity(bool disable, bool /*packetOnly = false*/, bool /*updateAnimTier = true*/) +bool Unit::SetDisableGravity(bool disable, bool updateAnimTier /*= true*/) { if (disable == IsGravityDisabled()) return false; @@ -13294,6 +13294,41 @@ bool Unit::SetDisableGravity(bool disable, bool /*packetOnly = false*/, bool /*u else RemoveUnitMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); + static OpcodeServer const gravityOpcodeTable[2][2] = + { + { SMSG_SPLINE_MOVE_GRAVITY_ENABLE, SMSG_MOVE_GRAVITY_ENABLE }, + { SMSG_SPLINE_MOVE_GRAVITY_DISABLE, SMSG_MOVE_GRAVITY_DISABLE } + }; + + if (Player* playerMover = ToPlayer()) + { + WorldPacket data(gravityOpcodeTable[disable][1], 12); + data << GetPackGUID(); + data << uint32(0); //! movement counter + playerMover->SendDirectMessage(&data); + + data.Initialize(MSG_MOVE_GRAVITY_CHNG, 64); + data << GetPackGUID(); + BuildMovementPacket(&data); + SendMessageToSet(&data, false); + } + else + { + WorldPacket data(gravityOpcodeTable[disable][0], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + } + + if (IsCreature() && updateAnimTier && IsAlive() && !HasUnitState(UNIT_STATE_ROOT) && !ToCreature()->GetMovementTemplate().IsRooted()) + { + if (IsGravityDisabled()) + SetAnimTier(AnimTier::Fly); + else if (IsHovering()) + SetAnimTier(AnimTier::Hover); + else + SetAnimTier(AnimTier::Ground); + } + return true; } @@ -13322,25 +13357,64 @@ bool Unit::SetSwim(bool enable) AddUnitMovementFlag(MOVEMENTFLAG_SWIMMING); else RemoveUnitMovementFlag(MOVEMENTFLAG_SWIMMING); + + static OpcodeServer const swimOpcodeTable[2] = { SMSG_SPLINE_MOVE_STOP_SWIM, SMSG_SPLINE_MOVE_START_SWIM }; + + WorldPacket data(swimOpcodeTable[enable], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + return true; } -bool Unit::SetCanFly(bool enable, bool /*packetOnly = false */) +bool Unit::SetCanFly(bool enable, bool packetOnly /*= false */) { - if (enable == HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY)) - return false; + if (!packetOnly) + { + if (enable == HasUnitMovementFlag(MOVEMENTFLAG_CAN_FLY)) + return false; - if (enable) + if (enable) + { + AddUnitMovementFlag(MOVEMENTFLAG_CAN_FLY); + RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING); + } + else + RemoveUnitMovementFlag(MOVEMENTFLAG_CAN_FLY | MOVEMENTFLAG_MASK_MOVING_FLY); + } + + static OpcodeServer const flyOpcodeTable[2][2] = { - AddUnitMovementFlag(MOVEMENTFLAG_CAN_FLY); - RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING); + { SMSG_SPLINE_MOVE_UNSET_FLYING, SMSG_MOVE_UNSET_CAN_FLY }, + { SMSG_SPLINE_MOVE_SET_FLYING, SMSG_MOVE_SET_CAN_FLY } + }; + + if (!enable && GetTypeId() == TYPEID_PLAYER) + ToPlayer()->SetFallInformation(0, GetPositionZ()); + + if (Player* playerMover = ToPlayer()) + { + WorldPacket data(flyOpcodeTable[enable][1], 12); + data << GetPackGUID(); + data << uint32(0); //! movement counter + playerMover->SendDirectMessage(&data); + + data.Initialize(MSG_MOVE_UPDATE_CAN_FLY, 64); + data << GetPackGUID(); + BuildMovementPacket(&data); + SendMessageToSet(&data, false); } else - RemoveUnitMovementFlag(MOVEMENTFLAG_CAN_FLY | MOVEMENTFLAG_MASK_MOVING_FLY); + { + WorldPacket data(flyOpcodeTable[enable][0], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + } + return true; } -bool Unit::SetWaterWalking(bool enable, bool /*packetOnly = false */) +bool Unit::SetWaterWalking(bool enable) { if (enable == HasUnitMovementFlag(MOVEMENTFLAG_WATERWALKING)) return false; @@ -13349,10 +13423,36 @@ bool Unit::SetWaterWalking(bool enable, bool /*packetOnly = false */) AddUnitMovementFlag(MOVEMENTFLAG_WATERWALKING); else RemoveUnitMovementFlag(MOVEMENTFLAG_WATERWALKING); + + static OpcodeServer const waterWalkingOpcodeTable[2][2] = + { + { SMSG_SPLINE_MOVE_LAND_WALK, SMSG_MOVE_LAND_WALK }, + { SMSG_SPLINE_MOVE_WATER_WALK, SMSG_MOVE_WATER_WALK } + }; + + if (Player* playerMover = ToPlayer()) + { + WorldPacket data(waterWalkingOpcodeTable[enable][1], 12); + data << GetPackGUID(); + data << uint32(0); //! movement counter + playerMover->SendDirectMessage(&data); + + data.Initialize(MSG_MOVE_WATER_WALK, 64); + data << GetPackGUID(); + BuildMovementPacket(&data); + SendMessageToSet(&data, false); + } + else + { + WorldPacket data(waterWalkingOpcodeTable[enable][0], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + } + return true; } -bool Unit::SetFeatherFall(bool enable, bool /*packetOnly = false */) +bool Unit::SetFeatherFall(bool enable) { if (enable == HasUnitMovementFlag(MOVEMENTFLAG_FALLING_SLOW)) return false; @@ -13361,10 +13461,36 @@ bool Unit::SetFeatherFall(bool enable, bool /*packetOnly = false */) AddUnitMovementFlag(MOVEMENTFLAG_FALLING_SLOW); else RemoveUnitMovementFlag(MOVEMENTFLAG_FALLING_SLOW); + + static OpcodeServer const featherFallOpcodeTable[2][2] = + { + { SMSG_SPLINE_MOVE_NORMAL_FALL, SMSG_MOVE_NORMAL_FALL }, + { SMSG_SPLINE_MOVE_FEATHER_FALL, SMSG_MOVE_FEATHER_FALL } + }; + + if (Player* playerMover = ToPlayer()) + { + WorldPacket data(featherFallOpcodeTable[enable][1], 12); + data << GetPackGUID(); + data << uint32(0); //! movement counter + playerMover->SendDirectMessage(&data); + + data.Initialize(MSG_MOVE_FEATHER_FALL, 64); + data << GetPackGUID(); + BuildMovementPacket(&data); + SendMessageToSet(&data, false); + } + else + { + WorldPacket data(featherFallOpcodeTable[enable][0], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + } + return true; } -bool Unit::SetHover(bool enable, bool /*packetOnly = false*/, bool /*updateAnimTier = true*/) +bool Unit::SetHover(bool enable, bool updateAnimTier /*= true*/) { if (enable == HasUnitMovementFlag(MOVEMENTFLAG_HOVER)) return false; @@ -13389,6 +13515,42 @@ bool Unit::SetHover(bool enable, bool /*packetOnly = false*/, bool /*updateAnimT UpdateHeight(newZ); } } + + static OpcodeServer const hoverOpcodeTable[2][2] = + { + { SMSG_SPLINE_MOVE_UNSET_HOVER, SMSG_MOVE_UNSET_HOVER }, + { SMSG_SPLINE_MOVE_SET_HOVER, SMSG_MOVE_SET_HOVER } + }; + + if (Player* playerMover = ToPlayer()) + { + WorldPacket data(hoverOpcodeTable[enable][1], 12); + data << GetPackGUID(); + data << uint32(0); //! movement counter + playerMover->SendDirectMessage(&data); + + data.Initialize(MSG_MOVE_HOVER, 64); + data << GetPackGUID(); + BuildMovementPacket(&data); + SendMessageToSet(&data, false); + } + else + { + WorldPacket data(hoverOpcodeTable[enable][0], 9); + data << GetPackGUID(); + SendMessageToSet(&data, true); + } + + if (IsCreature() && updateAnimTier && IsAlive() && !HasUnitState(UNIT_STATE_ROOT) && !ToCreature()->GetMovementTemplate().IsRooted()) + { + if (IsGravityDisabled()) + SetAnimTier(AnimTier::Fly); + else if (IsHovering()) + SetAnimTier(AnimTier::Hover); + else + SetAnimTier(AnimTier::Ground); + } + return true; } diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 8f4ed233ab0..f22c050002c 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -1217,14 +1217,14 @@ class TC_GAME_API Unit : public WorldObject bool IsGravityDisabled() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY); } bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING); } bool IsHovering() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_HOVER); } - virtual bool SetWalk(bool enable); - virtual bool SetDisableGravity(bool disable, bool packetOnly = false, bool updateAnimTier = true); + bool SetWalk(bool enable); + bool SetDisableGravity(bool disable, bool updateAnimTier = true); bool SetFall(bool enable); - virtual bool SetSwim(bool enable); - virtual bool SetCanFly(bool enable, bool packetOnly = false); - virtual bool SetWaterWalking(bool enable, bool packetOnly = false); - virtual bool SetFeatherFall(bool enable, bool packetOnly = false); - virtual bool SetHover(bool enable, bool packetOnly = false, bool updateAnimTier = true); + bool SetSwim(bool enable); + bool SetCanFly(bool enable, bool packetOnly = false); + bool SetWaterWalking(bool enable); + bool SetFeatherFall(bool enable); + bool SetHover(bool enable, bool updateAnimTier = true); void SetInFront(WorldObject const* target); void SetFacingTo(float const ori, bool force = true); |
