Module:Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 120: Line 120:
local item = Data.splitID(itemid)
local item = Data.splitID(itemid)
local results = {}
local results = {}
if skill == nil then
return results
end
-- Find the recipe at data.data.skillData -> SKILL.data.KEY
-- Find the recipe at data.data.skillData -> SKILL.data.KEY
Line 166: Line 170:
resources = Shared.clone(resources)
resources = Shared.clone(resources)
-- Append the icon reference to each resource
-- Append the icon reference to each resource, as well as the associated skill for the recipes
-- From https://melvoridle.com/assets/data/melvorFull.json -> data.skillData -> Township.data.resources.media
-- From https://melvoridle.com/assets/data/melvorFull.json -> data.skillData -> Township.data.resources.media
local resource_icons = {
local resource_data = {
['melvorF:GP'] = {'Coins'},
['melvorF:GP'] = {_icon = {'Coins'}, _skill = nil},
['melvorF:Food'] = {'Raw Beef', type='item'},
['melvorF:Food'] = {_icon = {'Raw Beef', type='item'}, _skill = 'Cooking'},
['melvorF:Wood'] = {'Wood', type='resource'},
['melvorF:Wood'] = {_icon = {'Wood', type='resource'}, _skill = 'Woodcutting'},
['melvorF:Stone'] = {'Stone', type='resource'},
['melvorF:Stone'] = {_icon = {'Stone', type='resource'}, _skill = 'Mining'},
['melvorF:Ore'] = {'Iron Ore', type='rock'},
['melvorF:Ore'] = {_icon = {'Iron Ore', type='rock'}, _skill = 'Mining'},
['melvorF:Coal'] = {'Coal', type='resource'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'Mining'},
['melvorF:Bar'] = {'Iron Bar', type='item'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'Mining'},
['melvorF:Herbs'] = {'Garum Herb', type='item'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'Farming'},
['melvorF:Rune_Essence'] = {'Rune Essence', type='item'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'Mining'},
['melvorF:Leather'] = {'Leather', type='item'},
['melvorF:Leather'] = {_icon = {'Leather', type='item'}, _skill = nil},
['melvorF:Potions'] = {'Potion', type='resource'},
['melvorF:Potions'] = {_icon = {'Potion', type='resource'}, _skill = 'Herblore'},
['melvorF:Planks'] = {'Planks', type='resource'},
['melvorF:Planks'] = {_icon = {'Planks', type='resource'}, _skill = 'Woodcutting'},
['melvorF:Clothing'] = {'Leather Body', type='item'}
['melvorF:Clothing'] = {_icon = {'Leather Body', type='item'}, _skill = 'Crafting'}
}
}
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
resource._icon = resource_icons[resource.id]
resource._skill = resource_data[resource.id]._skill
resource._icon = resource_data[resource.id]._icon
resource._icon.notext = true
resource._icon.notext = true
resource._icon.nolink = true
resource._icon.nolink = true
end
end
 
return resources
return resources
end
end
Line 197: Line 202:
local resources = Data.Township.Resources()
local resources = Data.Township.Resources()
-- Get the list of convertable items, and calculate the exchange rate
-- Get the list of convertable items, and calculates each item's exchange rate
-- Also inserts the resource's assocaited skill
-- See township.js -> TownshipResource.buildResourceItemConversions for the calculation of valid items
-- See TownshipResource.buildResourceItemConversions for the list of valid items
local function matchFood(item)
return item.type == 'Food' and (not string.match(item.id, '_Perfect')) and item.category ~= 'Farming' and (not item.ignoreCompletion)
end
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
resource.itemConversions = {}
resource.itemConversions = {}
Line 205: Line 212:
-- No conversions
-- No conversions
elseif resource.id == 'melvorF:Food' then
elseif resource.id == 'melvorF:Food' then
resource._skill = 'Cooking'
resource.itemConversions = Shared.clone(GameData.getEntities('items', matchFood))
for _, food in ipairs(Data.Item.Match('type', 'Food')) do
if (not string.match(food.id, '_Perfect')) and food.category ~= 'Farming' and (not food.ignoreCompletion) then
table.insert(resource.itemConversions, food)
end
end
elseif resource.id == 'melvorF:Wood' or resource.id == 'melvorF:Planks' then
elseif resource.id == 'melvorF:Wood' or resource.id == 'melvorF:Planks' then
resource._skill = 'Woodcutting'
resource.itemConversions = Data.Item.Match('type', 'Logs')
resource.itemConversions = Data.Item.Match('type', 'Logs')
elseif resource.id == 'melvorF:Stone' or resource.id == 'melvorF:Ore' then
elseif resource.id == 'melvorF:Stone' or resource.id == 'melvorF:Ore' then
resource._skill = 'Mining'
for _, ore in ipairs(Data.Item.Match('type', 'Ore')) do
for _, ore in ipairs(Data.Item.Match('type', 'Ore')) do
if not string.match(ore.id, 'Meteorite_Ore') then
if not string.match(ore.id, 'Meteorite_Ore') then
Line 222: Line 222:
end
end
elseif resource.id == 'melvorF:Coal' then
elseif resource.id == 'melvorF:Coal' then
resource._skill = 'Mining'
local coal = 'melvorD:Coal_Ore'
local coal = 'melvorD:Coal_Ore'
table.insert(resource.itemConversions, Data.Item.ByID(coal))
table.insert(resource.itemConversions, Data.Item.ByID(coal))
elseif resource.id == 'melvorF:Bar' then
elseif resource.id == 'melvorF:Bar' then
resource._skill = 'Mining'
for _, bar in ipairs(Data.Item.Match('type', 'Ore')) do
for _, bar in ipairs(Data.Item.Match('type', 'Ore')) do
if not string.match(bar.id, 'Meteorite_Bar') then
if not string.match(bar.id, 'Meteorite_Bar') then
Line 233: Line 231:
end
end
elseif resource.id == 'melvorF:Herbs' then
elseif resource.id == 'melvorF:Herbs' then
resource._skill = 'Farming'
resource.itemConversions = Data.Item.Match('type', 'Herb')
resource.itemConversions = Data.Item.Match('type', 'Herb')
elseif resource.id == 'melvorF:Rune_Essence' then
elseif resource.id == 'melvorF:Rune_Essence' then
resource._skill = 'Mining'
local ressence = 'melvorD:Rune_Essence'
local ressence = 'melvorD:Rune_Essence'
local pessence = 'melvorTotH:Pure_Essence'
local pessence = 'melvorTotH:Pure_Essence'
Line 242: Line 238:
table.insert(resource.itemConversions, Data.Item.ByID(pessence))
table.insert(resource.itemConversions, Data.Item.ByID(pessence))
elseif resource.id == 'melvorF:Leather' then
elseif resource.id == 'melvorF:Leather' then
resource._skill = 'Crafting' -- Placeholder - actually no related skill to obtain
local leather = 'Leather'
local leather = 'Leather'
table.insert(resource.itemConversions, Data.Item.ByID(leather))
table.insert(resource.itemConversions, Data.Item.ByID(leather))
elseif resource.id == 'melvorF:Potions' then
elseif resource.id == 'melvorF:Potions' then
resource._skill = 'Herblore'
for _, potion in ipairs(Data.Item.Match('type', 'Potion')) do
for _, potion in ipairs(Data.Item.Match('type', 'Potion')) do
if string.match(potion.id, '_IV') then
if string.match(potion.id, '_IV') then
Line 253: Line 247:
end
end
elseif resource.id == 'melvorF:Clothing' then
elseif resource.id == 'melvorF:Clothing' then
resource._skill = 'Crafting'
local matches = {}
local matches = {}
table.insert(matches, Data.Item.Match('tier', 'Leather'))
table.insert(matches, Data.Item.Match('tier', 'Leather'))
Line 352: Line 345:
table.insert(ret_resource, '\r\n|style="text-align:left"|'..Icons.Icon({item.name, type='item', noicon=true}))
table.insert(ret_resource, '\r\n|style="text-align:left"|'..Icons.Icon({item.name, type='item', noicon=true}))
-- DLC
-- DLC
table.insert(ret_resource, '\r\n|style="text-align:center"|'..Data.PLACEHOLDER_NAMESPACE_ICON(item._namespace))
table.insert(ret_resource, '\r\n|style="text-align:center"|'..'XXX')
-- Level
-- Level
if required_level == nil then
if required_level == nil then
572

edits