mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[Grids] Convert Grid/Grid Entries to Repositories (#4011)
* [Grids] Convert Grid/Grid Entries to Repositories - Convert `AddWaypoint()`, `AddWaypointForSpawn()`, `DeleteWaypoint()`, `GetHighestWaypoint()`, `GetRandomWaypointFromGrid()`, `GridExistsInZone()`, and `ModifyGrid()` to repositories. * Update grid.cpp * Update questmgr.cpp * Update waypoints.cpp * Update waypoints.cpp
This commit is contained in:
@@ -76,6 +76,48 @@ public:
|
||||
return grid_entries;
|
||||
}
|
||||
|
||||
static int GetHighestWaypoint(Database& db, uint32 zone_id, uint32 grid_id)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
SQL(
|
||||
SELECT COALESCE(MAX(`number`), 0) FROM `{}`
|
||||
WHERE `zoneid` = {} AND `gridid` = {}
|
||||
),
|
||||
TableName(),
|
||||
zone_id,
|
||||
grid_id
|
||||
)
|
||||
);
|
||||
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
return Strings::ToInt(row[0]);
|
||||
}
|
||||
|
||||
static int GetNextWaypoint(Database& db, uint32 zone_id, uint32 grid_id)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT MAX(`number`) FROM `{}` WHERE `zoneid` = {} AND `gridid` = {}",
|
||||
TableName(),
|
||||
zone_id,
|
||||
grid_id
|
||||
)
|
||||
);
|
||||
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
return Strings::ToInt(row[0]) + 1;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_GRID_ENTRIES_REPOSITORY_H
|
||||
|
||||
@@ -71,6 +71,27 @@ public:
|
||||
return grids;
|
||||
}
|
||||
|
||||
static int GetHighestGrid(Database& db, uint32 zone_id)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
SQL(
|
||||
SELECT COALESCE(MAX(`id`), 0) FROM `{}`
|
||||
WHERE `zoneid` = {}
|
||||
),
|
||||
TableName(),
|
||||
zone_id
|
||||
)
|
||||
);
|
||||
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
return Strings::ToInt(row[0]);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_GRID_REPOSITORY_H
|
||||
|
||||
@@ -44,7 +44,35 @@ public:
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
static uint32 GetPathGridBySpawn2ID(Database& db, uint32 spawn2_id)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"SELECT `pathgrid` FROM `{}` WHERE `id` = {}",
|
||||
TableName(),
|
||||
spawn2_id
|
||||
)
|
||||
);
|
||||
|
||||
if (!results.Success() || !results.RowCount()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto row = results.begin();
|
||||
|
||||
return Strings::ToUnsignedInt(row[0]);
|
||||
}
|
||||
|
||||
static void SetPathGridBySpawn2ID(Database& db, uint32 spawn2_id, uint32 grid_id)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE `spawn2` SET `pathgrid` = {} WHERE `id` = {}",
|
||||
grid_id,
|
||||
spawn2_id
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //EQEMU_SPAWN2_REPOSITORY_H
|
||||
|
||||
Reference in New Issue
Block a user