Add rotation to .gob info

Port From (https://github.com/TrinityCore/TrinityCore/commit/afac2b174290c871d845e37f88c6f0c874d15fd6)
This commit is contained in:
hondacrx
2021-11-15 23:06:07 -05:00
parent 5b65a04358
commit 2aa910e9f6
3 changed files with 64 additions and 39 deletions
+1 -1
View File
@@ -1105,7 +1105,7 @@ namespace Framework.Constants
SpawninfoCompatibilityMode = 5071,
SpawninfoGuidinfo = 5072,
SpawninfoSpawnidLocation = 5073,
SpawninfoDistancefromplayer = 5074,
SpawninfoRotation = 5074,
SpawngroupBadgroup = 5075,
SpawngroupSpawncount = 5076,
ListRespawnsRange = 5077,
+32
View File
@@ -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);
+30 -37
View File
@@ -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)