From b87c5484b1ba303dd076f0836aee10ac68ce063c Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Jun 2021 16:57:14 -0400 Subject: [PATCH] [Pets] Unhardcode Beastlord pet values. (#1379) * [Pets] Unhardcode Beastlord pet values. - Create a Beastlord pets table to allow server operators to easily customize Beastlord pets without a source modification. * Add table to schema. --- common/database_schema.h | 1 + common/version.h | 2 +- utils/sql/db_update_manifest.txt | 1 + .../required/2021_06_06_beastlord_pets.sql | 28 ++++++++ zone/pets.cpp | 69 ++++++++++--------- zone/zonedb.h | 14 ++++ 6 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 utils/sql/git/required/2021_06_06_beastlord_pets.sql diff --git a/common/database_schema.h b/common/database_schema.h index b338a9bc5..25bc70f22 100644 --- a/common/database_schema.h +++ b/common/database_schema.h @@ -217,6 +217,7 @@ namespace DatabaseSchema { "npc_types_tint", "object", "pets", + "pets_beastlord_data", "pets_equipmentset", "pets_equipmentset_entries", "proximities", diff --git a/common/version.h b/common/version.h index e04ba3418..514bed8c7 100644 --- a/common/version.h +++ b/common/version.h @@ -34,7 +34,7 @@ * Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt */ -#define CURRENT_BINARY_DATABASE_VERSION 9166 +#define CURRENT_BINARY_DATABASE_VERSION 9167 #ifdef BOTS #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9028 diff --git a/utils/sql/db_update_manifest.txt b/utils/sql/db_update_manifest.txt index 8efa47aa9..8fd174822 100644 --- a/utils/sql/db_update_manifest.txt +++ b/utils/sql/db_update_manifest.txt @@ -420,6 +420,7 @@ 9164|2021_04_23_character_exp_modifiers.sql|SHOW TABLES LIKE 'character_exp_modifiers'|empty| 9165|2021_04_28_idle_pathing.sql|SHOW COLUMNS FROM `spawn2` LIKE 'path_when_zone_idle'|empty| 9166|2021_02_12_dynamic_zone_members.sql|SHOW TABLES LIKE 'dynamic_zone_members'|empty| +9167|2021_06_06_beastlord_pets.sql|SHOW TABLES LIKE 'pets_beastlord_data'|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/required/2021_06_06_beastlord_pets.sql b/utils/sql/git/required/2021_06_06_beastlord_pets.sql new file mode 100644 index 000000000..afa9229c0 --- /dev/null +++ b/utils/sql/git/required/2021_06_06_beastlord_pets.sql @@ -0,0 +1,28 @@ +SET NAMES utf8mb4; +SET FOREIGN_KEY_CHECKS = 0; + +-- ---------------------------- +-- Table structure for pets_beastlord_data +-- ---------------------------- +DROP TABLE IF EXISTS `pets_beastlord_data`; +CREATE TABLE `pets_beastlord_data` ( + `player_race` int UNSIGNED NOT NULL DEFAULT 1, + `pet_race` int UNSIGNED NOT NULL DEFAULT 42, + `texture` tinyint UNSIGNED NOT NULL DEFAULT 0, + `helm_texture` tinyint UNSIGNED NOT NULL DEFAULT 0, + `gender` tinyint UNSIGNED NOT NULL DEFAULT 2, + `size_modifier` float UNSIGNED NULL DEFAULT 1, + `face` tinyint UNSIGNED NOT NULL DEFAULT 0, + PRIMARY KEY (`player_race`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Compact; + +-- ---------------------------- +-- Records of pets_beastlord_data +-- ---------------------------- +INSERT INTO `pets_beastlord_data` VALUES (2, 42, 2, 0, 2, 1, 0); -- Barbarian +INSERT INTO `pets_beastlord_data` VALUES (9, 91, 0, 0, 2, 2.5, 0); -- Troll +INSERT INTO `pets_beastlord_data` VALUES (10, 43, 3, 0, 2, 1, 0); -- Ogre +INSERT INTO `pets_beastlord_data` VALUES (128, 42, 0, 0, 1, 2, 0); -- Iksar +INSERT INTO `pets_beastlord_data` VALUES (130, 63, 0, 0, 2, 0.8, 0); -- Vah Shir + +SET FOREIGN_KEY_CHECKS = 1; \ No newline at end of file diff --git a/zone/pets.cpp b/zone/pets.cpp index e88f0f246..1c833f088 100644 --- a/zone/pets.cpp +++ b/zone/pets.cpp @@ -299,39 +299,16 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower, strcat(npc_type->name, "`s_pet"); } - //handle beastlord pet appearance - if(record.petnaming == 2) - { - switch(GetBaseRace()) - { - case VAHSHIR: - npc_type->race = TIGER; - npc_type->size *= 0.8f; - break; - case TROLL: - npc_type->race = ALLIGATOR; - npc_type->size *= 2.5f; - break; - case OGRE: - npc_type->race = BEAR; - npc_type->texture = 3; - npc_type->gender = 2; - break; - case BARBARIAN: - npc_type->race = WOLF; - npc_type->texture = 2; - break; - case IKSAR: - npc_type->race = WOLF; - npc_type->texture = 0; - npc_type->gender = 1; - npc_type->size *= 2.0f; - npc_type->luclinface = 0; - break; - default: - npc_type->race = WOLF; - npc_type->texture = 0; - } + // Beastlord Pets + 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; } // handle monster summoning pet appearance @@ -716,3 +693,29 @@ bool Pet::CheckSpellLevelRestriction(uint16 spell_id) return owner->CheckSpellLevelRestriction(spell_id); return true; } + +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; + } + + auto row = results.begin(); + beastlord_pet_data.race_id = atoi(row[0]); + beastlord_pet_data.texture = atoi(row[1]); + beastlord_pet_data.helm_texture = atoi(row[2]); + beastlord_pet_data.gender = atoi(row[3]); + beastlord_pet_data.size_modifier = atof(row[4]); + beastlord_pet_data.face = atoi(row[5]); + return beastlord_pet_data; +} diff --git a/zone/zonedb.h b/zone/zonedb.h index d7e41ecb0..e05e0872a 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -15,6 +15,8 @@ #include "bot_database.h" #endif +#define WOLF 42 + class Client; class Corpse; class Merc; @@ -243,6 +245,17 @@ struct ClientMercEntry { uint32 npcid; }; +namespace BeastlordPetData { + struct PetStruct { + uint16 race_id = WOLF; + uint8 texture = 0; + uint8 helm_texture = 0; + uint8 gender = 2; + float size_modifier = 1.0f; + uint8 face = 0; + }; +} + class ZoneDatabase : public SharedDatabase { typedef std::list ItemList; public: @@ -458,6 +471,7 @@ public: bool GetPetEntry(const char *pet_type, PetRecord *into); bool GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into); 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); void AddLootDropToNPC(NPC* npc, uint32 lootdrop_id, ItemList* item_list, uint8 droplimit, uint8 mindrop); uint32 GetMaxNPCSpellsID();