Skip to content

Commit

Permalink
prepare merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mdX7 committed Dec 27, 2023
1 parent 76b3015 commit 8978ed8
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 18 deletions.
7 changes: 7 additions & 0 deletions WowPacketParser/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@
-->
<add key="SaveTempSpawns" value="false"/>

<!--
Option: SaveExistingSpawns
Description: Spawn spawns which are already existing in db (compared by entry, position) or comment them in sql
Default: "false" (comment existing spawns in sql)
-->
<add key="SaveExistingSpawns" value="false"/>

<!--
Option: SkipOnlyVerifiedBuildUpdateRows
Description: Ship only VerifiedBuild row in update querys
Expand Down
58 changes: 48 additions & 10 deletions WowPacketParser/SQL/Builders/Spawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace WowPacketParser.SQL.Builders
[BuilderClass]
public static class Spawns
{
public static bool FloatComparison(float x, float y, float precision)
{
return Math.Abs(x - y) < precision;
}

private static bool GetTransportMap(WoWObject @object, out int mapId)
{
mapId = -1;
Expand Down Expand Up @@ -63,6 +68,25 @@ public static string Creature(Dictionary<WowGuid, Unit> units)
? units.Values.GroupBy(u => u, new SpawnComparer()).Select(x => x.First())
: units.Values.ToList();


if (!Settings.SaveExistingSpawns && SQLConnector.Enabled)
{
var spawnsDb = SQLDatabase.GetCreatures(new RowList<CreatureDB>());
var precision = 0.02f; // warning - some zones shifted by 0.2 in some cases between later expansions
foreach (var creature in unitList)
{
var existingCreature = spawnsDb.Where(p => p.Data.ID == (uint)creature.ObjectData.EntryID
&& p.Data.Map == creature.Map
&& FloatComparison((float)p.Data.PosX, creature.Movement.Position.X, precision)
&& FloatComparison((float)p.Data.PosY, creature.Movement.Position.Y, precision)
&& FloatComparison((float)p.Data.PosZ, creature.Movement.Position.Z, precision)
&& FloatComparison((float)p.Data.Orientation, creature.Movement.Orientation, precision)).FirstOrDefault();

if (existingCreature != null)
creature.ExistingDatabaseSpawn = true;
}
}

foreach (var creature in unitList)
{
Row<Creature> row = new Row<Creature>();
Expand Down Expand Up @@ -255,6 +279,16 @@ public static string Creature(Dictionary<WowGuid, Unit> units)
addonRow.Comment += " - !!! might be temporary spawn !!!";
}
}
else if (creature.IsExistingSpawn() && !Settings.SaveExistingSpawns)
{
row.CommentOut = true;
row.Comment += " - !!! already present in database !!!";
if (Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_addon))
{
addonRow.CommentOut = true;
addonRow.Comment += " - !!! already present in database !!!";
}
}
else if (creature.IsOnTransport() && badTransport)
{
row.CommentOut = true;
Expand Down Expand Up @@ -297,11 +331,6 @@ public static string Creature(Dictionary<WowGuid, Unit> units)
return result.ToString();
}

public static bool FloatComparison(float x, float y, float precision)
{
return Math.Abs(x - y) < precision;
}

[BuilderMethod(Gameobjects = true)]
public static string GameObject(Dictionary<WowGuid, GameObject> gameObjects)
{
Expand All @@ -321,13 +350,22 @@ public static string GameObject(Dictionary<WowGuid, GameObject> gameObjects)

if (!Settings.SaveExistingSpawns && SQLConnector.Enabled)
{
var templatesDb = SQLDatabase.GetGameObjects(new RowList<GameObjectDB>());
var precision = 0.000001f; // warning - some zones shifted by 0.2 in some cases between later expansions
var spawnsDb = SQLDatabase.GetGameObjects(new RowList<GameObjectDB>());
var precision = 0.02f; // warning - some zones shifted by 0.2 in some cases between later expansions
foreach (var go in gobList)
{
var staticRot = go.GetStaticRotation();
var existingGo = templatesDb.Where(p => FloatComparison((float)p.Data.PosX, go.Movement.Position.X, precision) && FloatComparison((float)p.Data.PosY, go.Movement.Position.Y, precision) && FloatComparison((float)p.Data.PosZ, go.Movement.Position.Z, precision) && FloatComparison((float)p.Data.Ori, go.Movement.Orientation, precision) &&
FloatComparison((float)p.Data.Rot0, staticRot.X, precision) && FloatComparison((float)p.Data.Rot1, staticRot.Y, precision) && FloatComparison((float)p.Data.Rot2, staticRot.Z, precision) && FloatComparison((float)p.Data.Rot3, staticRot.W, precision)).FirstOrDefault();
var existingGo = spawnsDb.Where(p => p.Data.ID == (uint)go.ObjectData.EntryID
&& p.Data.Map == go.Map
&& FloatComparison((float)p.Data.PosX, go.Movement.Position.X, precision)
&& FloatComparison((float)p.Data.PosY, go.Movement.Position.Y, precision)
&& FloatComparison((float)p.Data.PosZ, go.Movement.Position.Z, precision)
&& FloatComparison((float)p.Data.Orientation, go.Movement.Orientation, precision)
&& FloatComparison((float)p.Data.Rot0, staticRot.X, precision)
&& FloatComparison((float)p.Data.Rot1, staticRot.Y, precision)
&& (FloatComparison((float)p.Data.Rot2, staticRot.Z, precision) || FloatComparison((float)p.Data.Rot2, -staticRot.Z, precision))
&& (FloatComparison((float)p.Data.Rot3, staticRot.W, precision) || FloatComparison((float)p.Data.Rot3, -staticRot.W, precision))).FirstOrDefault();

if (existingGo != null)
go.ExistingDatabaseSpawn = true;
}
Expand Down Expand Up @@ -475,7 +513,7 @@ public static string GameObject(Dictionary<WowGuid, GameObject> gameObjects)
addonRow.Comment += " - !!! might be temporary spawn !!!";
}
}
else if (go.ExistingDatabaseSpawn && !Settings.SaveExistingSpawns)
else if (go.IsExistingSpawn() && !Settings.SaveExistingSpawns)
{
row.CommentOut = true;
row.Comment += " - !!! already present in database !!!";
Expand Down
41 changes: 40 additions & 1 deletion WowPacketParser/SQL/SQLDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,45 @@ public static RowList<T> Get<T>(RowList<T> rowList = null, string database = nul
return result;
}

public static RowList<CreatureDB> GetCreatures(RowList<CreatureDB> rowList = null, string database = null)
{
if (!SQLConnector.Enabled)
return null;

if (!SQLUtil.IsTableVisible<CreatureDB>())
return null;

var result = new RowList<CreatureDB>();

using (var command = SQLConnector.CreateCommand(new SQLSelect<CreatureDB>(rowList, database).Build()))
{
if (command == null)
return null;

var fields = SQLUtil.GetFields<CreatureDB>();
var fieldsCount = fields.Select(f => f.Item3.First().Count).Sum();
using (MySqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
var creature = new CreatureDB();

creature.DbGuid = reader.GetUInt32(0);
creature.ID = reader.GetUInt32(1);
creature.Map = reader.GetUInt32(2);
creature.PosX = reader.GetDecimal(3);
creature.PosY = reader.GetDecimal(4);
creature.PosZ = reader.GetDecimal(5);
creature.Orientation = reader.GetDecimal(6);

result.Add(creature);
}
}
}

return result;
}

public static RowList<GameObjectDB> GetGameObjects(RowList<GameObjectDB> rowList = null, string database = null)
{
if (!SQLConnector.Enabled)
Expand Down Expand Up @@ -516,7 +555,7 @@ public static RowList<GameObjectDB> GetGameObjects(RowList<GameObjectDB> rowList
go.PosX = reader.GetDecimal(3);
go.PosY = reader.GetDecimal(4);
go.PosZ = reader.GetDecimal(5);
go.Ori = reader.GetDecimal(6);
go.Orientation = reader.GetDecimal(6);
go.Rot0 = reader.GetDecimal(7);
go.Rot1 = reader.GetDecimal(8);
go.Rot2 = reader.GetDecimal(9);
Expand Down
23 changes: 23 additions & 0 deletions WowPacketParser/Store/Objects/CreatureDB.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using WowPacketParser.SQL;

namespace WowPacketParser.Store.Objects
{
[DBTableName("creature")]
public sealed record CreatureDB : IDataModel
{
[DBFieldName("guid", true)]
public uint DbGuid;
[DBFieldName("id")]
public uint ID;
[DBFieldName("map")]
public uint Map;
[DBFieldName("position_x")]
public decimal PosX;
[DBFieldName("position_y")]
public decimal PosY;
[DBFieldName("position_z")]
public decimal PosZ;
[DBFieldName("orientation")]
public decimal Orientation;
}
}
9 changes: 2 additions & 7 deletions WowPacketParser/Store/Objects/GameObjectDB.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WowPacketParser.SQL;
using WowPacketParser.SQL;

namespace WowPacketParser.Store.Objects
{
Expand All @@ -23,7 +18,7 @@ public sealed record GameObjectDB : IDataModel
[DBFieldName("position_z")]
public decimal PosZ;
[DBFieldName("orientation")]
public decimal Ori;
public decimal Orientation;
[DBFieldName("rotation0")]
public decimal Rot0;
[DBFieldName("rotation1")]
Expand Down
6 changes: 6 additions & 0 deletions WowPacketParser/Store/Objects/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public sealed record Unit : WoWObject
public UnitDynamicFlagsWOD? DynamicFlagsWod;

public IUnitData UnitData;
public bool ExistingDatabaseSpawn { get; set; }

public Unit() : base()
{
Expand Down Expand Up @@ -88,5 +89,10 @@ public CreatureEquipment GetEquipment()
ItemVisual3 = equipment[2].ItemVisual
};
}

public override bool IsExistingSpawn()
{
return ExistingDatabaseSpawn;
}
}
}

0 comments on commit 8978ed8

Please sign in to comment.