Skip to content

Commit 48584b2

Browse files
committed
Fix waypoint sql output for TrinityCore
1 parent 8528526 commit 48584b2

1 file changed

Lines changed: 25 additions & 26 deletions

File tree

WowPacketParser/SQL/Builders/Movement.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using WowPacketParser.Enums;
2-
using WowPacketParser.Misc;
3-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using System.Globalization;
3+
using System.Linq;
44
using System.Text;
5+
using WowPacketParser.Enums;
6+
using WowPacketParser.Misc;
7+
using WowPacketParser.PacketStructures;
58
using WowPacketParser.Parsing.Proto;
69
using WowPacketParser.Proto;
7-
using WowPacketParser.PacketStructures;
8-
using System.IO;
9-
using Org.BouncyCastle.Crypto.Digests;
1010

1111
namespace WowPacketParser.SQL.Builders
1212
{
@@ -16,7 +16,7 @@ public class Movement : BaseProtoQueryBuilder
1616
private struct Waypoint
1717
{
1818
public Vec3 Position { get; init; }
19-
public float Orientation { get; init; }
19+
public float? Orientation { get; init; }
2020
public bool Point { get; init; }
2121
}
2222

@@ -78,33 +78,30 @@ protected override VoidType Process(PacketBase basePacket, PacketMonsterMove pac
7878
Type = movementType
7979
};
8080

81-
for (var index = 0; index < packet.PackedPoints.Count; index++)
81+
foreach (var node in packet.PackedPoints)
8282
{
83-
var node = packet.PackedPoints[index];
84-
bool finalP = packet.Destination == null && packet.PackedPoints.Count - 1 != index;
8583
path.Waypoints.Add(new Waypoint()
8684
{
8785
Position = node,
88-
Orientation = 100,
86+
Orientation = null,
8987
Point = false
9088
});
9189
}
9290

93-
for (var index = 0; index < packet.Points.Count; index++)
91+
foreach (var node in packet.Points)
9492
{
95-
var node = packet.Points[index];
9693
path.Waypoints.Add(new Waypoint()
9794
{
9895
Position = node,
99-
Orientation = 100,
96+
Orientation = null,
10097
Point = true
10198
});
10299
}
103100

104101
bool dest = false;
105102
if (packet.Destination != null && !(packet.Destination.X == 0 && packet.Destination.Y == 0 && packet.Destination.Z == 0))
106103
{
107-
float ori = packet.HasLookOrientation ? packet.LookOrientation : 100f;
104+
float? ori = packet.HasLookOrientation ? packet.LookOrientation : null;
108105
path.Waypoints.Add(new Waypoint()
109106
{
110107
Position = packet.Destination,
@@ -131,7 +128,7 @@ protected override VoidType Process(PacketBase basePacket, PacketMonsterMove pac
131128
protected override string GenerateQuery()
132129
{
133130
StringBuilder output = new();
134-
output.AppendLine("SET @MOVID = 0;");
131+
output.AppendLine("SET @MOVID := SET_VALUE_MANUALLY_HERE;");
135132
int pathIdCounter = 0;
136133
foreach (var (mover, paths) in pathsPerGuid)
137134
{
@@ -144,30 +141,32 @@ protected override string GenerateQuery()
144141
}
145142
else if (Settings.TargetedProject == TargetedProject.TrinityCore)
146143
{
147-
output.AppendLine("INSERT INTO waypoint_path_node (PathId, NodeId, PositionX, PositionY, PositionZ, Orientation, Delay) VALUES");
144+
var types = paths.Paths.Select(k => k.Type).Distinct().ToArray();
145+
var flags = types.Length == 1 && types[0] is PathType.ExactPath or PathType.ExactPathFlying or PathType.ExactPathFlyingCyclic ? 2 : 0;
146+
147+
output.AppendLine("INSERT INTO waypoint_path (`PathId`, `MoveType`, `Flags`, `Velocity`, `Comment`) VALUES");
148+
output.AppendLine($"(@MOVID + {pathIdCounter}, 0, {flags}, NULL, '{SQLUtil.EscapeString(StoreGetters.GetName(Utilities.ObjectTypeToStore(mover.Type.ToObjectType()), (int)mover.Entry))}');");
149+
output.AppendLine("INSERT INTO waypoint_path_node (`PathId`, `NodeId`, `PositionX`, `PositionY`, `PositionZ`, `Orientation`) VALUES");
148150
}
149151
int pointIdCounter = 1;
150152
foreach (var path in paths.Paths)
151-
{
153+
{
152154
foreach (var node in path.Waypoints)
153155
{
154156
if (node.Point == false)
155157
{
156-
if (Settings.SkipIntermediatePoints == true)
158+
if (Settings.SkipIntermediatePoints)
157159
continue;
158160
output.Append("-- ");
159161
}
160162

161163
var isLast = pointIdCounter == paths.PointCount;
162164
if (Settings.TargetedProject == TargetedProject.Cmangos)
163-
output.Append($"(@MOVID + {pathIdCounter}, '{pointIdCounter}', '{node.Position.X}', '{node.Position.Y}', '{node.Position.Z}', '{node.Orientation}', '0', '0', NULL)");
165+
output.Append($"(@MOVID + {pathIdCounter}, '{pointIdCounter}', '{node.Position.X}', '{node.Position.Y}', '{node.Position.Z}', '{node.Orientation ?? 100.0f}', '0', '0', NULL)");
164166
else if (Settings.TargetedProject == TargetedProject.TrinityCore)
165-
output.Append($"(@MOVID + {pathIdCounter}, '{pointIdCounter}', '{node.Position.X}', '{node.Position.Y}', '{node.Position.Z}', '{node.Orientation}')");
167+
output.Append($"(@MOVID + {pathIdCounter}, {pointIdCounter}, {node.Position.X}, {node.Position.Y}, {node.Position.Z}, {(node.Orientation.HasValue ? node.Orientation.Value.ToString(CultureInfo.InvariantCulture) : "NULL")})");
166168

167-
if (!isLast)
168-
output.Append(",");
169-
else
170-
output.Append(";");
169+
output.Append(!isLast ? ',' : ';');
171170

172171
if (pointIdCounter == 1)
173172
output.Append($" -- PathType: {path.Type}");
@@ -177,7 +176,7 @@ protected override string GenerateQuery()
177176
++pointIdCounter;
178177
}
179178
}
180-
179+
181180
output.AppendLine();
182181

183182
++pathIdCounter;

0 commit comments

Comments
 (0)