[Commands] Convert NPC Spawn Methods to Repositories (#3956)

* [Commands] Convert NPC Spawn Methods to Repositories

# Notes
- Convert `AddNewNPCSpawnGroupCommand()`, `AddNPCTypes()`, `AddSpawnFromSpawnGroup()`, `CreateNewNPCCommand()`, `DeleteSpawnLeaveInNPCTypeTable()`, `DeleteSpawnRemoveFromNPCTypeTable()`, `NPCSpawnDB()`, and `UpdateNPCTypeAppearance()`.

* Regenerate.

* Cleanup.
This commit is contained in:
Alex King
2024-01-13 00:02:19 -05:00
committed by GitHub
parent 6968a70310
commit e182d685d3
4 changed files with 309 additions and 248 deletions
@@ -16,6 +16,7 @@
#include "../../strings.h"
#include <ctime>
class BaseSpawngroupRepository {
public:
struct Spawngroup {
@@ -44,7 +44,32 @@ public:
*/
// Custom extended repository methods here
static uint32 GetOpenIDInZoneRange(Database& db, uint32 zone_id)
{
const uint32 min_id = zone_id * 1000;
const uint32 max_id = min_id + 999;
auto results = db.QueryDatabase(
fmt::format(
"SELECT MAX({}) FROM `{}` WHERE `{}` BETWEEN {} AND {}",
PrimaryKey(),
TableName(),
PrimaryKey(),
min_id,
max_id
)
);
if (!results.Success() || !results.RowCount()) {
return 0;
}
auto row = results.begin();
const uint32 npc_id = row[0] ? Strings::ToUnsignedInt(row[0]) + 1 : 0;
return npc_id < max_id ? npc_id : 0;
}
};
#endif //EQEMU_NPC_TYPES_REPOSITORY_H