From 6b344e9a09a44c51d9f361243cc24ba909f89aaf Mon Sep 17 00:00:00 2001 From: hondacrx Date: Fri, 6 Jan 2023 15:59:08 -0500 Subject: [PATCH] Core/SAI: Improved SMART_ACTION_JUMP_TO_POS to mirror behavior similar to SMART_ACTION_MOVE_TO_POS Port From (https://github.com/TrinityCore/TrinityCore/commit/f291ca97962e087f9d87077b1ee6fa5b386937ed) --- Source/Framework/Constants/SmartAIConst.cs | 2 +- Source/Game/AI/SmartScripts/SmartAIManager.cs | 8 ++++-- Source/Game/AI/SmartScripts/SmartScript.cs | 25 ++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/Framework/Constants/SmartAIConst.cs b/Source/Framework/Constants/SmartAIConst.cs index 39306cbbd..b077ffecd 100644 --- a/Source/Framework/Constants/SmartAIConst.cs +++ b/Source/Framework/Constants/SmartAIConst.cs @@ -344,7 +344,7 @@ namespace Framework.Constants SetDynamicFlag = 94, // UNUSED, DO NOT REUSE AddDynamicFlag = 95, // UNUSED, DO NOT REUSE RemoveDynamicFlag = 96, // UNUSED, DO NOT REUSE - JumpToPos = 97, // Speedxy, Speedz, Targetx, Targety, Targetz + JumpToPos = 97, // SpeedXY, SpeedZ, Gravity, UseDefaultGravity, PointId, ContactDistance SendGossipMenu = 98, // Menuid, optionIndex GoSetLootState = 99, // State SendTargetToTarget = 100, // Id diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index c68de7e68..eaa8d9e1b 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -3483,8 +3483,12 @@ namespace Game.AI } public struct Jump { - public uint speedxy; - public uint speedz; + public uint SpeedXY; + public uint SpeedZ; + public uint Gravity; + public uint UseDefaultGravity; + public uint PointId; + public uint ContactDistance; } public struct FleeAssist { diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index 51cc7416c..8c6f393cf 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -22,6 +22,7 @@ using Game.Entities; using Game.Groups; using Game.Maps; using Game.Misc; +using Game.Movement; using Game.Spells; using System; using System.Collections.Generic; @@ -1824,12 +1825,28 @@ namespace Game.AI } case SmartActions.JumpToPos: { - foreach (var target in targets) + WorldObject target = null; + + if (!targets.Empty()) + target = targets.SelectRandom(); + + Position pos = new(e.Target.x, e.Target.y, e.Target.z); + if (target) { - Creature creature = target.ToCreature(); - if (creature != null) - creature.GetMotionMaster().MoveJump(e.Target.x, e.Target.y, e.Target.z, 0.0f, e.Action.jump.speedxy, e.Action.jump.speedz); + float x, y, z; + target.GetPosition(out x, out y, out z); + if (e.Action.jump.ContactDistance > 0) + target.GetContactPoint(_me, out x, out y, out z, e.Action.jump.ContactDistance); + pos = new Position(x + e.Target.x, y + e.Target.y, z + e.Target.z); } + + if (e.Action.jump.Gravity != 0 || e.Action.jump.UseDefaultGravity != 0) + { + float gravity = e.Action.jump.UseDefaultGravity != 0 ? (float)MotionMaster.gravity : e.Action.jump.Gravity; + _me.GetMotionMaster().MoveJumpWithGravity(pos, e.Action.jump.SpeedXY, gravity, e.Action.jump.PointId); + } + else + _me.GetMotionMaster().MoveJump(pos, e.Action.jump.SpeedXY, e.Action.jump.SpeedZ, e.Action.jump.PointId); break; } case SmartActions.GoSetLootState: