Module:Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 100: Line 100:
-- Returns the recipe for the item of a desired skill.
-- Returns the recipe for the item of a desired skill.
function Data.Item.FindRecipes(itemid, skill)
function Data.Item.FindRecipes(itemid, skill)
-- No skill? No recipes
if skill == nil then
return {}
end
-- the key name for each skill in the json file
-- the key name for each skill in the json file
local skill_recipe_keys = {
local skill_recipe_keys = {
Woodcutting = {recipes='trees', productID='productId'}, -- lowercase "d"
['melvorD:Woodcutting'] = {recipes='trees', productID='productId'}, -- lowercase "d"
Fishing = {recipes='fish', productID='productId'}, -- lowercase "d"
['melvorD:Fishing'] = {recipes='fish', productID='productId'}, -- lowercase "d"
Cooking = {recipes='recipes', productID='productID'},
['melvorD:Cooking'] = {recipes='recipes', productID='productID'},
Mining = {recipes='rockData', productID='productId'}, -- lowercase "d"
['melvorD:Mining'] = {recipes='rockData', productID='productId'}, -- lowercase "d"
Smithing = {recipes='recipes', productID='productID'},
['melvorD:Smithing'] = {recipes='recipes', productID='productID'},
Farming = {recipes='recipes', productID='productId'}, -- lowercase "d"
['melvorD:Farming'] = {recipes='recipes', productID='productId'}, -- lowercase "d"
Summoning = {recipes='recipes', productID='productID'},
['melvorD:Summoning'] = {recipes='recipes', productID='productID'},
Fletching = {recipes='recipes', productID='productID'},
['melvorD:Fletching'] = {recipes='recipes', productID='productID'},
Crafting = {recipes='recipes', productID='productID'},
['melvorD:Crafting'] = {recipes='recipes', productID='productID'},
Runecrafting = {recipes='recipes', productID='productID'},
['melvorD:Runecrafting'] = {recipes='recipes', productID='productID'},
Herblore = {recipes='recipes', productID='potionIDs'} -- Special case potions I-IV
['melvorD:Herblore'] = {recipes='recipes', productID='potionIDs'} -- Special case potions I-IV
--[[ Excluded skills:
--[[ Excluded skills:
Attack, Strength, Defence, Magic, Ranged, Prayer, Slayer
Attack, Strength, Defence, Magic, Ranged, Prayer, Slayer
Line 118: Line 124:
}
}


local item = Data.splitID(itemid)
local results = {}
local results = {}
if skill == nil then
local SkillData = GameData.getSkillData(skill)
return results
local recipes = skill_recipe_keys[skill].recipes
end
local productID = skill_recipe_keys[skill].productID
-- Find the recipe at data.data.skillData -> SKILL.data.KEY
if SkillData[recipes] ~= nil then
for namespace, data in pairs(Namespaces) do
for _, recipe in ipairs(SkillData[recipes]) do
-- We match multiple entries because there's a bug - melvorF -> skillData Farming has two duplicate entries in the array with differing info
-- Special case for Herblore
local Skill_matches = Data.tableMatches(data.data.skillData, 'skillID', 'melvorD:'..skill)
if skill == 'Herblore' then
for _, Skill in ipairs(Skill_matches) do
-- Iterate over the 4 potion tiers
local key = skill_recipe_keys[skill]
for _, potion in ipairs(recipe[productID]) do
if Skill ~= nil and Skill.data ~= nil and Skill.data[key.recipes] ~= nil then
if itemid == potion.id then
for _, recipe in ipairs(Skill.data[key.recipes]) do
table.insert(results, Shared.clone(recipe))
-- Check if id matches
if skill == 'Herblore' then
-- Iterate over the 4 potion tiers
for _, potion in ipairs(recipe[key.productID]) do
-- Same as below
local recipe_id = Data.splitID(potion)
if item.id == recipe_id.id then
local recipecopy = Shared.clone(recipe)
recipecopy._namespace = namespace
table.insert(results, recipecopy)
end
end
else
-- Same as above
local recipe_id = Data.splitID(recipe[key.productID])
if item.id == recipe_id.id then
local recipecopy = Shared.clone(recipe)
recipecopy._namespace = namespace
table.insert(results, recipecopy)
end
end
end
end
-- Base case
else
if itemid == recipe[productID] then
table.insert(results, Shared.clone(recipe))
end
end
end
end
end
end
end
end
return results
return results
end
end
Line 174: Line 165:
local resource_data = {
local resource_data = {
['melvorF:GP'] = {_icon = {'Coins'}, _skill = nil},
['melvorF:GP'] = {_icon = {'Coins'}, _skill = nil},
['melvorF:Food'] = {_icon = {'Raw Beef', type='item'}, _skill = 'Cooking'},
['melvorF:Food'] = {_icon = {'Raw Beef', type='item'}, _skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {_icon = {'Wood', type='resource'}, _skill = 'Woodcutting'},
['melvorF:Wood'] = {_icon = {'Wood', type='resource'}, _skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {_icon = {'Stone', type='resource'}, _skill = 'Mining'},
['melvorF:Stone'] = {_icon = {'Stone', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Ore'] = {_icon = {'Iron Ore', type='rock'}, _skill = 'Mining'},
['melvorF:Ore'] = {_icon = {'Iron Ore', type='rock'}, _skill = 'melvorD:Mining'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'Mining'},
['melvorF:Coal'] = {_icon = {'Coal', type='resource'}, _skill = 'melvorD:Mining'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'Mining'},
['melvorF:Bar'] = {_icon = {'Iron Bar', type='item'}, _skill = 'melvorD:Mining'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'Farming'},
['melvorF:Herbs'] = {_icon = {'Garum Herb', type='item'}, _skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'Mining'},
['melvorF:Rune_Essence'] = {_icon = {'Rune Essence', type='item'}, _skill = 'melvorD:Mining'},
['melvorF:Leather'] = {_icon = {'Leather', type='item'}, _skill = nil},
['melvorF:Leather'] = {_icon = {'Leather', type='item'}, _skill = nil},
['melvorF:Potions'] = {_icon = {'Potion', type='resource'}, _skill = 'Herblore'},
['melvorF:Potions'] = {_icon = {'Potion', type='resource'}, _skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {_icon = {'Planks', type='resource'}, _skill = 'Woodcutting'},
['melvorF:Planks'] = {_icon = {'Planks', type='resource'}, _skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {_icon = {'Leather Body', type='item'}, _skill = 'Crafting'}
['melvorF:Clothing'] = {_icon = {'Leather Body', type='item'}, _skill = 'melvorD:Crafting'}
}
}
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
Line 334: Line 325:
-- Get the skill based on the item.id or else use the resource's default skill
-- Get the skill based on the item.id or else use the resource's default skill
local skill_overrides = {
local skill_overrides = {
['melvorD:Raw_Magic_Fish'] = 'Fishing',
['melvorD:Raw_Magic_Fish'] = 'melvorD:Fishing',
['melvorF:Apple'] = 'Farming',
['melvorF:Apple'] = 'melvorD:Farming',
}
}
local skill = skill_overrides[item.id] or resource._skill
local skill = skill_overrides[item.id] or resource._skill
Line 375: Line 366:
-- Value/Resource
-- Value/Resource
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor/item.fromTownship .. '"|'..Icons.GP(Shared.round(item.sellsFor/item.fromTownship, 2, 2)))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor/item.fromTownship .. '"|'..Icons.GP(Shared.round(item.sellsFor/item.fromTownship, 2, 2)))
if resource.id =='Food' then
if resource.id =='melvorF:Food' then
-- Heals
-- Heals
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10 .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.formatnum(item.healsFor*10))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10 .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.formatnum(item.healsFor*10))
572

edits