FANDOM

 
18,614 Pages

-- <nowiki>  ... hide this module's contents from the wikitext parser
 
-- Module to generate a Drops table for an enemy in XC1.
 
local xc1Drops = {}
 
-- Format of a Wood table row
local rowFormatWood = [[
|-
| class="dropitem" | %s
| class="droprate" | %s%%
]]
 
-- Format of a Silver or Gold table row with a details column
local rowFormatDetails = [[
|-
| class="dropitem" | %s
| class="dropslot" | %s
| class="droprate" | %s%%
]]
 
-- Format of a Silver or Gold table row without a details column
local rowFormatNoDetails = [[
|-
| class="dropitem" colspan="2" | %s
| class="droprate" | %s%%
]]
 
--[==[ ------------------------------------------
 
Function to generate a link, hiding any disambig text (parenthesis)
 
]==]
local function plainlink( pagename )
    -- strip " (…)" from end of name, if present
    local shortname = mw.ustring.gsub( pagename, " *%(.*", "" )
 
    if pagename == "" then
        return pagename
    elseif shortname == pagename then
        return "[[" .. pagename .. "]]"
    else
        return "[[" .. pagename .. "|" .. shortname .. "]]"
    end
end
 
--[==[ ------------------------------------------
 
Function to display a slot count
 
]==]
local function slotcount( slots )
    if tonumber(slots) == 1 then
        return slots .. " slot"
    else
        return slots .. " slots"
    end
end
 
--[==[ ------------------------------------------
 
Function to generate a Wood Chest drops table.
 
]==]
function xc1Drops.Wood( frame )
  local arglist = frame:getParent().args
 
  -- Start of table and column headers
  local result = {}
  table.insert( result, '{| class="xc1 wood chest"' )
  table.insert( result, '! colspan="2" | Materials' )
 
  for i=1,2 do
    item = arglist[ "material" .. i ]
    if item == nil then break end
    rate = arglist[ "mrate" .. i ] or "??"
 
    table.insert( result,
      mw.ustring.format( rowFormatWood, plainlink(item), rate )
    )
  end
 
  -- End of the table
  table.insert( result, "|}" )
 
  -- Merge the array elements into one string, separated by newline characters.
  return table.concat( result, '\n' )
end
 
 
--[==[ ------------------------------------------
 
Function to generate a Silver Chest drops table with Crystals.
 
]==]
function xc1Drops.SilverCrystal( frame )
  local arglist = frame:getParent().args
 
  -- Start of table and column headers
  local result = {}
  table.insert( result, '{| class="xc1 silver chest"' )
 
  -- CRYSTALS
  numrows = tonumber(arglist[ "numbercrystals" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result,
      mw.ustring.format( '! colspan="3" | %s Crystals', arglist[ "family" ] or "" )
    )
    rate = arglist[ "crystalrate" ] or "??"
    for i=1,2 do
      itemA = arglist[ "crystal" .. i .. "a" ]
      itemB = arglist[ "crystal" .. i .. "b" ]
 
      if itemB == nil then
        item = plainlink(itemA)
      else
        item = plainlink(itemA) .. " / " .. plainlink(itemB)
      end
      table.insert( result,
        mw.ustring.format( rowFormatNoDetails, item, rate )
      )
    end
  end
 
  -- WEAPONS
  numrows = tonumber(arglist[ "numberweapons" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Weapons' )
    for i=1,numrows do
      item = arglist[ "weapon" .. i ]
      slot = arglist[ "wslots" .. i ]
      rate = arglist[ "wrate" .. i ]
      if item == nil or slot == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), slotcount(slot), rate )
        )
    end
  end
 
  -- ARMOURS
  numrows = tonumber(arglist[ "numberarmours" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Armours' )
    for i=1,numrows do
      item = arglist[ "armour" .. i ]
      slot = arglist[ "aslots" .. i ]
      rate = arglist[ "arate" .. i ]
      if item == nil or slot == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), slotcount(slot), rate )
        )
    end
  end
 
  -- End of the table
  table.insert( result, "|}" )
 
  -- Merge the array elements into one string, separated by newline characters.
  return table.concat( result, '\n' )
end
 
--[==[ ------------------------------------------
 
Function to generate a Silver Chest drops table with Cylinders.
 
]==]
function xc1Drops.SilverCylinder( frame )
  local arglist = frame:getParent().args
 
  -- Start of table and column headers
  local result = {}
  table.insert( result, '{| class="xc1 silver chest"' )
 
  -- CYLINDERS
  table.insert( result, '! colspan="3" | Cylinders' )
  rate = arglist[ "crystalrate" ] or "??"
  for i=1,2 do
    item = arglist[ "cylinder" .. i ]
    element = arglist[ "element" .. i ]
    if item == nil or element == nil then break end
 
    table.insert( result,
      mw.ustring.format( rowFormatDetails, plainlink(item), element, rate )
    )
  end
 
  -- WEAPONS
  numrows = tonumber(arglist[ "numberweapons" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Weapons' )
    for i=1,numrows do
      item = arglist[ "weapon" .. i ]
      slot = arglist[ "wslots" .. i ]
      rate = arglist[ "wrate" .. i ]
      if item == nil or slot == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), slotcount(slot), rate )
        )
    end
  end
 
  -- ARMOURS
  numrows = tonumber(arglist[ "numberarmours" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Armours' )
    for i=1,numrows do
      item = arglist[ "armour" .. i ]
      slot = arglist[ "aslots" .. i ]
      rate = arglist[ "arate" .. i ]
      if item == nil or slot == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), slotcount(slot), rate )
        )
    end
  end
 
  -- End of the table
  table.insert( result, "|}" )
 
  -- Merge the array elements into one string, separated by newline characters.
  return table.concat( result, '\n' )
end
 
 
 
--[==[ ------------------------------------------
 
Function to generate a Gold Chest drops table.
 
]==]
function xc1Drops.Gold( frame )
  local arglist = frame:getParent().args
 
  -- Start of table and column headers
  local result = {}
  table.insert( result, '{| class="xc1 gold chest"' )
 
  -- WEAPONS
  numrows = tonumber(arglist[ "numberweapons" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Weapons' )
    for i=1,numrows do
      item = arglist[ "weapon" .. i ]
      slot = arglist[ "wslots" .. i ]
      rate = arglist[ "wrate" .. i ]
      if item == nil or slot == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), slotcount(slot), rate )
        )
    end
  end
 
  -- UNIQUE WEAPONS
  numrows = tonumber(arglist[ "numberuniqueweapons" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Unique Weapons' )
    for i=1,numrows do
      item = arglist[ "uweapon" .. i ]
      rate = arglist[ "uwrate" .. i ]
      if item == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatNoDetails, plainlink(item), rate )
        )
    end
  end
 
  -- UNIQUE ARMOURS
  numrows = tonumber(arglist[ "numberuniquearmours" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Unique Armours' )
    for i=1,numrows do
      item = arglist[ "uarmour" .. i ]
      rate = arglist[ "uarate" .. i ]
      if item == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatNoDetails, plainlink(item), rate )
        )
    end
  end
 
  -- ART BOOKS
  numrows = tonumber(arglist[ "numberartbooks" ] or 0)
  if ( numrows > 0 ) then
    table.insert( result, '|-\n! colspan="3" | Advanced Art Books' )
    for i=1,numrows do
      item = arglist[ "book" .. i ]
      rate = arglist[ "brate" .. i ]
      who  = arglist[ "bwho" .. i ] or ""
      if item == nil or rate == nil then break end
        table.insert( result,
          mw.ustring.format( rowFormatDetails, plainlink(item), plainlink(who), rate )
        )
    end
  end
 
  -- End of the table
  table.insert( result, "|}" )
 
  -- Merge the array elements into one string, separated by newline characters.
  return table.concat( result, '\n' )
end
 
return xc1Drops
 
-- </nowiki>  ... end of this module's contents
Community content is available under CC-BY-SA unless otherwise noted.