Module:HeroClassData

From Heroes of Might and Magic: Olden Era Official Wiki

This module allows for the dynamic extraction of all variables, combat growth coefficients, and translations for hero classes stored within the wiki's Cargo database (specifically from the HeroClass and Translation tables). It automatically handles localized fallback to English if a translation in the requested language is missing.

Basic Syntax

To fetch a data field, use the following syntax:

{{#invoke:HeroClassData|get|CLASS_ID|VARIABLE|LANGUAGE_CODE}}
  • CLASS_ID : The technical identifier of the hero class (e.g., might_dungeon, magic_undead).
  • VARIABLE : The keyword for the specific data field you want to display (see the list below).
  • LANGUAGE_CODE : (Optional) The localization code (e.g., en, fr, pl). Defaults to English (en).

---

Available Variables

📝 Text & Translations (Language-Dependent)

These variables query the Translation table using the type="hero_class" filter and dynamically adapt to the requested language code.

Variable Description Example Output (en)
name The localized name of the hero class. Overlord
description The localized official description, detailing mechanical behavior and class identity. Might Hero. Upon leveling up, most of the time gains Attack...

⚔️ Initial Attributes

The starting statistics given to any hero belonging to this class (queried from the HeroClass table).

Variable Description Value
offence Base Attack attribute. 2
defence Base Defense attribute. 2
spell_power Base Spell Power attribute. 2
intelligence Base Knowledge / Intelligence attribute. 1
luck Base Luck value. 0
morale Base Morale value. 0

📈 Stat Probability Growth (Leveling up)

Weights determining the percentage chance of a specific stat increasing upon reaching a new level.

Variable Description Example (might_dungeon)
roll_lvl1_attack % chance to gain Attack between levels 1 and 23. 30
roll_lvl1_defense % chance to gain Defense between levels 1 and 23. 35
roll_lvl1_power % chance to gain Spell Power between levels 1 and 23. 20
roll_lvl1_knowledge % chance to gain Knowledge between levels 1 and 23. 15
roll_lvl24_attack % chance to gain Attack at level 24 and above. 25
roll_lvl24_defense % chance to gain Defense at level 24 and above. 25
roll_lvl24_power % chance to gain Spell Power at level 24 and above. 25
roll_lvl24_knowledge % chance to gain Knowledge at level 24 and above. 25

⚙️ Technical Properties

Miscellaneous configuration variables mapped out in the class template definition.

Variable Description Example
faction The structural faction this class belongs to. dungeon
class_type The primary archetype profile. might or magic
native_biome The preferred battlefield and movement environment. Dirt
skills_roll_variant The table pointer determining skill weight probabilities. dungeon_might_skills_table
cost_gold Hiring fee required to purchase a hero of this class. 2500
enable_tactics Boolean indicating if the Tactics phase is enabled. yes / no

---

Practical Examples

Example 1: Fetching Localized Class Names

To display the French name of the Overlord class:

{{#invoke:HeroClassData|get|might_dungeon|name|fr}}

Output: Suzerain

Example 2: Building Template Integration

When listing a hero inside a dynamically generated row, use their underlying class_id to output their localized class text natively:

The hero belongs to the {{#invoke:HeroClassData|get|{{{class_id}}}|name|{{{lang|en}}}}} archetype.

local p = {}

-- Fonction principale pour récupérer une donnée de classe de héros
-- Syntaxe : {{#invoke:HeroClassData|get|ID_CLASSE|CHAMP|LANGUE}}
function p.get(frame)
    local args = frame.args[1] and frame.args or frame:getParent().args
    local class_id = args[1]
    local field = args[2]
    local lang = args[3] or 'en' -- Anglais par défaut

    if not class_id or not field then
        return "Erreur : ID de classe ou champ manquant."
    end

    -- 1. Gestion des champs textuels traduits (name, description)
    if field == 'name' or field == 'description' then
        -- Dans TranslationDef, le type pour ces lignes est "hero_class"
        local queryOpts = {
            where = string.format('target_id="%s" AND language="%s" AND type="hero_class"', class_id, lang)
        }
        
        local res = mw.ext.cargo.query('Translation', field, queryOpts)

        if res and res[1] and res[1][field] then
            return res[1][field]
        else
            -- Système de secours (fallback) vers l'anglais si la langue voulue est absente
            if lang ~= 'en' then
                local fallbackOpts = {
                    where = string.format('target_id="%s" AND language="en" AND type="hero_class"', class_id)
                }
                local fallbackRes = mw.ext.cargo.query('Translation', field, fallbackOpts)
                if fallbackRes and fallbackRes[1] and fallbackRes[1][field] then
                    return fallbackRes[1][field]
                end
            end
            return "" 
        end
    end

    -- 2. Gestion des statistiques et données brutes de la table "HeroClass"
    local classOpts = {
        where = string.format('id="%s"', class_id)
    }
    local classRes = mw.ext.cargo.query('HeroClass', field, classOpts)

    if classRes and classRes[1] and classRes[1][field] then
        return classRes[1][field]
    end

    return ""
end

return p