Core/Movement: Refactor jump speed calculation out of spell code
Port From (https://github.com/TrinityCore/TrinityCore/commit/705d5701bf17f1787d2646c55c994b0404659991)
This commit is contained in:
@@ -1036,6 +1036,28 @@ namespace Game.Movement
|
|||||||
Add(movement);
|
Add(movement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CalculateJumpSpeeds(float dist, UnitMoveType moveType, float speedMultiplier, float minHeight, float maxHeight, out float speedXY, out float speedZ)
|
||||||
|
{
|
||||||
|
float baseSpeed = _owner.IsControlledByPlayer() ? SharedConst.playerBaseMoveSpeed[(int)moveType] : SharedConst.baseMoveSpeed[(int)moveType];
|
||||||
|
Creature creature = _owner.ToCreature();
|
||||||
|
if (creature != null)
|
||||||
|
baseSpeed *= creature.GetCreatureTemplate().SpeedRun;
|
||||||
|
|
||||||
|
speedXY = Math.Min(baseSpeed * 3.0f * speedMultiplier, Math.Max(28.0f, _owner.GetSpeed(moveType) * 4.0f));
|
||||||
|
|
||||||
|
float duration = dist / speedXY;
|
||||||
|
float durationSqr = duration * duration;
|
||||||
|
float height;
|
||||||
|
if (durationSqr < minHeight * 8 / gravity)
|
||||||
|
height = minHeight;
|
||||||
|
else if (durationSqr > maxHeight * 8 / gravity)
|
||||||
|
height = maxHeight;
|
||||||
|
else
|
||||||
|
height = (float)(gravity * durationSqr / 8);
|
||||||
|
|
||||||
|
speedZ = (float)Math.Sqrt(2 * gravity * height);
|
||||||
|
}
|
||||||
|
|
||||||
void ResolveDelayedActions()
|
void ResolveDelayedActions()
|
||||||
{
|
{
|
||||||
while (_delayedActions.Count != 0)
|
while (_delayedActions.Count != 0)
|
||||||
|
|||||||
@@ -480,30 +480,15 @@ namespace Game.Spells
|
|||||||
void CalculateJumpSpeeds(SpellEffectInfo effInfo, float dist, out float speedXY, out float speedZ)
|
void CalculateJumpSpeeds(SpellEffectInfo effInfo, float dist, out float speedXY, out float speedZ)
|
||||||
{
|
{
|
||||||
Unit unitCaster = GetUnitCasterForEffectHandlers();
|
Unit unitCaster = GetUnitCasterForEffectHandlers();
|
||||||
float runSpeed = unitCaster.IsControlledByPlayer() ? SharedConst.playerBaseMoveSpeed[(int)UnitMoveType.Run] : SharedConst.baseMoveSpeed[(int)UnitMoveType.Run];
|
|
||||||
Creature creature = unitCaster.ToCreature();
|
|
||||||
if (creature != null)
|
|
||||||
runSpeed *= creature.GetCreatureTemplate().SpeedRun;
|
|
||||||
|
|
||||||
float multiplier = effInfo.Amplitude;
|
float multiplier = effInfo.Amplitude;
|
||||||
if (multiplier <= 0.0f)
|
if (multiplier <= 0.0f)
|
||||||
multiplier = 1.0f;
|
multiplier = 1.0f;
|
||||||
|
|
||||||
speedXY = Math.Min(runSpeed * 3.0f * multiplier, Math.Max(28.0f, unitCaster.GetSpeed(UnitMoveType.Run) * 4.0f));
|
|
||||||
|
|
||||||
float duration = dist / speedXY;
|
|
||||||
float durationSqr = duration * duration;
|
|
||||||
float minHeight = effInfo.MiscValue != 0 ? effInfo.MiscValue / 10.0f : 0.5f; // Lower bound is blizzlike
|
float minHeight = effInfo.MiscValue != 0 ? effInfo.MiscValue / 10.0f : 0.5f; // Lower bound is blizzlike
|
||||||
float maxHeight = effInfo.MiscValueB != 0 ? effInfo.MiscValueB / 10.0f : 1000.0f; // Upper bound is unknown
|
float maxHeight = effInfo.MiscValueB != 0 ? effInfo.MiscValueB / 10.0f : 1000.0f; // Upper bound is unknown
|
||||||
float height;
|
|
||||||
if (durationSqr < minHeight * 8 / MotionMaster.gravity)
|
|
||||||
height = minHeight;
|
|
||||||
else if (durationSqr > maxHeight * 8 / MotionMaster.gravity)
|
|
||||||
height = maxHeight;
|
|
||||||
else
|
|
||||||
height = (float)(MotionMaster.gravity * durationSqr / 8);
|
|
||||||
|
|
||||||
speedZ = MathF.Sqrt((float)(2 * MotionMaster.gravity * height));
|
unitCaster.GetMotionMaster().CalculateJumpSpeeds(dist, UnitMoveType.Run, multiplier, minHeight, maxHeight, out speedXY, out speedZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SpellEffectHandler(SpellEffectName.Jump)]
|
[SpellEffectHandler(SpellEffectName.Jump)]
|
||||||
|
|||||||
Reference in New Issue
Block a user