mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-17 03:08:26 +00:00
[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user