From 8b89beb02ebe992615fc2eca2646c365c0db3f07 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Mon, 18 Aug 2014 21:57:29 -0700 Subject: [PATCH] MakePoweredPet converted to QueryDatabase --- zone/pets.cpp | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/zone/pets.cpp b/zone/pets.cpp index c7b4b1eac..a3887e6f2 100644 --- a/zone/pets.cpp +++ b/zone/pets.cpp @@ -362,31 +362,34 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower, // handle monster summoning pet appearance if(record.monsterflag) { - char errbuf[MYSQL_ERRMSG_SIZE]; - char* query = 0; - MYSQL_RES *result = nullptr; - MYSQL_ROW row = nullptr; - uint32 monsterid; + + uint32 monsterid = 0; // get a random npc id from the spawngroups assigned to this zone - if (database.RunQuery(query, MakeAnyLenString(&query, - "SELECT npcID FROM (spawnentry INNER JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID) " - "INNER JOIN npc_types ON npc_types.id = spawnentry.npcID " - "WHERE spawn2.zone = '%s' AND npc_types.bodytype NOT IN (11, 33, 66, 67) " - "AND npc_types.race NOT IN (0,1,2,3,4,5,6,7,8,9,10,11,12,44,55,67,71,72,73,77,78,81,90,92,93,94,106,112,114,127,128,130,139,141,183,236,237,238,239,254,266,329,330,378,379,380,381,382,383,404,522) " - "ORDER BY RAND() LIMIT 1", zone->GetShortName()), errbuf, &result)) - { - row = mysql_fetch_row(result); - if (row) - monsterid = atoi(row[0]); - else - monsterid = 567; // since we don't have any monsters, just make it look like an earth pet for now - } - else { // if the database query failed - LogFile->write(EQEMuLog::Error, "Error querying database for monster summoning pet in zone %s (%s)", zone->GetShortName(), errbuf); - monsterid = 567; + auto query = StringFormat("SELECT npcID " + "FROM (spawnentry INNER JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID) " + "INNER JOIN npc_types ON npc_types.id = spawnentry.npcID " + "WHERE spawn2.zone = '%s' AND npc_types.bodytype NOT IN (11, 33, 66, 67) " + "AND npc_types.race NOT IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 44, " + "55, 67, 71, 72, 73, 77, 78, 81, 90, 92, 93, 94, 106, 112, 114, 127, 128, " + "130, 139, 141, 183, 236, 237, 238, 239, 254, 266, 329, 330, 378, 379, " + "380, 381, 382, 383, 404, 522) " + "ORDER BY RAND() LIMIT 1", zone->GetShortName()); + auto results = database.QueryDatabase(query); + if (!results.Success()) { + // if the database query failed + LogFile->write(EQEMuLog::Error, "Error querying database for monster summoning pet in zone %s (%s)", zone->GetShortName(), results.ErrorMessage().c_str()); } + if (results.RowCount() != 0) { + auto row = results.begin(); + monsterid = atoi(row[0]); + } + + // since we don't have any monsters, just make it look like an earth pet for now + if (monsterid == 0) + monsterid = 567; + // give the summoned pet the attributes of the monster we found const NPCType* monster = database.GetNPCType(monsterid); if(monster) { @@ -396,12 +399,9 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower, npc_type->gender = monster->gender; npc_type->luclinface = monster->luclinface; npc_type->helmtexture = monster->helmtexture; - } - else { + } else LogFile->write(EQEMuLog::Error, "Error loading NPC data for monster summoning pet (NPC ID %d)", monsterid); - } - safe_delete_array(query); } //this takes ownership of the npc_type data