Module:Skills

From Melvor Idle
Revision as of 14:43, 15 October 2020 by Falterfire (talk | contribs) (Formatting fix)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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 pairs(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 %!!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

return p