[Auras] Convert Get of Auras to Repositories (#3964)

* [Auras] Convert Get of Auras to Repositories

# Notes
- Convert `GetAuraEntry()` to repositories.

* Update aura.cpp
This commit is contained in:
Alex King 2024-01-13 00:29:43 -05:00 committed by GitHub
parent f1d5e3eedf
commit 4c028b85f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
#include "../common/strings.h" #include "../common/strings.h"
#include "../common/repositories/auras_repository.h"
#include "aura.h" #include "aura.h"
#include "client.h" #include "client.h"
@ -927,36 +928,33 @@ void Mob::MakeAura(uint16 spell_id)
} }
} }
bool ZoneDatabase::GetAuraEntry(uint16 spell_id, AuraRecord &record) bool ZoneDatabase::GetAuraEntry(uint16 spell_id, AuraRecord& r)
{ {
auto query = StringFormat( const auto& l = AurasRepository::GetWhere(
"SELECT npc_type, name, spell_id, distance, aura_type, spawn_type, movement, " *this,
"duration, icon, cast_time FROM auras WHERE type='%d'", fmt::format(
"`type` = {}",
spell_id spell_id
)
); );
auto results = QueryDatabase(query); if (l.empty()) {
if (!results.Success()) {
return false; return false;
} }
if (results.RowCount() != 1) { auto e = l.front();
return false;
}
auto row = results.begin(); strn0cpy(r.name, e.name.c_str(), sizeof(r.name));
record.npc_type = Strings::ToInt(row[0]); r.npc_type = e.npc_type;
strn0cpy(record.name, row[1], 64); r.spell_id = spell_id;
record.spell_id = Strings::ToInt(row[2]); r.distance = e.distance * e.distance;
record.distance = Strings::ToInt(row[3]); r.aura_type = e.aura_type;
record.distance *= record.distance; // so we can avoid sqrt r.spawn_type = e.spawn_type;
record.aura_type = Strings::ToInt(row[4]); r.movement = e.movement;
record.spawn_type = Strings::ToInt(row[5]); r.duration = e.duration * 1000; // Database is in seconds
record.movement = Strings::ToInt(row[6]); r.icon = e.icon;
record.duration = Strings::ToInt(row[7]) * 1000; // DB is in seconds r.cast_time = e.cast_time * 1000; // Database is in seconds
record.icon = Strings::ToInt(row[8]);
record.cast_time = Strings::ToInt(row[9]) * 1000; // DB is in seconds
return true; return true;
} }