forked from BAndysc/WoWDatabaseEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into dev
- Loading branch information
Showing
6 changed files
with
118 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
WDE.PacketViewer/Processing/Processors/Paths/CmangosPathSniffWaypointsExporter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using WDE.Module.Attributes; | ||
using WDE.SqlQueryGenerator; | ||
using WowPacketParser.Proto; | ||
|
||
namespace WDE.PacketViewer.Processing.Processors.Paths; | ||
|
||
[AutoRegister] | ||
[RequiresCore("CMaNGOS-Classic", "CMaNGOS-TBC", "CMaNGOS-WoTLK")] | ||
public class CmangosPathSniffWaypointsExporter : ISniffWaypointsExporter | ||
{ | ||
public string Id => "cmangos_script_waypoints"; | ||
|
||
public string Name => "CMaNGOS Script Waypoints (`waypoints`)"; | ||
|
||
public override string ToString() => Name; | ||
|
||
public async Task Export(StringBuilder sb, int basePathNum, UniversalGuid guid, IWaypointProcessor.UnitMovementState state, float randomness) | ||
{ | ||
var q = Queries.BeginTransaction(); | ||
List<object> toInsert = new(); | ||
|
||
uint pathEntry = guid.Entry; | ||
|
||
if (basePathNum > 0) | ||
pathEntry = (uint)(guid.Entry * 100 + (basePathNum - 1)); | ||
|
||
foreach (var path in state.Paths) | ||
{ | ||
bool outOfRange = pathEntry > guid.Entry * 100 + 99; | ||
|
||
if (outOfRange) | ||
q.StartBlockComment("Those paths are out of range, because a single entry can have up to 100 paths"); | ||
|
||
int pointid = 1; | ||
q.Table("waypoint_path").Where(row => row.Column<uint>("PathId") == pathEntry).Delete(); | ||
toInsert.Clear(); | ||
foreach (var segment in path.Segments) | ||
{ | ||
for (var index = 0; index < segment.Waypoints.Count; index++) | ||
{ | ||
var isFirst = index == 0; | ||
var isLast = index == segment.Waypoints.Count - 1; | ||
|
||
var waypoint = segment.Waypoints[index]; | ||
toInsert.Add(new | ||
{ | ||
PathId = pathEntry, | ||
Point = pointid++, | ||
PositionX = waypoint.X, | ||
PositionY = waypoint.Y, | ||
PositionZ = waypoint.Z, | ||
Orientation = isLast ? segment.FinalOrientation : null, | ||
WaitTime = isFirst ? (int)(segment.Wait?.TotalMilliseconds ?? 0) : 0 | ||
}); | ||
} | ||
} | ||
|
||
if (toInsert.Count > 0) | ||
q.Table("waypoint_path").BulkInsert(toInsert); | ||
|
||
if (outOfRange) | ||
q.EndBlockComment(); | ||
|
||
if (pathEntry == guid.Entry) | ||
pathEntry = guid.Entry * 100; | ||
else | ||
pathEntry++; | ||
|
||
q.BlankLine(); | ||
} | ||
|
||
sb.AppendLine(q.Close().QueryString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters