mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 16:41:29 +00:00
LoadPetInfo converted to QueryDatabase
This commit is contained in:
parent
e731cfd48d
commit
833227f7f6
194
zone/zonedb.cpp
194
zone/zonedb.cpp
@ -2173,129 +2173,109 @@ void ZoneDatabase::RemoveTempFactions(Client *client) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::LoadPetInfo(Client *c) {
|
void ZoneDatabase::LoadPetInfo(Client *client) {
|
||||||
// Load current pet and suspended pet
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char* query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
PetInfo *petinfo = c->GetPetInfo(0);
|
// Load current pet and suspended pet
|
||||||
PetInfo *suspended = c->GetPetInfo(1);
|
PetInfo *petinfo = client->GetPetInfo(0);
|
||||||
PetInfo *pi;
|
PetInfo *suspended = client->GetPetInfo(1);
|
||||||
uint16 pet;
|
|
||||||
|
|
||||||
memset(petinfo, 0, sizeof(PetInfo));
|
memset(petinfo, 0, sizeof(PetInfo));
|
||||||
memset(suspended, 0, sizeof(PetInfo));
|
memset(suspended, 0, sizeof(PetInfo));
|
||||||
|
|
||||||
if(database.RunQuery(query, MakeAnyLenString(&query,
|
std::string query = StringFormat("SELECT `pet`, `petname`, `petpower`, `spell_id`, "
|
||||||
"SELECT `pet`, `petname`, `petpower`, `spell_id`, `hp`, `mana`, `size` from `character_pet_info` where `char_id`=%u",
|
"`hp`, `mana`, `size` FROM `character_pet_info` "
|
||||||
c->CharacterID()), errbuf, &result))
|
"WHERE `char_id` = %u", client->CharacterID());
|
||||||
{
|
auto results = database.QueryDatabase(query);
|
||||||
safe_delete_array(query);
|
if(!results.Success()) {
|
||||||
while ((row = mysql_fetch_row(result))) {
|
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
pet = atoi(row[0]);
|
|
||||||
if (pet == 0)
|
|
||||||
pi = petinfo;
|
|
||||||
else if (pet == 1)
|
|
||||||
pi = suspended;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
strncpy(pi->Name,row[1],64);
|
|
||||||
pi->petpower = atoi(row[2]);
|
|
||||||
pi->SpellID = atoi(row[3]);
|
|
||||||
pi->HP = atoul(row[4]);
|
|
||||||
pi->Mana = atoul(row[5]);
|
|
||||||
pi->size = atof(row[6]);
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PetInfo *pi;
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
uint16 pet = atoi(row[0]);
|
||||||
|
|
||||||
if (RunQuery(query, MakeAnyLenString(&query,
|
if (pet == 0)
|
||||||
"SELECT `pet`, `slot`, `spell_id`, `caster_level`, `castername`, "
|
pi = petinfo;
|
||||||
"`ticsremaining`, `counters` FROM `character_pet_buffs` "
|
else if (pet == 1)
|
||||||
"WHERE `char_id`=%u",
|
pi = suspended;
|
||||||
c->CharacterID()), errbuf, &result))
|
else
|
||||||
{
|
continue;
|
||||||
safe_delete_array(query);
|
|
||||||
while ((row = mysql_fetch_row(result)))
|
|
||||||
{
|
|
||||||
pet = atoi(row[0]);
|
|
||||||
if (pet == 0)
|
|
||||||
pi = petinfo;
|
|
||||||
else if (pet == 1)
|
|
||||||
pi = suspended;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
uint32 slot_id = atoul(row[1]);
|
strncpy(pi->Name,row[1],64);
|
||||||
if(slot_id >= RuleI(Spells, MaxTotalSlotsPET)) {
|
pi->petpower = atoi(row[2]);
|
||||||
continue;
|
pi->SpellID = atoi(row[3]);
|
||||||
}
|
pi->HP = atoul(row[4]);
|
||||||
|
pi->Mana = atoul(row[5]);
|
||||||
uint32 spell_id = atoul(row[2]);
|
pi->size = atof(row[6]);
|
||||||
if(!IsValidSpell(spell_id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
uint32 caster_level = atoi(row[3]);
|
|
||||||
int caster_id = 0;
|
|
||||||
// The castername field is currently unused
|
|
||||||
//Client *caster = entity_list.GetClientByName(row[4]);
|
|
||||||
//if (caster) { caster_id = caster->GetID(); }
|
|
||||||
uint32 ticsremaining = atoul(row[5]);
|
|
||||||
uint32 counters = atoul(row[6]);
|
|
||||||
|
|
||||||
pi->Buffs[slot_id].spellid = spell_id;
|
|
||||||
pi->Buffs[slot_id].level = caster_level;
|
|
||||||
pi->Buffs[slot_id].player_id = caster_id;
|
|
||||||
pi->Buffs[slot_id].slotid = 2; // Always 2 in buffs struct for real buffs
|
|
||||||
|
|
||||||
pi->Buffs[slot_id].duration = ticsremaining;
|
|
||||||
pi->Buffs[slot_id].counters = counters;
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf);
|
query = StringFormat("SELECT `pet`, `slot`, `spell_id`, `caster_level`, `castername`, "
|
||||||
safe_delete_array(query);
|
"`ticsremaining`, `counters` FROM `character_pet_buffs` "
|
||||||
|
"WHERE `char_id` = %u", client->CharacterID());
|
||||||
|
results = QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
|
uint16 pet = atoi(row[0]);
|
||||||
|
if (pet == 0)
|
||||||
|
pi = petinfo;
|
||||||
|
else if (pet == 1)
|
||||||
|
pi = suspended;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint32 slot_id = atoul(row[1]);
|
||||||
|
if(slot_id >= RuleI(Spells, MaxTotalSlotsPET))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint32 spell_id = atoul(row[2]);
|
||||||
|
if(!IsValidSpell(spell_id))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
uint32 caster_level = atoi(row[3]);
|
||||||
|
int caster_id = 0;
|
||||||
|
// The castername field is currently unused
|
||||||
|
uint32 ticsremaining = atoul(row[5]);
|
||||||
|
uint32 counters = atoul(row[6]);
|
||||||
|
|
||||||
|
pi->Buffs[slot_id].spellid = spell_id;
|
||||||
|
pi->Buffs[slot_id].level = caster_level;
|
||||||
|
pi->Buffs[slot_id].player_id = caster_id;
|
||||||
|
pi->Buffs[slot_id].slotid = 2; // Always 2 in buffs struct for real buffs
|
||||||
|
|
||||||
|
pi->Buffs[slot_id].duration = ticsremaining;
|
||||||
|
pi->Buffs[slot_id].counters = counters;
|
||||||
|
}
|
||||||
|
|
||||||
|
query = StringFormat("SELECT `pet`, `slot`, `item_id` "
|
||||||
|
"FROM `character_pet_inventory` "
|
||||||
|
"WHERE `char_id`=%u",client->CharacterID());
|
||||||
|
results = database.QueryDatabase(query);
|
||||||
|
if (!results.Success()) {
|
||||||
|
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (database.RunQuery(query, MakeAnyLenString(&query,
|
for(auto row = results.begin(); row != results.end(); ++row) {
|
||||||
"SELECT `pet`, `slot`, `item_id` FROM `character_pet_inventory` WHERE `char_id`=%u",
|
uint16 pet = atoi(row[0]);
|
||||||
c->CharacterID()), errbuf, &result))
|
if (pet == 0)
|
||||||
{
|
pi = petinfo;
|
||||||
safe_delete_array(query);
|
else if (pet == 1)
|
||||||
while((row = mysql_fetch_row(result))) {
|
pi = suspended;
|
||||||
pet = atoi(row[0]);
|
else
|
||||||
if (pet == 0)
|
continue;
|
||||||
pi = petinfo;
|
|
||||||
else if (pet == 1)
|
|
||||||
pi = suspended;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int slot = atoi(row[1]);
|
int slot = atoi(row[1]);
|
||||||
if (slot < EmuConstants::EQUIPMENT_BEGIN || slot > EmuConstants::EQUIPMENT_END)
|
if (slot < EmuConstants::EQUIPMENT_BEGIN || slot > EmuConstants::EQUIPMENT_END)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
pi->Items[slot] = atoul(row[2]);
|
||||||
|
}
|
||||||
|
|
||||||
pi->Items[slot] = atoul(row[2]);
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in LoadPetInfo query '%s': %s", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZoneDatabase::GetFactionData(FactionMods* fm, uint32 class_mod, uint32 race_mod, uint32 deity_mod, int32 faction_id) {
|
bool ZoneDatabase::GetFactionData(FactionMods* fm, uint32 class_mod, uint32 race_mod, uint32 deity_mod, int32 faction_id) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user