Core/Movement: Corrected values sent in knockback packet when speedXY < 0

Port From (https://github.com/TrinityCore/TrinityCore/commit/732a8ee26199d7f04c692fa64f96955db13cf69d)
This commit is contained in:
hondacrx
2021-11-08 10:44:57 -05:00
parent 5f0af0e527
commit 80d6b08c13
5 changed files with 19 additions and 31 deletions
-19
View File
@@ -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}";
+11 -4
View File
@@ -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);
}
}
+2 -2
View File
@@ -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);
+5 -5
View File
@@ -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)]
+1 -1
View File
@@ -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);
}
}
}