feat: resolve spell \$d duration to real seconds from SpellDuration.dbc

Spell descriptions now substitute \$d with actual duration values:
  Before: "X damage over X sec"
  After:  "30 damage over 18 sec"

Implementation:
- DurationIndex field (40) added to all expansion Spell.dbc layouts
- SpellDuration.dbc loaded during cache build: maps index → base ms
- cleanSpellDescription substitutes \$d with resolved seconds/minutes
- getSpellDuration() accessor on GameHandler

Combined with \$s1/\$s2/\$s3 from the previous commit, most common
spell description templates are now fully resolved with real values.
This commit is contained in:
Kelsi 2026-03-23 01:00:18 -07:00
parent a5aa1faf7a
commit 11ecc475c8
7 changed files with 48 additions and 4 deletions

View file

@ -23200,9 +23200,33 @@ void GameHandler::loadSpellNameCache() {
if (f1 != 0xFFFFFFFF) entry.effectBasePoints[1] = static_cast<int32_t>(dbc->getUInt32(i, f1));
if (f2 != 0xFFFFFFFF) entry.effectBasePoints[2] = static_cast<int32_t>(dbc->getUInt32(i, f2));
}
// Duration: read DurationIndex and resolve via SpellDuration.dbc later
if (spellL) {
uint32_t durF = spellL->field("DurationIndex");
if (durF != 0xFFFFFFFF)
entry.durationSec = static_cast<float>(dbc->getUInt32(i, durF)); // store index temporarily
}
spellNameCache_[id] = std::move(entry);
}
}
// Resolve DurationIndex → seconds via SpellDuration.dbc
auto durDbc = am->loadDBC("SpellDuration.dbc");
if (durDbc && durDbc->isLoaded()) {
std::unordered_map<uint32_t, float> durMap;
for (uint32_t di = 0; di < durDbc->getRecordCount(); ++di) {
uint32_t durId = durDbc->getUInt32(di, 0);
int32_t baseMs = static_cast<int32_t>(durDbc->getUInt32(di, 1));
if (baseMs > 0 && baseMs < 100000000) // filter out absurd values
durMap[durId] = baseMs / 1000.0f;
}
for (auto& [sid, entry] : spellNameCache_) {
uint32_t durIdx = static_cast<uint32_t>(entry.durationSec);
if (durIdx > 0) {
auto it = durMap.find(durIdx);
entry.durationSec = (it != durMap.end()) ? it->second : 0.0f;
}
}
}
LOG_INFO("Trainer: Loaded ", spellNameCache_.size(), " spell names from Spell.dbc");
}
@ -23445,6 +23469,12 @@ const int32_t* GameHandler::getSpellEffectBasePoints(uint32_t spellId) const {
return (it != spellNameCache_.end()) ? it->second.effectBasePoints : nullptr;
}
float GameHandler::getSpellDuration(uint32_t spellId) const {
const_cast<GameHandler*>(this)->loadSpellNameCache();
auto it = spellNameCache_.find(spellId);
return (it != spellNameCache_.end()) ? it->second.durationSec : 0.0f;
}
const std::string& GameHandler::getSpellName(uint32_t spellId) const {
auto it = spellNameCache_.find(spellId);
return (it != spellNameCache_.end()) ? it->second.name : EMPTY_STRING;