mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
Merge pull request #203 from addtheice/RunQueryToDatabaseQuery_zone_pets
Run query to database query zone pets
This commit is contained in:
commit
2e1b75e95b
199
zone/pets.cpp
199
zone/pets.cpp
@ -362,31 +362,34 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower,
|
|||||||
|
|
||||||
// handle monster summoning pet appearance
|
// handle monster summoning pet appearance
|
||||||
if(record.monsterflag) {
|
if(record.monsterflag) {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char* query = 0;
|
uint32 monsterid = 0;
|
||||||
MYSQL_RES *result = nullptr;
|
|
||||||
MYSQL_ROW row = nullptr;
|
|
||||||
uint32 monsterid;
|
|
||||||
|
|
||||||
// get a random npc id from the spawngroups assigned to this zone
|
// get a random npc id from the spawngroups assigned to this zone
|
||||||
if (database.RunQuery(query, MakeAnyLenString(&query,
|
auto query = StringFormat("SELECT npcID "
|
||||||
"SELECT npcID FROM (spawnentry INNER JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID) "
|
"FROM (spawnentry INNER JOIN spawn2 ON spawn2.spawngroupID = spawnentry.spawngroupID) "
|
||||||
"INNER JOIN npc_types ON npc_types.id = spawnentry.npcID "
|
"INNER JOIN npc_types ON npc_types.id = spawnentry.npcID "
|
||||||
"WHERE spawn2.zone = '%s' AND npc_types.bodytype NOT IN (11, 33, 66, 67) "
|
"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) "
|
"AND npc_types.race NOT IN (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 44, "
|
||||||
"ORDER BY RAND() LIMIT 1", zone->GetShortName()), errbuf, &result))
|
"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, "
|
||||||
row = mysql_fetch_row(result);
|
"380, 381, 382, 383, 404, 522) "
|
||||||
if (row)
|
"ORDER BY RAND() LIMIT 1", zone->GetShortName());
|
||||||
monsterid = atoi(row[0]);
|
auto results = database.QueryDatabase(query);
|
||||||
else
|
if (!results.Success()) {
|
||||||
monsterid = 567; // since we don't have any monsters, just make it look like an earth pet for now
|
// 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());
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// give the summoned pet the attributes of the monster we found
|
||||||
const NPCType* monster = database.GetNPCType(monsterid);
|
const NPCType* monster = database.GetNPCType(monsterid);
|
||||||
if(monster) {
|
if(monster) {
|
||||||
@ -396,12 +399,9 @@ void Mob::MakePoweredPet(uint16 spell_id, const char* pettype, int16 petpower,
|
|||||||
npc_type->gender = monster->gender;
|
npc_type->gender = monster->gender;
|
||||||
npc_type->luclinface = monster->luclinface;
|
npc_type->luclinface = monster->luclinface;
|
||||||
npc_type->helmtexture = monster->helmtexture;
|
npc_type->helmtexture = monster->helmtexture;
|
||||||
}
|
} else
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error loading NPC data for monster summoning pet (NPC ID %d)", monsterid);
|
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
|
//this takes ownership of the npc_type data
|
||||||
@ -450,46 +450,35 @@ bool ZoneDatabase::GetPetEntry(const char *pet_type, PetRecord *into) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into) {
|
bool ZoneDatabase::GetPoweredPetEntry(const char *pet_type, int16 petpower, PetRecord *into) {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query;
|
||||||
char *query = 0;
|
|
||||||
uint32 querylen = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
if (petpower <= 0) {
|
if (petpower <= 0)
|
||||||
querylen = MakeAnyLenString(&query,
|
query = StringFormat("SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset "
|
||||||
"SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset FROM pets "
|
"FROM pets WHERE type='%s' AND petpower<=0", pet_type);
|
||||||
"WHERE type='%s' AND petpower<=0", pet_type);
|
else
|
||||||
}
|
query = StringFormat("SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset "
|
||||||
else {
|
"FROM pets WHERE type='%s' AND petpower<=%d ORDER BY petpower DESC LIMIT 1",
|
||||||
querylen = MakeAnyLenString(&query,
|
pet_type, petpower);
|
||||||
"SELECT npcID, temp, petpower, petcontrol, petnaming, monsterflag, equipmentset FROM pets "
|
auto results = QueryDatabase(query);
|
||||||
"WHERE type='%s' AND petpower<=%d ORDER BY petpower DESC LIMIT 1", pet_type, petpower);
|
if (!results.Success()) {
|
||||||
}
|
LogFile->write(EQEMuLog::Error, "Error in GetPoweredPetEntry query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (RunQuery(query, querylen, errbuf, &result)) {
|
if (results.RowCount() != 1)
|
||||||
safe_delete_array(query);
|
return false;
|
||||||
if (mysql_num_rows(result) == 1) {
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
|
|
||||||
into->npc_type = atoi(row[0]);
|
auto row = results.begin();
|
||||||
into->temporary = atoi(row[1]);
|
|
||||||
into->petpower = atoi(row[2]);
|
|
||||||
into->petcontrol = atoi(row[3]);
|
|
||||||
into->petnaming = atoi(row[4]);
|
|
||||||
into->monsterflag = atoi(row[5]);
|
|
||||||
into->equipmentset = atoi(row[6]);
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
into->npc_type = atoi(row[0]);
|
||||||
return(true);
|
into->temporary = atoi(row[1]);
|
||||||
}
|
into->petpower = atoi(row[2]);
|
||||||
mysql_free_result(result);
|
into->petcontrol = atoi(row[3]);
|
||||||
}
|
into->petnaming = atoi(row[4]);
|
||||||
else {
|
into->monsterflag = atoi(row[5]);
|
||||||
LogFile->write(EQEMuLog::Error, "Error in GetPoweredPetEntry query '%s': %s", query, errbuf);
|
into->equipmentset = atoi(row[6]);
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
return true;
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Mob* Mob::GetPet() {
|
Mob* Mob::GetPet() {
|
||||||
@ -657,11 +646,6 @@ bool ZoneDatabase::GetBasePetItems(int32 equipmentset, uint32 *items) {
|
|||||||
// A slot will only get an item put in it if it is empty. That way
|
// A slot will only get an item put in it if it is empty. That way
|
||||||
// an equipmentset can overload a slot for the set(s) it includes.
|
// an equipmentset can overload a slot for the set(s) it includes.
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
uint32 querylen = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
int32 curset = equipmentset;
|
int32 curset = equipmentset;
|
||||||
int32 nextset = -1;
|
int32 nextset = -1;
|
||||||
@ -673,56 +657,43 @@ bool ZoneDatabase::GetBasePetItems(int32 equipmentset, uint32 *items) {
|
|||||||
// query pets_equipmentset_entries with the set_id and loop over
|
// query pets_equipmentset_entries with the set_id and loop over
|
||||||
// all of the result rows. Check if we have something in the slot
|
// all of the result rows. Check if we have something in the slot
|
||||||
// already. If no, add the item id to the equipment array.
|
// already. If no, add the item id to the equipment array.
|
||||||
|
|
||||||
while (curset >= 0 && depth < 5) {
|
while (curset >= 0 && depth < 5) {
|
||||||
if (RunQuery(query,
|
std::string query = StringFormat("SELECT nested_set FROM pets_equipmentset WHERE set_id = '%s'", curset);
|
||||||
MakeAnyLenString(&query, "SELECT nested_set FROM pets_equipmentset WHERE set_id='%s'", curset),
|
auto results = QueryDatabase(query);
|
||||||
errbuf, &result))
|
if (!results.Success()) {
|
||||||
{
|
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
if (mysql_num_rows(result) == 1) {
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
nextset = atoi(row[0]);
|
|
||||||
mysql_free_result(result);
|
|
||||||
|
|
||||||
if (RunQuery(query,
|
|
||||||
MakeAnyLenString(&query, "SELECT slot, item_id FROM pets_equipmentset_entries WHERE set_id='%s'", curset),
|
|
||||||
errbuf, &result))
|
|
||||||
{
|
|
||||||
safe_delete_array(query);
|
|
||||||
while ((row = mysql_fetch_row(result)))
|
|
||||||
{
|
|
||||||
slot = atoi(row[0]);
|
|
||||||
if (slot >= EmuConstants::EQUIPMENT_SIZE)
|
|
||||||
continue;
|
|
||||||
if (items[slot] == 0)
|
|
||||||
items[slot] = atoi(row[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems query '%s': %s", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
curset = nextset;
|
|
||||||
depth++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// invalid set reference, it doesn't exist
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems equipment set '%d' does not exist", curset);
|
|
||||||
mysql_free_result(result);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems query '%s': %s", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} // end while
|
|
||||||
|
if (results.RowCount() != 1) {
|
||||||
|
// invalid set reference, it doesn't exist
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems equipment set '%d' does not exist", curset);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto row = results.begin();
|
||||||
|
nextset = atoi(row[0]);
|
||||||
|
|
||||||
|
query = StringFormat("SELECT slot, item_id FROM pets_equipmentset_entries WHERE set_id='%s'", curset);
|
||||||
|
results = QueryDatabase(query);
|
||||||
|
if (!results.Success())
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error in GetBasePetItems query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
else {
|
||||||
|
for (row = results.begin(); row != results.end(); ++row)
|
||||||
|
{
|
||||||
|
slot = atoi(row[0]);
|
||||||
|
|
||||||
|
if (slot >= EmuConstants::EQUIPMENT_SIZE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (items[slot] == 0)
|
||||||
|
items[slot] = atoi(row[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curset = nextset;
|
||||||
|
depth++;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user