From eb33e5a064e9d40f1e18e2d157843bd310e6b10e Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:41:08 -0500 Subject: [PATCH] [Ground Spawns] Convert Ground Spawns to Repositories (#3967) # Notes - Convert `LoadGroundSpawns()` to repositories. --- common/eq_packet_structs.h | 6 +-- common/patches/rof2_structs.h | 6 +-- common/patches/rof_structs.h | 6 +-- common/patches/sod_structs.h | 6 +-- common/patches/sof_structs.h | 6 +-- common/patches/titanium_structs.h | 8 ++-- common/patches/uf_structs.h | 6 +-- zone/object.cpp | 62 +++++++++++++++++-------------- zone/zone.cpp | 2 +- zone/zonedb.h | 2 +- 10 files changed, 58 insertions(+), 52 deletions(-) diff --git a/common/eq_packet_structs.h b/common/eq_packet_structs.h index 55c8a500e..08f66c46b 100644 --- a/common/eq_packet_structs.h +++ b/common/eq_packet_structs.h @@ -3445,7 +3445,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -3457,8 +3457,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/rof2_structs.h b/common/patches/rof2_structs.h index f1a9b111c..66f183599 100644 --- a/common/patches/rof2_structs.h +++ b/common/patches/rof2_structs.h @@ -3619,7 +3619,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -3631,8 +3631,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/rof_structs.h b/common/patches/rof_structs.h index c5ce0e702..202a6a6df 100644 --- a/common/patches/rof_structs.h +++ b/common/patches/rof_structs.h @@ -3556,7 +3556,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -3568,8 +3568,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/sod_structs.h b/common/patches/sod_structs.h index 9d6e36e80..3a2586f58 100644 --- a/common/patches/sod_structs.h +++ b/common/patches/sod_structs.h @@ -3026,7 +3026,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -3038,8 +3038,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/sof_structs.h b/common/patches/sof_structs.h index 9f8d48eb1..f6fe8ee69 100644 --- a/common/patches/sof_structs.h +++ b/common/patches/sof_structs.h @@ -2951,7 +2951,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -2963,8 +2963,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/titanium_structs.h b/common/patches/titanium_structs.h index 15537013f..ae89fe385 100644 --- a/common/patches/titanium_structs.h +++ b/common/patches/titanium_structs.h @@ -1,5 +1,5 @@ /* EQEMu: Everquest Server Emulator - + Copyright (C) 2001-2016 EQEMu Development Team (http://eqemulator.net) This program is free software; you can redistribute it and/or modify @@ -2604,7 +2604,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -2616,8 +2616,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/common/patches/uf_structs.h b/common/patches/uf_structs.h index 15c49ab26..a009399e9 100644 --- a/common/patches/uf_structs.h +++ b/common/patches/uf_structs.h @@ -3078,7 +3078,7 @@ struct Make_Pet_Struct { //Simple struct for getting pet info uint32 min_dmg; uint32 max_dmg; }; -struct Ground_Spawn{ +struct GroundSpawn{ float max_x; float max_y; float min_x; @@ -3090,8 +3090,8 @@ struct Ground_Spawn{ uint32 max_allowed; uint32 respawntimer; }; -struct Ground_Spawns { - struct Ground_Spawn spawn[50]; //Assigned max number to allow +struct GroundSpawns { + struct GroundSpawn spawn[50]; //Assigned max number to allow }; //struct PetitionBug_Struct{ diff --git a/zone/object.cpp b/zone/object.cpp index cfb42ddad..ef0a24ec5 100644 --- a/zone/object.cpp +++ b/zone/object.cpp @@ -29,6 +29,7 @@ #include "zonedb.h" #include "../common/repositories/criteria/content_filter_criteria.h" #include "../common/events/player_event_logs.h" +#include "../common/repositories/ground_spawns_repository.h" const char DEFAULT_OBJECT_NAME[] = "IT63_ACTORDEF"; @@ -748,39 +749,44 @@ void ZoneDatabase::UpdateObject(uint32 id, uint32 type, uint32 icon, const Objec } } -// -Ground_Spawns* ZoneDatabase::LoadGroundSpawns(uint32 zone_id, int16 version, Ground_Spawns* gs) { - - std::string query = StringFormat( - "SELECT max_x, max_y, max_z, " - "min_x, min_y, heading, name, " - "item, max_allowed, respawn_timer " - "FROM ground_spawns " - "WHERE zoneid = %i AND (version = %u OR version = -1) %s " - "LIMIT 50", - zone_id, - version, - ContentFilterCriteria::apply().c_str() +GroundSpawns* ZoneDatabase::LoadGroundSpawns( + uint32 zone_id, + int16 instance_version, + GroundSpawns* gs +) +{ + const auto& l = GroundSpawnsRepository::GetWhere( + *this, + fmt::format( + "`zoneid` = {} AND (`version` = {} OR `version` = -1) {} LIMIT 50", + zone_id, + instance_version, + ContentFilterCriteria::apply() + ) ); - auto results = QueryDatabase(query); - if (!results.Success()) { + if (l.empty()) { return gs; } - int spawnIndex=0; - for (auto row = results.begin(); row != results.end(); ++row, ++spawnIndex) { - gs->spawn[spawnIndex].max_x=Strings::ToFloat(row[0]); - gs->spawn[spawnIndex].max_y=Strings::ToFloat(row[1]); - gs->spawn[spawnIndex].max_z=Strings::ToFloat(row[2]); - gs->spawn[spawnIndex].min_x=Strings::ToFloat(row[3]); - gs->spawn[spawnIndex].min_y=Strings::ToFloat(row[4]); - gs->spawn[spawnIndex].heading=Strings::ToFloat(row[5]); - strcpy(gs->spawn[spawnIndex].name,row[6]); - gs->spawn[spawnIndex].item=Strings::ToInt(row[7]); - gs->spawn[spawnIndex].max_allowed=Strings::ToInt(row[8]); - gs->spawn[spawnIndex].respawntimer=Strings::ToInt(row[9]); - } + uint32 slot_id = 0; + + for (const auto& e : l) { + strcpy(gs->spawn[slot_id].name, e.name.c_str()); + + gs->spawn[slot_id].max_x = e.max_x; + gs->spawn[slot_id].max_y = e.max_y; + gs->spawn[slot_id].max_z = e.max_z; + gs->spawn[slot_id].min_x = e.min_x; + gs->spawn[slot_id].min_y = e.min_y; + gs->spawn[slot_id].heading = e.heading; + gs->spawn[slot_id].item = e.item; + gs->spawn[slot_id].max_allowed = e.max_allowed; + gs->spawn[slot_id].respawntimer = e.respawn_timer; + + slot_id++; + } + return gs; } diff --git a/zone/zone.cpp b/zone/zone.cpp index 219a98805..f9b078aa3 100644 --- a/zone/zone.cpp +++ b/zone/zone.cpp @@ -349,7 +349,7 @@ bool Zone::IsSpecialBindLocation(const glm::vec4& location) //this also just loads into entity_list, not really into zone bool Zone::LoadGroundSpawns() { - Ground_Spawns groundspawn; + GroundSpawns groundspawn; memset(&groundspawn, 0, sizeof(groundspawn)); int gsindex=0; diff --git a/zone/zonedb.h b/zone/zonedb.h index aa8330c5c..ba997a0f1 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -381,7 +381,7 @@ public: uint32 AddObject(uint32 type, uint32 icon, const Object_Struct& object, const EQ::ItemInstance* inst); void UpdateObject(uint32 id, uint32 type, uint32 icon, const Object_Struct& object, const EQ::ItemInstance* inst); void DeleteObject(uint32 id); - Ground_Spawns* LoadGroundSpawns(uint32 zone_id, int16 version, Ground_Spawns* gs); + GroundSpawns* LoadGroundSpawns(uint32 zone_id, int16 instance_version, GroundSpawns* gs); /* Traders */ void SaveTraderItem(uint32 char_id,uint32 itemid,uint32 uniqueid, int32 charges,uint32 itemcost,uint8 slot);