LoadBuffs converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-08-21 13:53:54 -07:00
parent 00b8c8ce47
commit 10d384f131

View File

@ -1978,35 +1978,32 @@ void ZoneDatabase::SaveBuffs(Client *client) {
}
}
void ZoneDatabase::LoadBuffs(Client *c) {
Buffs_Struct *buffs = c->GetBuffs();
uint32 max_slots = c->GetMaxBuffSlots();
for(int i = 0; i < max_slots; ++i) {
buffs[i].spellid = SPELL_UNKNOWN;
void ZoneDatabase::LoadBuffs(Client *client) {
Buffs_Struct *buffs = client->GetBuffs();
uint32 max_slots = client->GetMaxBuffSlots();
for(int index = 0; index < max_slots; ++index)
buffs[index].spellid = SPELL_UNKNOWN;
std::string query = StringFormat("SELECT spell_id, slot_id, caster_level, caster_name, ticsremaining, "
"counters, numhits, melee_rune, magic_rune, persistent, dot_rune, "
"caston_x, caston_y, caston_z, ExtraDIChance "
"FROM `character_buffs` WHERE `character_id` = '%u'", client->CharacterID());
auto results = QueryDatabase(query);
if (!results.Success()) {
LogFile->write(EQEMuLog::Error, "Error in LoadBuffs query '%s': %s", query.c_str(), results.ErrorMessage().c_str());
return;
}
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
if (RunQuery(query, MakeAnyLenString(&query, "SELECT spell_id, slot_id, caster_level, caster_name, ticsremaining, counters, "
"numhits, melee_rune, magic_rune, persistent, dot_rune, caston_x, caston_y, caston_z, ExtraDIChance FROM `character_buffs` WHERE "
"`character_id`='%u'",
c->CharacterID()), errbuf, &result))
{
safe_delete_array(query);
while ((row = mysql_fetch_row(result)))
{
for (auto row = results.begin(); row != results.end(); ++row) {
uint32 slot_id = atoul(row[1]);
if(slot_id >= c->GetMaxBuffSlots()) {
if(slot_id >= client->GetMaxBuffSlots())
continue;
}
uint32 spell_id = atoul(row[0]);
if(!IsValidSpell(spell_id)) {
if(!IsValidSpell(spell_id))
continue;
}
Client *caster = entity_list.GetClientByName(row[3]);
uint32 caster_level = atoi(row[2]);
@ -2024,6 +2021,7 @@ void ZoneDatabase::LoadBuffs(Client *c) {
buffs[slot_id].spellid = spell_id;
buffs[slot_id].casterlevel = caster_level;
if(caster) {
buffs[slot_id].casterid = caster->GetID();
strcpy(buffs[slot_id].caster_name, caster->GetName());
@ -2049,37 +2047,24 @@ void ZoneDatabase::LoadBuffs(Client *c) {
buffs[slot_id].UpdateClient = false;
}
mysql_free_result(result);
}
else {
LogFile->write(EQEMuLog::Error, "Error in LoadBuffs query '%s': %s", query, errbuf);
safe_delete_array(query);
return;
}
max_slots = c->GetMaxBuffSlots();
for(int i = 0; i < max_slots; ++i) {
if(!IsValidSpell(buffs[i].spellid)) {
max_slots = client->GetMaxBuffSlots();
for(int index = 0; index < max_slots; ++index) {
if(!IsValidSpell(buffs[index].spellid))
continue;
}
for(int j = 0; j < 12; ++j) {
bool cont = false;
switch(spells[buffs[i].spellid].effectid[j]) {
case SE_Charm:
buffs[i].spellid = SPELL_UNKNOWN;
cont = true;
break;
case SE_Illusion:
if(!buffs[i].persistant_buff) {
buffs[i].spellid = SPELL_UNKNOWN;
cont = true;
}
for(int effectIndex = 0; effectIndex < 12; ++effectIndex) {
if (spells[buffs[index].spellid].effectid[effectIndex] == SE_Charm) {
buffs[index].spellid = SPELL_UNKNOWN;
break;
}
if(cont) {
if (spells[buffs[index].spellid].effectid[effectIndex] == SE_Illusion) {
if(buffs[index].persistant_buff)
break;
buffs[index].spellid = SPELL_UNKNOWN;
}
}
}