Anonymous

Module:Township: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 259: Line 259:
['melvorF:Clothing'] = {traderMatches = matchClothing}
['melvorF:Clothing'] = {traderMatches = matchClothing}
}
}
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id].traderMatches))
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id].traderMatches))
end
end
-- Calculate the conversion ratios
-- Calculate the trader's conversion ratios
-- See township.js TownshipResource.getBaseConvertToTownshipRatio and TownshipResource.getBaseConvertFromTownshipRatio for the conversion prices
-- See township.js TownshipResource.getBaseConvertToTownshipRatio and TownshipResource.getBaseConvertFromTownshipRatio for the conversion prices
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
Line 298: Line 299:
-- Builds the table of trader items
-- Builds the table of trader items
function Data.Township.getTraderTable(frame)
function Data.Township.getTraderTable(frame)
-- Get the resources data with associated trader data
local resources = Data.Township.Trader()
local resources = Data.Township.Trader()
-- Build the text
local ret = {}
local ret = {}
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
if #resource.itemConversions ~= 0 then -- Skips GP
if #resource.itemConversions ~= 0 then -- Skips GP
local ret_resource = {}
local ret_resource = {}
-- Header
table.insert(ret_resource, '\r\n==='..resource.name..'===')
table.insert(ret_resource, '\r\n==='..resource.name..'===')
table.insert(ret_resource, '\r\n{| class="wikitable sortable stickyHeader"')
table.insert(ret_resource, '\r\n{| class="wikitable sortable stickyHeader"')
Line 315: Line 320:
table.insert(ret_resource, '\r\n!Value')
table.insert(ret_resource, '\r\n!Value')
table.insert(ret_resource, '\r\n!Value/Resource')
table.insert(ret_resource, '\r\n!Value/Resource')
if resource.id =='Food' then
if resource.id =='melvorF:Food' then
table.insert(ret_resource, '\r\n!Heals')
table.insert(ret_resource, '\r\n!Heals')
table.insert(ret_resource, '\r\n!Heals/Resource')
table.insert(ret_resource, '\r\n!Heals/Resource')
end
end
-- Each item
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
-- Find the recipe to get the required level
-- To indicate the skill level, we need to find the recipe of the item in the target skill
-- Unfortunately Module:Items/SourceTables.getItemSources does not provide parseable data
local required_level = nil
local required_level = nil
local recipes = nil
local recipes = nil
local skill = resource._skill
-- Get the skill based on the item.id or else use the resource's default skill
local skill_overrides = {
['melvorD:Raw_Magic_Fish'] = 'Fishing',
['melvorF:Apple'] = 'Farming',
}
local skill = skill_overrides[item.id] or resource._skill
-- Check for upgraded Crafting items and downgrade them so we can display the crafting level for the base item
-- e.g. converts Black_Dhide_Body_U -> Black_Dhide_Body for the purposes of the lookup
local lookup_id = item.id
local lookup_id = item.id
-- A few special skill overrides
if string.match(item.id, '_U$') then
if item.id == 'Raw_Magic_Fish' then
skill = 'Fishing'
elseif item.id == 'Apple' then
skill = 'Farming'
elseif string.match(item.id, '_U$') then
-- Upgraded Crafting item. Display the level for the base item
-- Converts Black_Dhide_Body_U -> Black_Dhide_Body for the purposes of the lookup
lookup_id = string.sub(item.id, 1, #item.id - 2)
lookup_id = string.sub(item.id, 1, #item.id - 2)
end
end
-- Find the recipe
local recipes = Data.Item.FindRecipes(lookup_id, skill)
local recipes = Data.Item.FindRecipes(lookup_id, skill)
if #recipes == 1 then
if #recipes == 1 then
required_level = recipes[1].level
required_level = recipes[1].level
end
end
-- Alright, now that we've found the required recipe and level, we can draw the item's row entry
table.insert(ret_resource, '\r\n|-')
table.insert(ret_resource, '\r\n|-')
-- Icon
-- Icon
572

edits