Anonymous

Module:LevelUpTable/Data: Difference between revisions

From Melvor Idle
Add farming plot data
(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...")
 
(Add farming plot data)
Line 7: Line 7:
local Skills = require('Module:Skills')
local Skills = require('Module:Skills')
local Items = require('Module:Items')
local Items = require('Module:Items')
local Shared = require('Module:Shared')


local UnlockData = {}
local UnlockData = {}
Line 20: Line 21:
end
end


--==== Helper functions ====--
-- Mimicks the C# Select method.
-- Mimicks the C# Select method.
function Select(list, selector)
function Select(list, selector)
Line 27: Line 29:
     end
     end
     return result
     return result
end
function Concat(...)
    local args = {...}
    local result = {}
    for _, tbl in ipairs(args) do
        for _, value in ipairs(tbl) do
            table.insert(result, value)
        end
    end
    return result
end
function getRealmFromID(obj)
local ns, _ = Shared.getLocalID(obj.id)
if ns == 'melvorItA' then
return 'melvorItA:Abyssal'
else
return 'melvorD:Melvor'
end
end
end


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


Line 73: Line 99:
local skillID = 'Farming'
local skillID = 'Farming'
local data = getDataSet(SkillData.Farming.recipes, realm)
local data = getDataSet(SkillData.Farming.recipes, realm)
-- Create lookup for plot category name.
return Select(data, function(x)  
local plotLookup = {}
for _, plot in ipairs(SkillData.Farming.categories) do
        plotLookup[plot.id] = plot.name
    end
 
local seeds = Select(data, function(x)  
local productItem = Items.getItemByID(x.productId)
local productItem = Items.getItemByID(x.productId)
return UnlockData.new(productItem.id, productItem.name, Skills.getRecipeLevel(skillID, x), skillID)
return UnlockData.new(productItem.id, productItem.name, Skills.getRecipeLevel(skillID, x), skillID)
end)
end)
local plotData = getDataSetId(SkillData.Farming.plots, realm)
local plots = Select(plotData, function(x)
return UnlockData.new(x.id, plotLookup[x.categoryID], Skills.getRecipeLevel(skillID, x), "Farming Plot")
end)
return Concat(seeds, plots)
end
end


function p.test()
function p.test()
--local realmName = 'Abyssal Realm'
local realm = Skills.getRealmFromName(realmName)
local realm = Skills.getRealmFromName(realmName)
Debug.log(getFarmingData(realm))
Debug.log(getFarmingData(realm))
2,875

edits