[Pets] Convert Load of Pets Beastlord Data to Repositories (#3995)

* [Pets] Convert Load of Pets Beastlord Data to Repositories

# Notes
- Convert `GetBeastlordPetData()` to repositories.
- Add support for `unsigned` versions of `float`, `double`, and `decimal`, without this we defaulted to `std::string`, such as with `pets_beastlord_data`.

* Update repository-generator.pl

---------

Co-authored-by: Chris Miles <akkadius1@gmail.com>
This commit is contained in:
Alex King 2024-01-29 00:05:43 -05:00 committed by GitHub
parent a1f2a21c99
commit b89772ca91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 45 deletions

View File

@ -19,13 +19,13 @@
class BasePetsBeastlordDataRepository {
public:
struct PetsBeastlordData {
uint32_t player_race;
uint32_t pet_race;
uint8_t texture;
uint8_t helm_texture;
uint8_t gender;
std::string size_modifier;
uint8_t face;
uint32_t player_race;
uint32_t pet_race;
uint8_t texture;
uint8_t helm_texture;
uint8_t gender;
float size_modifier;
uint8_t face;
};
static std::string PrimaryKey()

View File

@ -566,9 +566,12 @@ sub translate_mysql_data_type_to_c
elsif ($mysql_data_type =~ /int/) {
$struct_data_type = 'uint32_t';
}
elsif ($mysql_data_type =~ /float|decimal/) {
elsif ($mysql_data_type =~ /float|decimal/i) {
$struct_data_type = 'float';
}
elsif ($mysql_data_type =~ /double/i) {
$struct_data_type = 'double';
}
}
elsif ($mysql_data_type =~ /bigint/) {
$struct_data_type = 'int64_t';

View File

@ -21,6 +21,7 @@
#include "../common/strings.h"
#include "../common/repositories/pets_repository.h"
#include "../common/repositories/pets_beastlord_data_repository.h"
#include "entity.h"
#include "client.h"
@ -196,15 +197,18 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower,
}
// Beastlord Pets
if(record.petnaming == 2) {
if (record.petnaming == 2) {
uint16 race_id = GetBaseRace();
auto beastlord_pet_data = content_db.GetBeastlordPetData(race_id);
npc_type->race = beastlord_pet_data.race_id;
npc_type->texture = beastlord_pet_data.texture;
npc_type->helmtexture = beastlord_pet_data.helm_texture;
npc_type->gender = beastlord_pet_data.gender;
npc_type->size *= beastlord_pet_data.size_modifier;
npc_type->luclinface = beastlord_pet_data.face;
auto d = content_db.GetBeastlordPetData(race_id);
npc_type->race = d.race_id;
npc_type->texture = d.texture;
npc_type->helmtexture = d.helm_texture;
npc_type->gender = d.gender;
npc_type->luclinface = d.face;
npc_type->size *= d.size_modifier;
}
// handle monster summoning pet appearance
@ -655,27 +659,20 @@ bool Pet::CheckSpellLevelRestriction(Mob *caster, uint16 spell_id)
}
BeastlordPetData::PetStruct ZoneDatabase::GetBeastlordPetData(uint16 race_id) {
BeastlordPetData::PetStruct beastlord_pet_data;
std::string query = fmt::format(
SQL(
SELECT
`pet_race`, `texture`, `helm_texture`, `gender`, `size_modifier`, `face`
FROM `pets_beastlord_data`
WHERE `player_race` = {}
),
race_id
);
auto results = QueryDatabase(query);
if (!results.Success() || results.RowCount() != 1) {
return beastlord_pet_data;
BeastlordPetData::PetStruct d;
const auto& e = PetsBeastlordDataRepository::FindOne(*this, race_id);
if (!e.player_race) {
return d;
}
auto row = results.begin();
beastlord_pet_data.race_id = Strings::ToInt(row[0]);
beastlord_pet_data.texture = Strings::ToInt(row[1]);
beastlord_pet_data.helm_texture = Strings::ToInt(row[2]);
beastlord_pet_data.gender = Strings::ToInt(row[3]);
beastlord_pet_data.size_modifier = Strings::ToFloat(row[4]);
beastlord_pet_data.face = Strings::ToInt(row[5]);
return beastlord_pet_data;
d.race_id = e.pet_race;
d.texture = e.texture;
d.helm_texture = e.helm_texture;
d.gender = e.gender;
d.size_modifier = e.size_modifier;
d.face = e.face;
return d;
}

View File

@ -15,8 +15,6 @@
#include "bot_database.h"
#define WOLF 42
class Client;
class Corpse;
class Merc;
@ -337,12 +335,12 @@ struct CharacterCorpseEntry
namespace BeastlordPetData {
struct PetStruct {
uint16 race_id = WOLF;
uint8 texture = 0;
uint8 helm_texture = 0;
uint8 gender = Gender::Neuter;
float size_modifier = 1.0f;
uint8 face = 0;
uint16 race_id = Race::Wolf;
uint8 texture = 0;
uint8 helm_texture = 0;
uint8 gender = Gender::Neuter;
float size_modifier = 1.0f;
uint8 face = 0;
};
}