Difference between revisions of "Module:Skills"

From Melvor Idle
(Fixed sorting on growth times)
(Added getMiningTable)
Line 113: Line 113:
  
 
   return p._getFarmingTable(category)
 
   return p._getFarmingTable(category)
 +
end
 +
 +
function p.getMiningTable(frame)
 +
  local result = '{|class="wikitable sortable stickyHeader"'
 +
  result = result..'\r\n|- class="headerRow-0"'
 +
  result = result..'\r\n!colspan=2|Ore!!'..Icons.Icon({'Mining', type='skill', notext=true})..' Level'
 +
  result = result..'!!XP!!Respawn Time!!Ore Value'
 +
  local mineData = Shared.clone(SkillData.Mining)
 +
  table.sort(mineData, function(a, b) return a.level < b.level end)
 +
  for i, oreData in Shared.skpairs(mineData) do
 +
    local ore = Items.getItemByID(oreData.ore)
 +
    result = result..'\r\n|-\r\n|'..Icons.Icon({ore.name, type='item', size='50', notext=true})..'||'..ore.name
 +
    result = result..'||'..oreData.level..'||'..ore.miningXP
 +
    result = result..'||data-sort-interval="'..oreData.respawnInterval.."'|"
 +
    result = result..Shared.timeString(oreData.respawnInterval / 1000, true)
 +
    result = result..'||data-sort-value="'..ore.sellsFor..'"|'..Icons.GP(ore.sellsFor)
 +
  end
 +
 +
  result = result..'\r\n|}'
 +
  return result
 
end
 
end
  
 
return p
 
return p

Revision as of 16:15, 27 October 2020

Data pulled from Module:Skills/data


local p = {}

local SkillData = mw.loadData('Module:Skills/data')
local Constants = mw.loadData('Module:Constants/data')

local Shared = require('Module:Shared')
local Items = require('Module:Items')
local Icons = require('Module:Icons')

local MasteryCheckpoints = {.1, .25, .5, .95}

function p.getSkillID(skillName)
  for skName, ID in Shared.skpairs(Constants.skill) do
    if skName == skillName then
      return ID
    end
  end
  return nil
end

function p.getMasteryUnlockTable(frame)
  local skillName = frame.args ~= nil and frame.args[1] or frame
  local skillID = p.getSkillID(skillName)
  if skillID == nil then
    return "ERROR: Failed to find a skill ID for "..skillName
  end

  local unlockTable = SkillData.MasteryUnlocks[skillID]
  if unlockTable == nil then
    return 'ERROR: Failed to find Mastery Unlock data for '..skillName
  end

  local result = '{|class="wikitable"\r\n!Level!!Unlock'
  for i, unlock in Shared.skpairs(unlockTable) do
    result = result..'\r\n|-'
    result = result..'\r\n|'..unlock.level..'||'..unlock.unlock
  end
  result = result..'\r\n|}'
  return result
end

function p.getMasteryCheckpointTable(frame)
  local skillName = frame.args ~= nil and frame.args[1] or frame
  local skillID = p.getSkillID(skillName)
  if skillID == nil then
    return "ERROR: Failed to find a skill ID for "..skillName
  end

  if SkillData.MasteryCheckpoints[skillID] == nil then
    return 'ERROR: Failed to find Mastery Unlock data for '..skillName
  end

  local bonuses = SkillData.MasteryCheckpoints[skillID].bonuses
  local totalPoolXP = SkillData.MasteryPoolXP[skillID + 1]

  local result = '{|class="wikitable"\r\n!Pool %!!style="width:100px"|Pool XP!!Bonus'
  for i, bonus in Shared.skpairs(bonuses) do
    result = result..'\r\n|-'
    result = result..'\r\n|'..(MasteryCheckpoints[i] * 100)..'%||'
    result = result..Shared.formatnum(totalPoolXP * MasteryCheckpoints[i])..' xp||'..bonus
  end
  result = result..'\r\n|-\r\n!colspan="2"|Total Mastery Pool XP'
  result = result..'\r\n|'..Shared.formatnum(totalPoolXP)
  result = result..'\r\n|}'
  return result
end

function p._getFarmingTable(category)
  local seedList = {}
  if category == 'Allotment' or category == 'Herb' or category == 'Tree' then
    seedList = Items.getItems(function(item) return item.tier == category end)
  else
    return 'ERROR: Invalid farming category. Please choose Allotment, Herb, or Tree'
  end

  local result = '{|class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan=2|Seeds!!'..Icons.Icon({'Farming', type='skill', notext=true})..' Level'
  result = result..'!!XP!!Growth Time!!Seed Value'
  if category == 'Allotment' then
    result = result..'!!colspan="2"|Crop!!Crop Healing!!Crop Value'
  elseif category == 'Herb' then
    result = result..'!!colspan="2"|Herb!!Herb Value'
  elseif category == 'Tree' then
    result = result..'!!colspan="2"|Logs!!Log Value'
  end
  result = result..'!!Seed Sources'
  
  table.sort(seedList, function(a, b) return a.farmingLevel < b.farmingLevel end)

  for i, seed in pairs(seedList) do
    result = result..'\r\n|-'
    result = result..'\r\n|'..Icons.Icon({seed.name, type='item', size='50', notext=true})..'||[['..seed.name..']]'
    result = result..'||'..seed.farmingLevel..'||'..Shared.formatnum(seed.farmingXP)
    result = result..'||data-sort-value="'..seed.timeToGrow..'"|'..Shared.timeString(seed.timeToGrow, true)
    result = result..'||data-sort-value="'..seed.sellsFor..'"|'..Icons.GP(seed.sellsFor)

    local crop = Items.getItemByID(seed.grownItemID)
    result = result..'||'..Icons.Icon({crop.name, type='item', size='50', notext=true})..'||[['..crop.name..']]'
    if category == 'Allotment' then
      result = result..'||'..Icons.Icon({'Hitpoints', type='skill', notext=true})..' '..(crop.healsFor * 10)
    end
    result = result..'||data-sort-value="'..crop.sellsFor..'"|'..Icons.GP(crop.sellsFor)
    result = result..'||'..Items._getItemSources(seed)
  end

  result = result..'\r\n|}'
  return result
end

function p.getFarmingTable(frame)
  local category = frame.args ~= nil and frame.args[1] or frame

  return p._getFarmingTable(category)
end

function p.getMiningTable(frame)
  local result = '{|class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan=2|Ore!!'..Icons.Icon({'Mining', type='skill', notext=true})..' Level'
  result = result..'!!XP!!Respawn Time!!Ore Value'
  local mineData = Shared.clone(SkillData.Mining)
  table.sort(mineData, function(a, b) return a.level < b.level end)
  for i, oreData in Shared.skpairs(mineData) do
    local ore = Items.getItemByID(oreData.ore)
    result = result..'\r\n|-\r\n|'..Icons.Icon({ore.name, type='item', size='50', notext=true})..'||'..ore.name
    result = result..'||'..oreData.level..'||'..ore.miningXP
    result = result..'||data-sort-interval="'..oreData.respawnInterval.."'|"
    result = result..Shared.timeString(oreData.respawnInterval / 1000, true)
    result = result..'||data-sort-value="'..ore.sellsFor..'"|'..Icons.GP(ore.sellsFor)
  end

  result = result..'\r\n|}'
  return result
end

return p