Module:SkillUnlocks: Difference between revisions

From Melvor Idle
(Created page with "local p = {} --This module polls various game data sources to produce a full list of skill --level unlocks for each skill. The game has a hard-coded set of "milestones" --for each skill that does the same thing, but it is not exhaustive and not --permanently visible for most combat skills. local Shared = require('Module:Shared') local Icons = require('Module:Icons') local Items = require('Module:Items') function p._getAllItemsWithSkillRequirement(skillReqLabel) local...")
 
No edit summary
Line 31: Line 31:
end
end


function p.getSkillUnlockTable(skillName)
function p._getSkillUnlockTable(skillName)
local skillReqLabel = skillName .. 'LevelRequired'
local skillReqLabel = skillName .. 'LevelRequired'
local itemList = p._getAllItemsWithSkillRequirement(skillReqLabel)
local itemList = p._getAllItemsWithSkillRequirement(skillReqLabel)
Line 73: Line 73:


return table.concat(resultPart)
return table.concat(resultPart)
end
function p.getSkillUnlockTable(frame)
local skillName = frame.args ~= nil and frame.args[1]
return p._getSkillUnlockTable(skillName)
end
end


return p
return p

Revision as of 20:33, 22 April 2023

Documentation for this module may be created at Module:SkillUnlocks/doc

local p = {}

--This module polls various game data sources to produce a full list of skill
--level unlocks for each skill. The game has a hard-coded set of "milestones"
--for each skill that does the same thing, but it is not exhaustive and not
--permanently visible for most combat skills.

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

function p._getAllItemsWithSkillRequirement(skillReqLabel)
	local itemList = Items.getItems(function(item)
		-- Exclude Golbin Raid exclusives
		if item.golbinRaidExclusive ~= nil and item.golbinRaidExclusive then
			return false
		end
		
		return Items._getItemStat(item, skillReqLabel) ~= nil
	end)
	
	local itemsWithReqs = {}
	for i, item in ipairs(itemList) do
		local processedItem = {}
		processedItem.item = item
		processedItem.skillLevel = Items._getItemStat(item, skillReqLabel)
		table.insert(itemsWithReqs, processedItem)
	end
	
	return itemsWithReqs
end

function p._getSkillUnlockTable(skillName)
	local skillReqLabel = skillName .. 'LevelRequired'
	local itemList = p._getAllItemsWithSkillRequirement(skillReqLabel)
	if Shared.tableIsEmpty(itemList) then
		-- TODO: Omit empty tables
		return nil
	end
	
	-- Sort the list of items by level requirement
	table.sort(itemList, function(a, b) 
		return a.skillLevel < b.skillLevel
	end)
	
	-- Header and columns
	local resultPart = {}
	table.insert(resultPart, '{| class="wikitable"\r\n|-class="headerRow-0"')
	table.insert(resultPart, '\r\n!Level')
	table.insert(resultPart, '\r\n!Unlocks')
	
	-- Time to iterate the list!
	local currentLevel = 0
	for i, item in ipairs(itemList) do
		local itemLevel = Items._getItemStat(item.item, skillName .. 'LevelRequired')
		
		-- Start a new row if the current item's level differs from the current
		-- row
		if itemLevel ~= currentLevel then
			currentLevel = itemLevel
			table.insert(resultPart, '\r\n|-')
			table.insert(resultPart, '\r\n|' .. itemLevel)
			table.insert(resultPart, '\r\n|')
		else
			table.insert(resultPart, '<br/>')
		end
		
		-- Append item to the column
		table.insert(resultPart, Icons.Icon({item.item.name, type='item', noicon=true}))
	end
	
	table.insert(resultPart, '\r\n|}')

	return table.concat(resultPart)
end

function p.getSkillUnlockTable(frame)
	local skillName = frame.args ~= nil and frame.args[1]
	return p._getSkillUnlockTable(skillName)
end

return p