FANDOM


--
-- Module to provide access to Effects/data 
--  documentation: see Template:Effects/doc
--  test module: Effects/test
local p = {}
 
local dataModule = "Module:Effects/data"
 
-- To test enter in console:
--   =p.skinsWithEffect( { args={'diseased'}})
function p.skinsWithEffect(frame)
    local args = frame.args
	local lookup = mw.loadData("Module:Abilities/view/heroesByEffect")
	local effectId = string.lower(args[1])
 
    local skinList = lookup.skins[effectId]
    if skinList == nil then return "" end  -- unknown effectId or no skins
 
    local utils = require("Module:LibTableUtils")
    return utils.listToString(skinList, "/")
end
 
-- function to get the heroes who have a trait or ability with the given effectId. 
-- returns list as string. If named arg 'sep' not set then 
--    only a list of heroes who have a trait or ability with effectId is returned 
--    e.g. "Ekko/Ignus the Mad/..."
--  if 'sep' is present then string of pairs separated by 'sep' is returned
--    e.g. sep="+" returns "agnon-plummeting doom/ella ametryst-charm+kiss of death/indigo=..."
-- To test enter in console:
--   =p.heroesWithEffect( { args={'diseased'}})
function p.heroesWithEffect(frame)
    local args = frame.args
	local lookup = mw.loadData("Module:Abilities/view/heroesByEffect")
	local effectId = string.lower(args[1])
	local listSeparator = args['sep']
 
    local heroesMap = lookup.heroes[effectId]
    if heroesMap == nil then return "" end  -- unknown effectId or no heroes
 
    local result = {}
    local utils = require("Module:LibTableUtils")
    for heroId, abilities in pairs(heroesMap) do
        -- mw.log(heroId, abilities)
        if listSeparator ~= nil then
            result[#result+1] = heroId .. '-' .. utils.listToString(abilities, listSeparator)
        else 
            result[#result+1] = heroId
        end
    end
    table.sort(result)
    return table.concat(result, "/")    
end
 
-- To test enter in console:
--   =p.epicsWithEffect( { args={'dazed'}})
function p.epicsWithEffect(frame)
    local args = frame.args
	local lookup = mw.loadData("Module:Epics/view/epicsByEffect")
	local effectId = string.lower(args[1])
 
    local epicList = lookup[effectId]
    if epicList == nil then return "" end  -- unknown effectId or no epics
 
    local utils = require("Module:LibTableUtils")
    return utils.listToString(epicList, "/")
end
 
--
-- get|<effectId>|<attribute>|<sep=separator>
-- To test enter
--   =p.get( { args={'dazed', 'description'}})
--   =p.get( { args={'dazed', 'heroes', sep='+'}})  -- list of heroes and their traits/abilities with that effect
-- in console
-- returns attribute value or calculated list (heroes, epics)
--
function p.get(frame)
    local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
 
	local data = mw.loadData(dataModule)
	local effectId = string.lower(args[1])
	local attr = string.lower(args[2])
	local effect = data[effectId]
	if ( effect and type(effect) == "table" ) then
    --mw.log("lookup -> ", effect[attr])
	    if attr == "heroes" then
	        return heroesWithEffect(effectId, false, args['sep'])
	    elseif attr == "epics" then
	        return heroesWithEffect(effectId, true)
	    else
	        local value = effect[attr]
	        if type(value) == "table" then
	            util = require("Module:LibTableUtils")
                if value[1] == nil then 
                    return util.keysToString(value)
                else 
                    return util.listToString(value)
                end
            else
	            return value
	       end
	    end
	end
	return nil
end
 
--
-- ids|<filter>
--   filter: "debuff", "buff" or nothing (=no filter)
--   returns string list with effect ids ("burned/chilled/dazed/...")
--
function p.ids(frame)
    local args = frame.args
    local filterType = nil
	if args[1] ~= nil then
	    filterType = string.lower(args[1])
	end
    local effectIds = {}
    local data = mw.loadData(dataModule)
    for id, effect in pairs(data) do 
        if filterType == nil or effect.type == filterType then
            effectIds[#effectIds+1] = id
        end
    end
    table.sort(effectIds)
    return table.concat(effectIds, "/")
end
 
-- return list of a categories of the effects
-- =p.categoryIds( { args={ 'debuff' }})
function p.categoryIds(frame)
    local args = frame.args
    local effectType = string.lower(args[1])
    local categories = {}
    local effectCatData = mw.loadData("Module:Effects/view/effectsByCategory")
    local data = effectCatData[effectType]
    if data == nil then 
        return '??' .. effectType .. '??' 
    end
    for cat, _ in pairs(data) do 
        categories[#categories+1] = cat
    end
    table.sort(categories)
    return table.concat(categories, "/")
end
 
-- =p.category( { args={ 'debuff', 'Damage over Time'}})
function p.category(frame)
    local args = frame.args
    local effectType = string.lower(args[1])
    local categories = {}
    local libUtils = require("Module:LibTableUtils")
    local effectCatData = mw.loadData("Module:Effects/view/effectsByCategory")
    local data = effectCatData[effectType]
    if data == nil then 
        return '??' .. effectType .. '??' 
    else
        return libUtils.listToString(data[args[2]], nil, true)
    end
end
 
 
return p
Community content is available under CC-BY-SA unless otherwise noted.