Module:HeroListByClass
From Heroes of Might and Magic: Olden Era Official Wiki
Documentation for this module may be created at Module:HeroListByClass/doc
local p = {}
-- 1. Fonction utilitaire pour les traductions
local function getTrans(target_id, lang, type_force, field)
field = field or "name"
if not target_id or target_id == "" then return nil end
local types = type_force and {type_force} or {"wiki", "ui", "hero", "hero_class", "skill", "spell", "hero_specialization"}
for _, t in ipairs(types) do
local query = mw.ext.cargo.query("Translation", field, {
where = string.format("target_id = '%s' AND language = '%s' AND type = '%s'", target_id, lang, t),
limit = 1
})
if query and #query > 0 then return query[1][field] end
end
return nil
end
-- 2. Fonction principale
function p.display(frame)
local class_filter = frame.args.class_id
local lang = frame.args.language or mw.title.getCurrentTitle().text:match("/(%a%a)$") or "en"
-- Table de conversion des classes
local class_map = {
["herald"] = "magic_demon",
["warlock"] = "magic_dungeon",
["cleric"] = "magic_human",
["druid"] = "magic_nature",
["necromancer"] = "magic_undead",
["riftspeaker"] = "magic_unfrozen",
["enforcer"] = "might_demon",
["overlord"] = "might_dungeon",
["warden"] = "might_nature",
["death knight"] = "might_undead",
["oathkeeper"] = "might_unfrozen",
["knight"] = "might_human"
}
-- Initialisation du tableau
local html = {'{| class="wikitable sortable" style="width:100%"'}
-- Construction de la requête
local where_clause = "id NOT LIKE '%campaign%' AND id NOT LIKE '%tutorial%' AND id NOT LIKE '%cm_fun%'"
local mapped_id = nil
if class_filter and class_filter ~= "" then
mapped_id = class_map[class_filter:lower()] or class_filter
where_clause = where_clause .. string.format(" AND class_id = '%s'", mapped_id)
end
-- Débogage
local count_test = mw.ext.cargo.query("Hero", "COUNT(*)", {where = where_clause})
local total = (count_test and #count_test > 0) and count_test[1]["COUNT(*)"] or 0
table.insert(html, '<tr><td colspan="4" style="background:#f9f9f9;">DEBUG: Filtre = ' .. (mapped_id or "Aucun") .. ' | Héros trouvés = ' .. total .. '</td></tr>')
-- Récupération des données
local heroes = mw.ext.cargo.query("Hero", "id, name_sid, class_id, specialization_id, start_skills, start_magics", {
where = where_clause
})
-- En-têtes
local h_name = getTrans("wiki_name", lang, "wiki") or "Name"
local h_spec = getTrans("wiki_hero_spec", lang, "wiki") or "Specialization"
local h_skills = getTrans("starting_skills", lang, "ui") or "Skills"
local h_spells = getTrans("starting_spells", lang, "ui") or "Spells"
table.insert(html, string.format('! %s !! %s !! %s !! %s', h_name, h_spec, h_skills, h_spells))
-- Boucle des héros
for _, h in ipairs(heroes) do
-- (Insère ici tes boucles for pour remplir skills_html et spells_html)
-- ...
local skills_html = {} -- Exemple vide à remplir
local spells_html = {} -- Exemple vide à remplir
table.insert(html, '|- style="vertical-align: middle;"')
table.insert(html, "| " .. (getTrans(h.name_sid, lang, 'hero') or h.name_sid))
table.insert(html, "| " .. (getTrans(h.specialization_id, lang, 'hero_specialization') or h.specialization_id))
table.insert(html, "| " .. table.concat(skills_html, "<br>"))
table.insert(html, "| " .. table.concat(spells_html, "<br>"))
end
table.insert(html, "|}")
return table.concat(html, "\n")
end
return p


