Core/Movement: Use MotionMaster::MoveKnockbackFrom for creatures hit by SPELL_EFFECT_LEAP_BACK, SPELL_EFFECT_PULL_TOWARDS and SPELL_EFFECT_PULL_TOWARDS_DEST

This commit is contained in:
Shauren
2025-11-18 18:05:33 +01:00
parent 71ebbc60cc
commit 7c5e6f695d
5 changed files with 12 additions and 45 deletions

View File

@@ -12325,7 +12325,7 @@ void Unit::SendMoveKnockBack(Player* player, float speedXY, float speedZ, float
player->GetSession()->SendPacket(moveKnockBack.Write());
}
void Unit::KnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/)
void Unit::KnockbackFrom(Position const& origin, float speedXY, float speedZ, float angle /*= M_PI*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/)
{
Player* player = ToPlayer();
if (!player)
@@ -12339,14 +12339,14 @@ void Unit::KnockbackFrom(Position const& origin, float speedXY, float speedZ, Mo
}
if (!player)
GetMotionMaster()->MoveKnockbackFrom(origin, speedXY, speedZ, spellEffectExtraData);
GetMotionMaster()->MoveKnockbackFrom(origin, speedXY, speedZ, angle, spellEffectExtraData);
else
{
float o = GetPosition() == origin ? GetOrientation() + M_PI : origin.GetAbsoluteAngle(this);
float o = (GetPosition() == origin ? GetOrientation() : GetAbsoluteAngle(origin)) + angle;
if (speedXY < 0)
{
speedXY = -speedXY;
o = o - M_PI;
o = o - float(M_PI);
}
float vcos = std::cos(o);
@@ -12470,21 +12470,6 @@ uint32 Unit::GetModelForForm(ShapeshiftForm form, uint32 spellId) const
return 0;
}
void Unit::JumpTo(float speedXY, float speedZ, float angle, Optional<Position> dest)
{
if (dest)
angle += GetRelativeAngle(*dest);
if (GetTypeId() == TYPEID_UNIT)
GetMotionMaster()->MoveJumpTo(angle, speedXY, speedZ);
else
{
float vcos = std::cos(angle+GetOrientation());
float vsin = std::sin(angle+GetOrientation());
SendMoveKnockBack(ToPlayer(), speedXY, -speedZ, vcos, vsin);
}
}
void Unit::HandleSpellClick(Unit* clicker, int8 seatId /*= -1*/)
{
bool spellClickHandled = false;

View File

@@ -1133,8 +1133,7 @@ class TC_GAME_API Unit : public WorldObject
void UpdateHeight(float newZ);
void SendMoveKnockBack(Player* player, float speedXY, float speedZ, float vcos, float vsin);
void KnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void JumpTo(float speedXY, float speedZ, float angle, Optional<Position> dest = {});
void KnockbackFrom(Position const& origin, float speedXY, float speedZ, float angle = M_PI, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MonsterMoveWithSpeed(float x, float y, float z, float speed, bool generatePath = false, bool forceDestination = false);

View File

@@ -801,7 +801,7 @@ void MotionMaster::MoveCharge(PathGenerator const& path, float speed /*= SPEED_C
init.Launch();
}
void MotionMaster::MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/)
void MotionMaster::MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, float angle /*= M_PI*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/)
{
// This function may make players fall below map
if (_owner->GetTypeId() == TYPEID_PLAYER)
@@ -811,7 +811,7 @@ void MotionMaster::MoveKnockbackFrom(Position const& origin, float speedXY, floa
return;
Position dest = _owner->GetPosition();
float o = dest == origin ? 0.0f : _owner->GetRelativeAngle(origin) + float(M_PI);
float o = (dest == origin ? 0.0f : _owner->GetRelativeAngle(origin)) + angle;
if (speedXY < 0)
{
speedXY = -speedXY;
@@ -858,23 +858,6 @@ void MotionMaster::MoveKnockbackFrom(Position const& origin, float speedXY, floa
Add(movement);
}
void MotionMaster::MoveJumpTo(float angle, float speedXY, float speedZ)
{
// This function may make players fall below map
if (_owner->GetTypeId() == TYPEID_PLAYER)
return;
float x, y, z = _owner->GetPositionZ();
float moveTimeHalf = speedZ / Movement::gravity;
float dist = 2 * moveTimeHalf * speedXY;
_owner->GetNearPoint2D(nullptr, x, y, dist, _owner->GetOrientation() + angle);
_owner->UpdateAllowedPositionZ(x, y, z);
MoveJump({ x, y, z }, speedXY, speedZ);
}
void MotionMaster::MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id /*= EVENT_JUMP*/, MovementFacingTarget const& facing /*= {}*/,
bool orientationFixed /*= false*/, JumpArrivalCastArgs const* arrivalCast /*= nullptr*/, Movement::SpellEffectExtraData const* spellEffectExtraData /*= nullptr*/,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult /*= {}*/)

View File

@@ -190,8 +190,7 @@ class TC_GAME_API MotionMaster
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});
void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint32 id = EVENT_CHARGE, bool generatePath = false, Unit const* target = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveCharge(PathGenerator const& path, float speed = SPEED_CHARGE, Unit const* target = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveJumpTo(float angle, float speedXY, float speedZ);
void MoveKnockbackFrom(Position const& origin, float speedXY, float speedZ, float angle = M_PI, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr);
void MoveJump(Position const& pos, float speedXY, float speedZ, uint32 id = EVENT_JUMP, MovementFacingTarget const& facing = {},
bool orientationFixed = false, JumpArrivalCastArgs const* arrivalCast = nullptr, Movement::SpellEffectExtraData const* spellEffectExtraData = nullptr,
Optional<Scripting::v2::ActionResultSetter<MovementStopReason>>&& scriptResult = {});

View File

@@ -4072,8 +4072,9 @@ void Spell::EffectLeapBack()
float speedxy = effectInfo->MiscValue / 10.f;
float speedz = damage / 10.f;
// Disengage
unitTarget->JumpTo(speedxy, speedz, effectInfo->PositionFacing);
unitTarget->KnockbackFrom(unitTarget->GetPosition(), speedxy, speedz, effectInfo->PositionFacing);
// changes fall time
if (m_caster->GetTypeId() == TYPEID_PLAYER)
@@ -4162,7 +4163,7 @@ void Spell::EffectPullTowards()
return;
}
unitTarget->JumpTo(speedXY, speedZ, 0.0f, pos);
unitTarget->KnockbackFrom(unitTarget->GetPosition(), speedXY, speedZ, unitTarget->GetRelativeAngle(pos));
}
void Spell::EffectPullTowardsDest()
@@ -4198,7 +4199,7 @@ void Spell::EffectPullTowardsDest()
return;
}
unitTarget->JumpTo(speedXY, speedZ, 0.0f, *pos);
unitTarget->KnockbackFrom(unitTarget->GetPosition(), speedXY, speedZ, unitTarget->GetRelativeAngle(pos));
}
void Spell::EffectChangeRaidMarker()