Module:Skill Effects

From Brave Nine Wiki

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

local p = {}
local cargo = mw.ext.cargo

function p._skillEffectList(args, frame)
  -- Cargo Query: Get all Effect Details
  local tables = 'EffectDetails'
  local queryFields = "Id,Name,Type"
  local queryArgs = {
    where = 'Name="' .. args[1] .. '"',
    groupBy = 'Id',
    limit = '999',
    orderBy = "Type"
  }
  
  local queryResult = cargo.query(tables, queryFields, queryArgs)
  if queryResult == nil then
      return "(no values)"
  end
  
  local output = mw.html.create('div')
  local mercenaries = ''

  if type( queryResult ) == "table" then
    -- Go through all the weapons in the query result
    for _, effect in ipairs(queryResult) do
      local skillTable = 'SkillLevels'
      local skillQueryFields = "SkillName"
      local skillQueryArgs = {
        where = 'MainEffect1 = "' .. effect.Id .. '" OR SubEffect11 = "' .. effect.Id .. '" OR SubEffect12 = "' .. effect.Id .. '" OR SubEffect13 = "' .. effect.Id .. '" OR MainEffect2 = "' .. effect.Id .. '" OR SubEffect21 = "' .. effect.Id .. '" OR SubEffect22 = "' .. effect.Id .. '" OR SubEffect23 = "' .. effect.Id .. '" OR MainEffect3 = "' .. effect.Id .. '" OR SubEffect31 = "' .. effect.Id .. '" OR SubEffect32 = "' .. effect.Id .. '" OR SubEffect33 = "' .. effect.Id .. '" OR AwakenedEffect = "' .. effect.Id .. '" OR AwakenedSubEffect1 = "' .. effect.Id .. '" OR AwakenedSubEffect2 = "' .. effect.Id .. '" OR AwakenedSubEffect3 = "' .. effect.Id .. '"',
        limit = '999',
      }

      local skillQueryResult = cargo.query(skillTable, skillQueryFields, skillQueryArgs)
      if skillQueryResult == nil then
          return "(no values)"
      end

      if type( skillQueryResult ) == "table" then
        local skills = ''
        for _, skillLevel in ipairs(skillQueryResult) do
          if string.find(skills, skillLevel.SkillName) then
            -- do nothing
          else
            skills = skills .. skillLevel.SkillName .. ' '
            local charaTable = 'Mercenaries'
            local charaQueryFields = "Name"
            local charaQueryArgs = {
              where = 'Skill = "' .. skillLevel.SkillName .. '"',
              limit = '999',
              orderBy = "Name"
            }

            local charaQueryResult = cargo.query(charaTable, charaQueryFields, charaQueryArgs)
            if charaQueryResult == nil then
                return "(no values)"
            end

            if type( charaQueryResult ) == "table" then
              for _, mercenary in ipairs(charaQueryResult) do
                if string.find(mercenaries, mercenary.Name) then
                  -- do nothing
                else
                  mercenaries = mercenaries .. mercenary.Name
                  output:tag('div')
          :css('display', 'inline-block')
          :wikitext(frame:expandTemplate{
            title = 'Mercenary icon with text',
            args = {
              mercenary.Name
            }
          })
                end
              end
            end
          end
        end
      end
    end
    return tostring(output)
  end
end
    
function p.skillEffectList(frame)
  local getArgs = require 'Module:Arguments'.getArgs
    return p._skillEffectList(getArgs(frame, {wrappers = 'Template:Skill mercenary icon list'}), frame)
end

return p