diff --git a/Source/Game/Entities/Object/Position.cs b/Source/Game/Entities/Object/Position.cs index eaf3dcfba..250e2834b 100644 --- a/Source/Game/Entities/Object/Position.cs +++ b/Source/Game/Entities/Object/Position.cs @@ -325,25 +325,6 @@ namespace Game.Entities return Math.Abs(Math.Sin(angle)) * GetExactDist2d(pos.GetPositionX(), pos.GetPositionY()) < width; } - public void GetSinCos(float x, float y, out float vsin, out float vcos) - { - float dx = GetPositionX() - x; - float dy = GetPositionY() - y; - - if (Math.Abs(dx) < 0.001f && Math.Abs(dy) < 0.001f) - { - float o = NormalizeOrientation(GetOrientation() - MathF.PI); - vcos = MathF.Cos(o); - vsin = MathF.Sin(o); - } - else - { - float dist = (float)Math.Sqrt((dx * dx) + (dy * dy)); - vcos = dx / dist; - vsin = dy / dist; - } - } - public override string ToString() { return $"X: {posX} Y: {posY} Z: {posZ} O: {Orientation}"; diff --git a/Source/Game/Entities/Unit/Unit.Movement.cs b/Source/Game/Entities/Unit/Unit.Movement.cs index 4c8af14c6..4fa0de062 100644 --- a/Source/Game/Entities/Unit/Unit.Movement.cs +++ b/Source/Game/Entities/Unit/Unit.Movement.cs @@ -235,7 +235,7 @@ namespace Game.Entities GetMotionMaster().LaunchMoveSpline(init, 0, MovementGeneratorPriority.Normal, MovementGeneratorType.Point); } - public void KnockbackFrom(float x, float y, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null) + public void KnockbackFrom(Position origin, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null) { Player player = ToPlayer(); if (!player) @@ -250,11 +250,18 @@ namespace Game.Entities } if (!player) - GetMotionMaster().MoveKnockbackFrom(x, y, speedXY, speedZ, spellEffectExtraData); + GetMotionMaster().MoveKnockbackFrom(origin, speedXY, speedZ, spellEffectExtraData); else { - float vcos, vsin; - GetSinCos(x, y, out vsin, out vcos); + float o = GetPosition() == origin ? GetOrientation() + MathF.PI : origin.GetRelativeAngle(this); + if (speedXY < 0) + { + speedXY = -speedXY; + o = o - MathF.PI; + } + + float vcos = MathF.Cos(o); + float vsin = MathF.Sin(o); SendMoveKnockBack(player, speedXY, -speedZ, vcos, vsin); } } diff --git a/Source/Game/Movement/MotionMaster.cs b/Source/Game/Movement/MotionMaster.cs index c9b1e7951..c182a30f4 100644 --- a/Source/Game/Movement/MotionMaster.cs +++ b/Source/Game/Movement/MotionMaster.cs @@ -656,7 +656,7 @@ namespace Game.Movement init.Launch(); } - public void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null) + public void MoveKnockbackFrom(Position origin, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null) { //This function may make players fall below map if (_owner.IsTypeId(TypeId.Player)) @@ -670,7 +670,7 @@ namespace Game.Movement float dist = 2 * moveTimeHalf * speedXY; float max_height = -MoveSpline.ComputeFallElevation(moveTimeHalf, false, -speedZ); - _owner.GetNearPoint(_owner, out x, out y, out z, dist, _owner.GetAbsoluteAngle(srcX, srcY) + MathFunctions.PI); + _owner.GetNearPoint(_owner, out x, out y, out z, dist, _owner.GetAbsoluteAngle(origin) + MathFunctions.PI); MoveSplineInit init = new(_owner); init.MoveTo(x, y, z); diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 66f6a7e8f..7396fd2b4 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -4021,18 +4021,18 @@ namespace Game.Spells if (speedxy < 0.01f && speedz < 0.01f) return; - float x, y; + Position origin; if (effectInfo.Effect == SpellEffectName.KnockBackDest) { if (m_targets.HasDst()) - destTarget.GetPosition(out x, out y); + origin = new(destTarget.GetPosition()); else return; } - else //if (GetEffect(i].Effect == SPELL_EFFECT_KNOCK_BACK) - m_caster.GetPosition(out x, out y); + else //if (effectInfo.Effect == SPELL_EFFECT_KNOCK_BACK) + origin = new(m_caster.GetPosition()); - unitTarget.KnockbackFrom(x, y, speedxy, speedz); + unitTarget.KnockbackFrom(origin, speedxy, speedz); } [SpellEffectHandler(SpellEffectName.LeapBack)] diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index 768933269..4ae9d21b5 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -1446,7 +1446,7 @@ namespace Scripts.Spells.Generic float verticalSpeed = 8.0f; // This method relies on the Dalaran Sewer map disposition and Water Spout position // What we do is knock the player from a position exactly behind him and at the end of the pipe - player.KnockbackFrom(target.GetPositionX(), player.GetPositionY(), horizontalSpeed, verticalSpeed); + player.KnockbackFrom(target.GetPosition(), horizontalSpeed, verticalSpeed); } } }