Module:AbilityTable: Difference between revisions

Jump to navigation Jump to search
Replace key-based hero lookup with name-based; drop _hero_lookup entirely (with help from vergir-bot LLM)
Remove CC_PROPS duplication; derive ordered prop list from debuff_prop_to_effect keys at load time (with help from vergir-bot LLM)
Line 282: Line 282:


-- Maps AbilityData property names to human-readable effect names for the debuff table.
-- Maps AbilityData property names to human-readable effect names for the debuff table.
-- Ordered list ensures deterministic effect output; pairs() iteration order is not guaranteed.
-- DebuffDuration is absent: it signals "(See notes)" on Duration rather than a named effect.
-- DebuffDuration is absent: it signals "(See notes)" on Duration rather than a named effect.
local debuff_prop_to_effect = {
local debuff_prop_to_effect = {
Line 297: Line 298:
     TimeSlowDuration    = "Time Slow",
     TimeSlowDuration    = "Time Slow",
     LateCheckoutStun    = "Stun",
     LateCheckoutStun    = "Stun",
}
-- Ordered list of keys from debuff_prop_to_effect, used to iterate props deterministically.
local debuff_props_ordered = {
    "StunDuration", "SleepDuration", "SilenceDuration", "SilenceDebuff",
    "PetrifyDuration", "HexDuration", "ImmobilizeDuration", "LiftDuration",
    "SlowPercent", "HoldInPlaceDuration", "DebuffAccuracy",
    "TimeSlowDuration", "LateCheckoutStun",
}
}


Line 313: Line 322:
         return cells
         return cells
     end
     end
    local CC_PROPS = {
        "StunDuration", "SleepDuration", "SilenceDuration", "SilenceDebuff",
        "PetrifyDuration", "HexDuration", "ImmobilizeDuration", "LiftDuration",
        "SlowPercent", "HoldInPlaceDuration", "DebuffAccuracy",
        "TimeSlowDuration", "LateCheckoutStun",
    }


     local effects_seen = {}  -- ordered list of { name, tier }
     local effects_seen = {}  -- ordered list of { name, tier }
     local effects_set  = {}  -- effect name -> true, for dedup
     local effects_set  = {}  -- effect name -> true, for dedup


     -- Base fields
     local function collect_effects(obj, tier)
    for _, prop in ipairs(CC_PROPS) do
        for _, prop in ipairs(debuff_props_ordered) do
        local val    = ability[prop]
            local val    = obj[prop]
        local effect = debuff_prop_to_effect[prop]
            local effect = debuff_prop_to_effect[prop]
        if val and val ~= 0 and effect and not effects_set[effect] then
            if val and val ~= 0 and effect and not effects_set[effect] then
            table.insert(effects_seen, { name = effect, tier = nil })
                table.insert(effects_seen, { name = effect, tier = tier })
            effects_set[effect] = true
                effects_set[effect] = true
            end
         end
         end
     end
     end


     -- Upgrade fields
     collect_effects(ability, nil)
     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
     if type(upgrades) == "table" then
     if type(upgrades) == "table" then
         for i, tier in ipairs(upgrades) do
         for i, tier in ipairs(upgrades) do
             if type(tier) == "table" then
             if type(tier) == "table" then
                 for _, prop in ipairs(CC_PROPS) do
                 collect_effects(tier, i)
                    local val    = tier[prop]
                    local effect = debuff_prop_to_effect[prop]
                    if val and val ~= 0 and effect and not effects_set[effect] then
                        table.insert(effects_seen, { name = effect, tier = i })
                        effects_set[effect] = true
                    end
                end
             end
             end
         end
         end
Line 379: Line 375:
     }
     }
     local dur_found = {}
     local dur_found = {}
     for _, f in ipairs(DUR_FIELDS) do
     local function collect_durations(obj)
        local val = num_val(ability[f])
        for _, f in ipairs(DUR_FIELDS) do
        if val and val > 0 then dur_found[f] = val end
            if not dur_found[f] then
                local val = num_val(obj[f])
                if val and val > 0 then dur_found[f] = val end
            end
        end
     end
     end
    collect_durations(ability)
     if type(upgrades) == "table" then
     if type(upgrades) == "table" then
         for _, tier in ipairs(upgrades) do
         for _, tier in ipairs(upgrades) do
             if type(tier) == "table" then
             if type(tier) == "table" then collect_durations(tier) end
                for _, f in ipairs(DUR_FIELDS) do
                    if not dur_found[f] then
                        local val = num_val(tier[f])
                        if val and val > 0 then dur_found[f] = val end
                    end
                end
            end
         end
         end
     end
     end