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 difference)

Revision as of 20:29, 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

return p