FANDOM


local p = {}
local l = require('Module:Link')
 
local bdata = mw.loadData( 'Module:TUBCreator/bonusdata' )
local hdata = mw.loadData( 'Module:TUBCreator/herodata' )
local variables = mw.loadData( 'Module:TUBCreator/variables' )
 
--Sort output table by names
function pairsByKeys (t, f)
  local a = {}
  for n in pairs(t) do table.insert(a, n) end
  table.sort(a, f)
  local i = 0      -- iterator variable
  local iter = function ()   -- iterator function
    i = i + 1
    if a[i] == nil then return nil
    else return a[i], t[a[i]]
    end
  end
  return iter
end
 
function icon(hero)
  return "[[File:"..hero.." Icon 1.png|link="..l.heroLinkArg(hero).."|"..hero.."]]"
end
 
function name(hero)
  return "[["..l.heroLinkArg(hero).."|"..hero.."]]"
end
 
--TUB output
function getTUBIcons(bonus)
  result = ""
  if bdata[bonus]["pairs"] ~= nil then
    for p, pair in pairs(bdata[bonus]["pairs"]) do
      if result ~= "" then
        result = result.." or "..icon(pair[1])..icon(pair[2])
      else
        result = icon(pair[1])..icon(pair[2])
      end
    end
  -- Default handling
  else
    for j, hero_name in pairsByKeys(bdata[bonus]["heroes"]) do
      result = result..icon(hero_name)
    end
  end
  return result 
end
 
function p.getIcons(frame)
    return getTUBIcons(frame.args[1])
end
 
function getTUBNames(bonus)
  result = ""
  if bdata[bonus]["pairs"] ~= nil then
    for p, pair in pairs(bdata[bonus]["pairs"]) do
      if result ~= "" then
        result = result.." or "..name(pair[1])..", "..name(pair[2])
      else
        result = name(pair[1])..", "..name(pair[2])
      end
    end
  -- Default handling
  else
    for j, hero_name in pairsByKeys(bdata[bonus]["heroes"]) do
      if result ~= "" then
        result = result..", "..name(hero_name)
      else
        result = result..name(hero_name)
      end
    end
  end
  return result 
end
 
function p.getNames(frame)
  return getTUBNames(frame.args[1])
end
 
function p.getDescription(frame)
  return bdata[frame.args[1]]["description"]
end
 
-- List of bonuses
function p.bonusList( frame )
  local hero = frame.args[1]
  local output_data = hero.." has the following [[Team-Up Bonuses]]:\n"
  for i, bonus_type in pairs(hdata[hero]) do
    if bdata[bonus_type] ~= nil then
      output_data = output_data.."*'''"..bonus_type.."''': "..bdata[bonus_type]["description"].."\n"
    else
      output_data = output_data.."*'''"..bonus_type.."''': \n"
    end
  end
  return output_data 
end
 
-- Create bonus list for specified hero
function p.createTUBPageData( frame )
  local hero = frame.args[1]
  local bonus_table = {}
  -- No data for hero (announced, etc.)
  if hdata[hero] == nil then
      return "[["..l.heroLinkArg(hero).."|"..hero.."]] doesn't have any Team-Up bonuses currently"
  end
  table.sort(hdata[hero])
  -- Create table with heroes and their bonuses
  for i, bonus_type in pairs(hdata[hero]) do
    -- Special case for paired bonuses (Bad Blood, Fantastic Fill-in)
    if bdata[bonus_type]["pairs"] ~= nil then
      for p, pair in pairs(bdata[bonus_type]["pairs"]) do
        if pair[1] == hero then
          if bonus_table[pair[2]] ~= nil then
            table.insert(bonus_table[pair[2]], bonus_type )
          else
            bonus_table[pair[2]] = {bonus_type}
          end
        elseif pair[2] == hero then
          if bonus_table[pair[1]] ~= nil then
            table.insert(bonus_table[pair[1]], bonus_type )
          else
            bonus_table[pair[1]] = {bonus_type}
          end
        end
      end
    -- Default handling
    else
      for j, hero_name in pairsByKeys(bdata[bonus_type]["heroes"]) do
        if bonus_table[hero_name] ~= nil then
          table.insert(bonus_table[hero_name], bonus_type )
        else
          bonus_table[hero_name] = {bonus_type}
        end
      end
    end
  end
  --Remove self entry
  bonus_table[hero] = nil
 
  -- Fill table with bonuses listed per value
  local bonus_count = {[50] = {}, [100] ={}, [150]={}, [200]={}, [250]={}, [300]={}, [350]={}, [400]={}, [450]={}}
  for hero_name, line in pairsByKeys(bonus_table) do
    local link = l.heroLinkArg(hero_name).."|"..hero_name
    local s = "\n|-\n|[[File:"..hero_name.." Icon 1.png|link="..link.."]]"
    s = s.."\n|[["..link.."]]"
    s = s.."\n|"..table.concat(bonus_table[hero_name], ", ")
    local count = 0
    for i, line in pairs(bonus_table[hero_name]) do
      count = count + 1
    end
    count = count*50
    table.insert(bonus_count[count], s)
  end
 
  -- Start creating table
  -- Team-Up Bonuses listed
  local output_data = "[["..l.heroLinkArg(hero).."|"..hero.."]] has the following [[Team-Up Bonuses]]:\n\n==Team-Up Bonuses==\n"
  for i, bonus_type in pairs(hdata[hero]) do
    if bdata[bonus_type] ~= nil then
      output_data = output_data.."*'''"..bonus_type.."''': "..bdata[bonus_type]["description"].."\n"
    else
      output_data = output_data.."*'''"..bonus_type.."''': \n"
    end
  end
 
  -- All possible Team-Ups
  output_data = output_data.."\n==All Possible Team-Ups==\n"..variables["tubheader"]
  for i, bonus_type in pairs(hdata[hero]) do
      output_data = output_data.."\n|-\n|"..getTUBIcons(bonus_type).."\n|"..getTUBNames(bonus_type).."\n|'''"..bonus_type.."'''"
  end
  output_data = output_data.."\n|}\n\n"
 
  -- Team-Ups per value
  for i, line in pairsByKeys(bonus_count) do
    output_data = output_data.."=="..i.." Point Team-Ups==\n"
    if next(line) ~= nil then
      output_data = output_data..variables["tubheader"]
      output_data = output_data..table.concat(line, "\n").."\n|}\n\n"
    else
      output_data = output_data.."''None''\n\n"
    end
  end
 
  return output_data
end
 
--Get table entry for specified bonus
function bonusTableRow(bonusName)
    return "\n|-\n|'''"..bonusName.."'''\n|"..bdata[bonusName]["description"].."\n|"..getTUBIcons(bonusName)
end
 
function p.getBonusRow(frame)
    return bonusTableRow(frame.args[1])
end
 
function p.GenerateTableList(frame)
  data = variables["listheader"]
  for bonus, value in pairsByKeys(bdata) do
      if string.match(bonus, "^["..frame.args[1].."]") then
        data = data.."\n"..bonusTableRow(bonus)
      end
  end
  return data.."\n|}"
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.