Module:LevelUpTable/Data: Difference between revisions

From Melvor Idle
(Created page with "-- SkillData object that acts as an interface for data shared between skills. local p = {} local Debug = require('Module:Debug') -- < Remove when module is finished. local GameData = require('Module:GameData') local SkillData = GameData.skillData local Skills = require('Module:Skills') local Items = require('Module:Items') local UnlockData = {} UnlockData.__index = UnlockData function UnlockData.new(id, name, level, skill) local self = setmetatable({}, UnlockData...")
(No difference)

Revision as of 16:40, 4 July 2024

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

-- SkillData object that acts as an interface for data shared between skills.
local p = {}

local Debug = require('Module:Debug') --  < Remove when module is finished.
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Skills = require('Module:Skills')
local Items = require('Module:Items')

local UnlockData = {}
UnlockData.__index = UnlockData

function UnlockData.new(id, name, level, skill)
    local self = setmetatable({}, UnlockData)
    self.name = name
    self.level = level
    self.skill = skill
    self.id = id
    return self
end

-- Mimicks the C# Select method.
function Select(list, selector)
    local result = {}
    for _, item in ipairs(list) do
        table.insert(result, selector(item))
    end
    return result
end

function getDataSet(skillData, realm)
	return GameData.getEntities(skillData, function(x) return Skills.getRecipeRealm(x) == realm.id end)
end

--==== Skill Data Collection ====--
function getWoodcuttingData(realm)
	local skillID = 'Woodcutting'
	local data = getDataSet(SkillData.Woodcutting.trees, realm)
	
	return Select(data, function(x) 
		return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
	end)
end

function getMiningData(realm)
	local skillID = 'Mining'
	local data = getDataSet(SkillData.Mining.rockData, realm)
	
	return Select(data, function(x) 
		return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
	end)
end

function getFishingData(realm)
	local skillID = 'Fishing'
	local data = getDataSet(SkillData.Fishing.fish, realm)
	
	return Select(data, function(x) 
		return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
	end)
end

function getThievingData(realm)
	local skillID = 'Thieving'
	local data = getDataSet(SkillData.Thieving.npcs, realm)
	
	return Select(data, function(x) 
		return UnlockData.new(x.id, x.name, Skills.getRecipeLevel(skillID, x), skillID)
	end)
end

function getFarmingData(realm)
	local skillID = 'Farming'
	local data = getDataSet(SkillData.Farming.recipes, realm)
	
	return Select(data, function(x) 
		local productItem = Items.getItemByID(x.productId)
		return UnlockData.new(productItem.id, productItem.name, Skills.getRecipeLevel(skillID, x), skillID)
	end)
end

function p.test()
	local realm = Skills.getRealmFromName(realmName)
	Debug.log(getFarmingData(realm))
end

p.UnlockData = UnlockData
return p