Dungeon Boss Wiki
Advertisement

Documentation for this module may be created at Module:Epics/doc

--
-- Module to provide access to Epics data
--
local p = {}
 
local dataModule = "Module:Epics/data"

-- helper to convert map keys to string list
local function keysToString(map, sep)
  if map == nil then
    return ""
  end
  
  local result = {}
  for key, _ in pairs(map) do
    result[#result+1] = key
  end
  table.sort(result)
  return table.concat(result, sep)
end

local function listToString(list)
  if list == nil then
    return ""
  end
    
  local result = {}
  for _, e in ipairs(list) do
    result[#result+1] = e
  end
  return table.concat(result, "/")
end


-- get|<epicId>|<attribute>
-- returns requested attribute of the given epic 
-- debug console: =p.get({args={"Archangel Emily", "effect"}})
--    returns "Chance to deal 2.5x damage and gain 2 energy."
function p.get(frame)
  local args = (frame.args[1] ~= nil) and frame.args or frame:getParent().args
  local data = mw.loadData(dataModule)
  local epicId = string.lower(args[1])
  local attr = args[2]
  local epic = data[epicId]
  if epic == nil then
    return ""
  end
  local value = epic[attr]
  
  if ( type(value) == "table" ) then
    if value[1] == nil then -- map or list?
      return keysToString(value, "/") 
    else
      return listToString(value, "/")
    end
  else
     return value
  end
end

--
-- ids|<element filter>
--   filter: "Fire", "Dark", etc. No filter=all
--   returns string list with ids of epics ("Archangel Emily/Augustus/Bovus El Doro/../...")
-- debug console: =p.ids({args={"Water"}})
function p.ids(frame)
  local args = frame.args
  local filterType = nil
  if args[1] ~= nil then
    mw.log("args1 is", (args[1]))
    filterType = args[1]
  end
  local epicIds = {}
  local data = mw.loadData(dataModule)
  for eid, epic in pairs(data) do
    --mw.log("lookup -> ", eid, filterType)
    if filterType == nil or epic.materials.element == filterType then
      epicIds[#epicIds+1] = eid
    end
  end
  table.sort(epicIds)
  return table.concat(epicIds, "/")
end

return p
Advertisement