[Pets] Convert Pets to Repositories (#3968)

* [Pets] Convert Pets to Repositories

# Notes
- Convert `GetPoweredPetEntry()` to repositories.

* Update pets.cpp
This commit is contained in:
Alex King 2024-01-12 23:41:56 -05:00 committed by GitHub
parent eb33e5a064
commit 8cb15f9357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 27 deletions

View File

@ -20,6 +20,8 @@
#include "../common/spdat.h"
#include "../common/strings.h"
#include "../common/repositories/pets_repository.h"
#include "entity.h"
#include "client.h"
#include "mob.h"
@ -369,38 +371,35 @@ Pet::Pet(NPCType *type_data, Mob *owner, PetType type, uint16 spell_id, int16 po
// Class should use npc constructor to set light properties
}
bool ZoneDatabase::GetPetEntry(const char *pet_type, PetRecord *into) {
return GetPoweredPetEntry(pet_type, 0, into);
bool ZoneDatabase::GetPetEntry(const std::string& pet_type, PetRecord *p)
{
return GetPoweredPetEntry(pet_type, 0, p);
}
bool ZoneDatabase::GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into) {
std::string query;
bool ZoneDatabase::GetPoweredPetEntry(const std::string& pet_type, int16 pet_power, PetRecord* r)
{
const auto& l = PetsRepository::GetWhere(
*this,
fmt::format(
"`type` = '{}' AND `petpower` <= {} ORDER BY `petpower` DESC LIMIT 1",
pet_type,
pet_power <= 0 ? 0 : pet_power
)
);
if (petpower <= 0)
query = StringFormat("SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset "
"FROM pets WHERE type='%s' AND petpower<=0", pet_type);
else
query = StringFormat("SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset "
"FROM pets WHERE type='%s' AND petpower<=%d ORDER BY petpower DESC LIMIT 1",
pet_type, petpower);
auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
if (l.empty()) {
return false;
}
if (results.RowCount() != 1)
return false;
auto e = l.front();
auto row = results.begin();
into->npc_type = Strings::ToInt(row[0]);
into->temporary = Strings::ToInt(row[1]);
into->petpower = Strings::ToInt(row[2]);
into->petcontrol = Strings::ToInt(row[3]);
into->petnaming = Strings::ToInt(row[4]);
into->monsterflag = Strings::ToInt(row[5]);
into->equipmentset = Strings::ToInt(row[6]);
r->npc_type = e.npcID;
r->temporary = e.temp;
r->petpower = e.petpower;
r->petcontrol = e.petcontrol;
r->petnaming = e.petnaming;
r->monsterflag = e.monsterflag;
r->equipmentset = e.equipmentset;
return true;
}

View File

@ -560,8 +560,8 @@ public:
uint32 AddNPCTypes(const char* zone, uint32 zone_version, Client *client, NPC* spawn, uint32 spawnGroupID);
uint32 UpdateNPCTypeAppearance(Client *client, NPC* spawn);
bool SetSpecialAttkFlag(uint8 id, const char* flag);
bool GetPetEntry(const char *pet_type, PetRecord *into);
bool GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into);
bool GetPetEntry(const std::string& pet_type, PetRecord* r);
bool GetPoweredPetEntry(const std::string& pet_type, int16 pet_power, PetRecord* r);
bool GetBasePetItems(int32 equipmentset, uint32 *items);
BeastlordPetData::PetStruct GetBeastlordPetData(uint16 race_id);
void AddLootTableToNPC(NPC* npc, uint32 loottable_id, ItemList* itemlist, uint32* copper, uint32* silver, uint32* gold, uint32* plat);