FANDOM


local p = {}
local heroCount = 0
local returnErrorFields = false
local errorFields = ''
local tierCount = 1
local tierLetters = {
  [1] = 'S+',
  [2] = 'S',
  [3] = 'S-',
  [4] = 'A+',
  [5] = 'A',
  [6] = 'A-',
  [7] = 'B+',
  [8] = 'B',
  [9] = 'B-',
  [10] = 'C'
}
-- Defining table cells 
-- (12 nested tables b/c 12 diff. weapon types)
local tiers = {
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}},
  {{},{},{},{},{},{},{},{},{},{},{},{}}
}
 
function p._tierList(t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,frame,iconflag)
  parseThroughTier(t1,frame)
  parseThroughTier(t2,frame)
  parseThroughTier(t3,frame)
  parseThroughTier(t4,frame)
  parseThroughTier(t5,frame)
  parseThroughTier(t6,frame)
  parseThroughTier(t7,frame)
  parseThroughTier(t8,frame)
  parseThroughTier(t9,frame)
  parseThroughTier(t10,frame)
 
  if not true then
    return createTable(frame,iconflag) .. "hero count: " .. heroCount .. "errors: " .. errorFields .. mw.title.getCurrentTitle().text
  end
  return createTable(frame,iconflag)
end
 
function parseThroughTier(tier,frame)
  if tier ~= '' then
    for k,heroName in ipairs(tier) do
      local weaponQuery = mw.smw.getQueryResult( '[[Category:Heroes]][[HeroName::' .. heroName .. ']]|?WeaponType')
      if weaponQuery.results[1] ~= nil then
        heroCount = heroCount + 1
        table.insert(tiers[tierCount][getWeaponTypeNum(weaponQuery.results[1].printouts.WeaponType[1])], heroName)
        --errorFields = errorFields .. "nil error" .. heroName .. '<br/>'
      end
      frame:callParserFunction('#vardefine', { heroName , tierLetters[tierCount] })
    end
  end
  tierCount = tierCount + 1
end
 
function createTable(frame,iconflag)
  local tbl = mw.html.create('table')
    :addClass('wikitable tierlist lightblue default')
    :css('text-align','center')
    :css('max-width','1200px')
 
  tbl:tag('th')
    :wikitext('Rating')
    :css('height', '45px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Red Sword.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Red Tome.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Red Breath.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Blue Lance.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Blue Tome.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Blue Breath.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Green Axe.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Green Tome.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Green Breath.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Neutral Bow.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Neutral Dagger.png|32px|link=]]')
    :css('width', '84px')
  tbl:tag('th')
    :wikitext('[[File:Icon Class Neutral Staff.png|32px|link=]]')
    :css('width', '84px')
 
  local iconTemplate = 'Template:TierListUnitBox'
  if iconflag == 'true' or iconflag == 'yes' then
    iconTemplate = 'Template:TierListUnitBoxR'
  end
  tierCount = 1
  for k,v in ipairs(tiers) do
    local tr = tbl:tag('tr')
    tr:tag('td'):wikitext('<b>' .. tierLetters[tierCount] .. '</b>')
    for tier,weaponType in ipairs(v) do
      local cellHeroes = ""
      for wt,hero in ipairs(weaponType) do
        local tierListUnitBox = frame:expandTemplate{ title = iconTemplate, args = { hero } }
        cellHeroes = cellHeroes .. tostring(tierListUnitBox)
      end
      local wtTD = tr:tag('td')
        :wikitext(cellHeroes)
    end
    tierCount = tierCount + 1
  end
  return tostring(tbl)
end
 
-- Copied from http://lua-users.org/wiki/SplitJoin
-- strsplit(seperator, string)
function strsplit(d,p)
   if p == nil then return '' end
   local t, ll
   t={}
   ll=0
   if(#p == 1) then
      return {p}
   end
   while true do
      l = string.find(p, d, ll, true) -- find the next d in the string
      if l ~= nil then -- if "not not" found then..
         table.insert(t, string.sub(p,ll,l-1)) -- Save it in our array.
         ll = l + 1 -- save just after where we found it for searching next time.
      else
         table.insert(t, string.sub(p,ll)) -- Save what's left in our array.
         break -- Break at end, as it should be, according to the lua manual.
      end
   end
   return t
end
 
function getWeaponTypeNum(weaponType)
  local weaponTypeNum = {
    ['Red Sword'] = 1,
    ['Red Tome'] = 2,
    ['Red Breath'] = 3,
    ['Blue Lance'] = 4,
    ['Blue Tome'] = 5,
    ['Blue Breath'] = 6,
    ['Green Axe'] = 7,
    ['Green Tome'] = 8,
    ['Green Breath'] = 9,
    ['Neutral Bow'] = 10,
    ['Neutral Dagger'] = 11,
    ['Neutral Staff'] = 12,
  }
  return weaponTypeNum[weaponType]
end
 
function p.tierList(frame)
  local args = frame.args
  local iconflag = ''
  if args['icons'] ~= nil then
    iconflag = args['icons']
  end
  return p._tierList(strsplit(",",args[1]),strsplit(",",args[2]),strsplit(",",args[3]),strsplit(",",args[4]),strsplit(",",args[5]),strsplit(",",args[6]),strsplit(",",args[7]),strsplit(",",args[8]),strsplit(",",args[9]),strsplit(",",args[10]),frame,iconflag)
end
 
return p
除了特别提示,社区内容遵循CC-BY-SA 授权许可。