From 7c43adf9f8961c303ff5bd00960c6afcab376dc5 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 5 Jan 2022 23:45:25 -0500 Subject: [PATCH] Core/MMaps: Fix charge underwater/falling Port From (https://github.com/TrinityCore/TrinityCore/commit/8d32849b3493d9e819be27945ef31488d8ba6dcf) --- .../Game/Movement/Generators/PathGenerator.cs | 30 +++++++++---------- Source/Game/Spells/Spell.cs | 18 ++++------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Source/Game/Movement/Generators/PathGenerator.cs b/Source/Game/Movement/Generators/PathGenerator.cs index 3ddbe7b3f..65429ff3e 100644 --- a/Source/Game/Movement/Generators/PathGenerator.cs +++ b/Source/Game/Movement/Generators/PathGenerator.cs @@ -195,23 +195,21 @@ namespace Game.Movement Log.outDebug(LogFilter.Maps, "++ BuildPolyPath . farFromPoly distToStartPoly={0:F3} distToEndPoly={1:F3}\n", distToStartPoly, distToEndPoly); bool buildShotrcut = false; - if (_sourceUnit.IsTypeId(TypeId.Unit)) + var p = (distToStartPoly > 7.0f) ? startPos : endPos; + if (_sourceUnit.GetMap().IsUnderWater(_sourceUnit.GetPhaseShift(), p.X, p.Y, p.Z)) { - Creature owner = _sourceUnit.ToCreature(); - - Vector3 p = (distToStartPoly > 7.0f) ? startPos : endPos; - if (_sourceUnit.GetMap().IsUnderWater(_sourceUnit.GetPhaseShift(), p.X, p.Y, p.Z)) - { - Log.outDebug(LogFilter.Maps, "++ BuildPolyPath . underWater case\n"); - if (owner.CanSwim()) - buildShotrcut = true; - } - else - { - Log.outDebug(LogFilter.Maps, "++ BuildPolyPath . flying case\n"); - if (owner.CanFly()) - buildShotrcut = true; - } + Log.outDebug(LogFilter.Maps, "++ BuildPolyPath :: underWater case"); + if (_sourceUnit.CanSwim()) + buildShotrcut = true; + } + else + { + Log.outDebug(LogFilter.Maps, "++ BuildPolyPath :: flying case"); + if (_sourceUnit.CanFly()) + buildShotrcut = true; + // Allow to build a shortcut if the unit is falling and it's trying to move downwards towards a target (i.e. charging) + else if (_sourceUnit.IsFalling() && endPos.Z < startPos.Z) + buildShotrcut = true; } if (buildShotrcut) diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index d716e8f33..e9b4d2112 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -4921,22 +4921,14 @@ namespace Game.Spells m_preGeneratedPath = new(unitCaster); m_preGeneratedPath.SetPathLengthLimit(range); - //first try with raycast, if it fails fall back to normal path - float targetObjectSize = Math.Min(target.GetCombatReach(), 4.0f); - bool result = m_preGeneratedPath.CalculatePath(target.GetPositionX(), target.GetPositionY(), target.GetPositionZ() + targetObjectSize, false, true); + + // first try with raycast, if it fails fall back to normal path + bool result = m_preGeneratedPath.CalculatePath(target.GetPositionX(), target.GetPositionY(), target.GetPositionZ(), false, false); if (m_preGeneratedPath.GetPathType().HasAnyFlag(PathType.Short)) return SpellCastResult.OutOfRange; else if (!result || m_preGeneratedPath.GetPathType().HasAnyFlag(PathType.NoPath | PathType.Incomplete)) - { - result = m_preGeneratedPath.CalculatePath(target.GetPositionX(), target.GetPositionY(), target.GetPositionZ() + targetObjectSize, false, false); - if (m_preGeneratedPath.GetPathType().HasAnyFlag(PathType.Short)) - return SpellCastResult.OutOfRange; - else if (!result || m_preGeneratedPath.GetPathType().HasAnyFlag(PathType.NoPath | PathType.Incomplete)) - return SpellCastResult.NoPath; - else if (m_preGeneratedPath.IsInvalidDestinationZ(target)) // Check position z, if not in a straight line - return SpellCastResult.NoPath; - } - else if (m_preGeneratedPath.IsInvalidDestinationZ(target)) // Check position z, if in a straight line + return SpellCastResult.NoPath; + else if (m_preGeneratedPath.IsInvalidDestinationZ(target)) // Check position z, if not in a straight line return SpellCastResult.NoPath; m_preGeneratedPath.ShortenPathUntilDist(target, objSize); //move back