LoadSpells converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-10-04 14:16:54 -07:00
parent 1c04dccf53
commit 938322a3d1

View File

@ -1423,26 +1423,23 @@ int SharedDatabase::GetMaxSpellID() {
void SharedDatabase::LoadSpells(void *data, int max_spells) { void SharedDatabase::LoadSpells(void *data, int max_spells) {
SPDat_Spell_Struct *sp = reinterpret_cast<SPDat_Spell_Struct*>(data); SPDat_Spell_Struct *sp = reinterpret_cast<SPDat_Spell_Struct*>(data);
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
if(RunQuery(query, MakeAnyLenString(&query, const std::string query = "SELECT * FROM spells_new ORDER BY id ASC";
"SELECT * FROM spells_new ORDER BY id ASC"), auto results = QueryDatabase(query);
errbuf, &result)) { if (!results.Success()) {
safe_delete_array(query); _log(SPELLS__LOAD_ERR, "Error in LoadSpells query '%s' %s", query.c_str(), results.ErrorMessage().c_str());
return;
}
if(results.ColumnCount() <= SPELL_LOAD_FIELD_COUNT) {
_log(SPELLS__LOAD_ERR, "Fatal error loading spells: Spell field count < SPELL_LOAD_FIELD_COUNT(%u)", SPELL_LOAD_FIELD_COUNT);
return;
}
int tempid = 0; int tempid = 0;
int counter = 0; int counter = 0;
if(result && mysql_field_count(getMySQL()) <= SPELL_LOAD_FIELD_COUNT) { for (auto row = results.begin(); row != results.end(); ++row) {
_log(SPELLS__LOAD_ERR, "Fatal error loading spells: Spell field count < SPELL_LOAD_FIELD_COUNT(%u)", SPELL_LOAD_FIELD_COUNT);
mysql_free_result(result);
return;
}
while (row = mysql_fetch_row(result)) {
tempid = atoi(row[0]); tempid = atoi(row[0]);
if(tempid >= max_spells) { if(tempid >= max_spells) {
_log(SPELLS__LOAD_ERR, "Non fatal error: spell.id >= max_spells, ignoring."); _log(SPELLS__LOAD_ERR, "Non fatal error: spell.id >= max_spells, ignoring.");
@ -1475,8 +1472,10 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) {
int y=0; int y=0;
for(y=0; y< EFFECT_COUNT;y++) for(y=0; y< EFFECT_COUNT;y++)
sp[tempid].base[y]=atoi(row[20+y]); // effect_base_value sp[tempid].base[y]=atoi(row[20+y]); // effect_base_value
for(y=0; y < EFFECT_COUNT; y++) for(y=0; y < EFFECT_COUNT; y++)
sp[tempid].base2[y]=atoi(row[32+y]); // effect_limit_value sp[tempid].base2[y]=atoi(row[32+y]); // effect_limit_value
for(y=0; y< EFFECT_COUNT;y++) for(y=0; y< EFFECT_COUNT;y++)
sp[tempid].max[y]=atoi(row[44+y]); sp[tempid].max[y]=atoi(row[44+y]);
@ -1501,11 +1500,14 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) {
sp[tempid].targettype = (SpellTargetType) atoi(row[98]); sp[tempid].targettype = (SpellTargetType) atoi(row[98]);
sp[tempid].basediff=atoi(row[99]); sp[tempid].basediff=atoi(row[99]);
int tmp_skill = atoi(row[100]);; int tmp_skill = atoi(row[100]);;
if(tmp_skill < 0 || tmp_skill > HIGHEST_SKILL) if(tmp_skill < 0 || tmp_skill > HIGHEST_SKILL)
sp[tempid].skill = SkillBegging; /* not much better we can do. */ // can probably be changed to client-based 'SkillNone' once activated sp[tempid].skill = SkillBegging; /* not much better we can do. */ // can probably be changed to client-based 'SkillNone' once activated
else else
sp[tempid].skill = (SkillUseTypes) tmp_skill; sp[tempid].skill = (SkillUseTypes) tmp_skill;
sp[tempid].zonetype=atoi(row[101]); sp[tempid].zonetype=atoi(row[101]);
sp[tempid].EnvironmentType=atoi(row[102]); sp[tempid].EnvironmentType=atoi(row[102]);
sp[tempid].TimeOfDay=atoi(row[103]); sp[tempid].TimeOfDay=atoi(row[103]);
@ -1574,13 +1576,8 @@ void SharedDatabase::LoadSpells(void *data, int max_spells) {
sp[tempid].min_range = static_cast<float>(atoi(row[231])); sp[tempid].min_range = static_cast<float>(atoi(row[231]));
sp[tempid].DamageShieldType = 0; sp[tempid].DamageShieldType = 0;
} }
mysql_free_result(result);
LoadDamageShieldTypes(sp, max_spells); LoadDamageShieldTypes(sp, max_spells);
} else {
_log(SPELLS__LOAD_ERR, "Error in LoadSpells query '%s' %s", query, errbuf);
safe_delete_array(query);
}
} }
int SharedDatabase::GetMaxBaseDataLevel() { int SharedDatabase::GetMaxBaseDataLevel() {