From 2aa910e9f69b7d44e7ca70b04e37253e24d2c546 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 15 Nov 2021 23:06:07 -0500 Subject: [PATCH] Add rotation to .gob info Port From (https://github.com/TrinityCore/TrinityCore/commit/afac2b174290c871d845e37f88c6f0c874d15fd6) --- Source/Framework/Constants/Language.cs | 2 +- Source/Framework/Util/Extensions.cs | 32 +++++++++ .../Game/Chat/Commands/GameObjectCommands.cs | 69 +++++++++---------- 3 files changed, 64 insertions(+), 39 deletions(-) diff --git a/Source/Framework/Constants/Language.cs b/Source/Framework/Constants/Language.cs index 4c2f45bbd..128302333 100644 --- a/Source/Framework/Constants/Language.cs +++ b/Source/Framework/Constants/Language.cs @@ -1105,7 +1105,7 @@ namespace Framework.Constants SpawninfoCompatibilityMode = 5071, SpawninfoGuidinfo = 5072, SpawninfoSpawnidLocation = 5073, - SpawninfoDistancefromplayer = 5074, + SpawninfoRotation = 5074, SpawngroupBadgroup = 5075, SpawngroupSpawncount = 5076, ListRespawnsRange = 5077, diff --git a/Source/Framework/Util/Extensions.cs b/Source/Framework/Util/Extensions.cs index 5f37df1d7..eac09d585 100644 --- a/Source/Framework/Util/Extensions.cs +++ b/Source/Framework/Util/Extensions.cs @@ -258,6 +258,38 @@ namespace System } } + public static void toEulerAnglesZYX(this Quaternion quaternion, out float z, out float y, out float x) + { + // rot = cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz + // cy*sz cx*cz+sx*sy*sz -cz*sx+cx*sy*sz + // -sy cy*sx cx*cy + + var matrix = Matrix4x4.CreateFromQuaternion(quaternion); + if (matrix.M31 < 1.0) + { + if (matrix.M31 > -1.0) + { + z = MathF.Atan2(matrix.M21, matrix.M11); + y = MathF.Asin(-matrix.M31); + x = MathF.Atan2(matrix.M31, matrix.M33); + } + else + { + // WARNING. Not unique. ZA - XA = -atan2(r01,r02) + z = -(float)MathF.Atan2(matrix.M12, matrix.M13); + y = MathFunctions.PiOver2; + x = 0.0f; + } + } + else + { + // WARNING. Not unique. ZA + XA = atan2(-r01,-r02) + z = (float)MathF.Atan2(-matrix.M12, -matrix.M13); + y = -MathFunctions.PiOver2; + x = 0.0f; + } + } + public static Matrix4x4 fromEulerAnglesZYX(float fYAngle, float fPAngle, float fRAngle) { float fCos = (float)Math.Cos(fYAngle); diff --git a/Source/Game/Chat/Commands/GameObjectCommands.cs b/Source/Game/Chat/Commands/GameObjectCommands.cs index 2168d1d2f..22a8806d5 100644 --- a/Source/Game/Chat/Commands/GameObjectCommands.cs +++ b/Source/Game/Chat/Commands/GameObjectCommands.cs @@ -149,6 +149,9 @@ namespace Game.Chat if (param1.IsEmpty()) return false; + GameObject thisGO = null; + GameObjectData data = null; + uint entry; ulong spawnId = 0; if (param1.Equals("guid")) @@ -160,10 +163,15 @@ namespace Game.Chat if (!ulong.TryParse(cValue, out spawnId)) return false; - GameObjectData data = Global.ObjectMgr.GetGameObjectData(spawnId); + data = Global.ObjectMgr.GetGameObjectData(spawnId); if (data == null) + { + handler.SendSysMessage(CypherStrings.CommandObjnotfound, spawnId); return false; + } + entry = data.Id; + thisGO = handler.GetObjectFromPlayerMapByDbGuid(spawnId); } else { @@ -173,13 +181,10 @@ namespace Game.Chat GameObjectTemplate gameObjectInfo = Global.ObjectMgr.GetGameObjectTemplate(entry); if (gameObjectInfo == null) + { + handler.SendSysMessage(CypherStrings.GameobjectNotExist, entry); return false; - - GameObject thisGO = null; - if (handler.GetSession().GetPlayer()) - thisGO = handler.GetSession().GetPlayer().FindNearestGameObject(entry, 30); - else if (handler.GetSelectedObject() != null && handler.GetSelectedObject().IsTypeId(TypeId.GameObject)) - thisGO = handler.GetSelectedObject().ToGameObject(); + } GameObjectTypes type = gameObjectInfo.type; uint displayId = gameObjectInfo.displayId; @@ -190,47 +195,35 @@ namespace Game.Chat if (thisGO != null) { handler.SendSysMessage(CypherStrings.SpawninfoGuidinfo, thisGO.GetGUID().ToString()); - handler.SendSysMessage(CypherStrings.SpawninfoSpawnidLocation, thisGO.GetSpawnId(), thisGO.GetPositionX(), thisGO.GetPositionY(), thisGO.GetPositionZ()); - Player player = handler.GetSession().GetPlayer(); - if (player != null) - { - Position playerPos = player.GetPosition(); - float dist = thisGO.GetExactDist(playerPos); - handler.SendSysMessage(CypherStrings.SpawninfoDistancefromplayer, dist); - } - } - handler.SendSysMessage(CypherStrings.GoinfoEntry, entry); - handler.SendSysMessage(CypherStrings.GoinfoType, type); - handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId); - handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId); + handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, thisGO.GetRespawnCompatibilityMode()); - if (thisGO != null) - { if (thisGO.GetGameObjectData() != null && thisGO.GetGameObjectData().spawnGroupData.groupId != 0) { SpawnGroupTemplateData groupData = thisGO.ToGameObject().GetGameObjectData().spawnGroupData; handler.SendSysMessage(CypherStrings.SpawninfoGroupId, groupData.name, groupData.groupId, groupData.flags, thisGO.GetMap().IsSpawnGroupActive(groupData.groupId)); } - - handler.SendSysMessage(CypherStrings.SpawninfoCompatibilityMode, thisGO.GetRespawnCompatibilityMode()); + + GameObjectOverride goOverride = Global.ObjectMgr.GetGameObjectOverride(spawnId); + if (goOverride == null) + goOverride = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); + if (goOverride != null) + handler.SendSysMessage(CypherStrings.GoinfoAddon, goOverride.Faction, goOverride.Flags); } + + if (data != null) + { + data.rotation.toEulerAnglesZYX(out float yaw, out float pitch, out float roll); + handler.SendSysMessage(CypherStrings.SpawninfoSpawnidLocation, data.spawnId, data.spawnPoint.GetPositionX(), data.spawnPoint.GetPositionY(), data.spawnPoint.GetPositionZ()); + handler.SendSysMessage(CypherStrings.SpawninfoRotation, yaw, pitch, roll); + } + + handler.SendSysMessage(CypherStrings.GoinfoEntry, entry); + handler.SendSysMessage(CypherStrings.GoinfoType, type); + handler.SendSysMessage(CypherStrings.GoinfoLootid, lootId); + handler.SendSysMessage(CypherStrings.GoinfoDisplayid, displayId); handler.SendSysMessage(CypherStrings.GoinfoName, name); handler.SendSysMessage(CypherStrings.GoinfoSize, gameObjectInfo.size); - GameObjectOverride goOverride = null; - if (spawnId != 0) - { - GameObjectOverride ovr = Global.ObjectMgr.GetGameObjectOverride(spawnId); - if (ovr != null) - goOverride = ovr; - } - - if (goOverride == null) - goOverride = Global.ObjectMgr.GetGameObjectTemplateAddon(entry); - - if (goOverride != null) - handler.SendSysMessage(CypherStrings.GoinfoAddon, goOverride.Faction, goOverride.Flags); - handler.SendSysMessage(CypherStrings.ObjectInfoAIInfo, gameObjectInfo.AIName, Global.ObjectMgr.GetScriptName(gameObjectInfo.ScriptId)); var ai = thisGO != null ? thisGO.GetAI() : null; if (ai != null)