16,254
edits
(Cleanup migrated functions) Tag: Manual revert |
(getRequirementString: Support requirement type MasteryLevel) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 14: | Line 14: | ||
local GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Num = require('Module:Number') | |||
-- getSkillName: Given a valid namespaced skill ID, returns that skill's name | -- getSkillName: Given a valid namespaced skill ID, returns that skill's name | ||
Line 30: | Line 31: | ||
end | end | ||
end | end | ||
end | |||
-- getSkillRecipeKey: Given a skill ID, returns the key under which all recipes | |||
-- for that skill reside. If the returned value is nil, then the skill has | |||
-- no recipes (that is, the skill does not produce any items) | |||
function p.getSkillRecipeKey(skillID) | |||
-- Convert skillID to local ID if not already | |||
local ns, localSkillID = Shared.getLocalID(skillID) | |||
local recipeIDs = { | |||
["Woodcutting"] = 'trees', | |||
["Fishing"] = 'fish', | |||
["Firemaking"] = 'logs', | |||
["Mining"] = 'rockData', | |||
["Thieving"] = 'npcs', | |||
["Agility"] = 'obstacles', | |||
["Cooking"] = 'recipes', | |||
["Smithing"] = 'recipes', | |||
["Farming"] = 'recipes', | |||
["Summoning"] = 'recipes', | |||
["Fletching"] = 'recipes', | |||
["Crafting"] = 'recipes', | |||
["Runecrafting"] = 'recipes', | |||
["Herblore"] = 'recipes', | |||
["Astrology"] = 'recipes', | |||
["Harvesting"] = 'veinData', | |||
["Township"] = 'buildings' | |||
} | |||
return recipeIDs[localSkillID] | |||
end | end | ||
Line 111: | Line 140: | ||
end | end | ||
-- | -- getPurchaseIconType: Given a purchase from shop dtaa, returns the icon type to be used within | ||
-- Icons.Icon() to retrieve the purchase's icon | |||
function p. | function p.getPurchaseIconType(purchase) | ||
local purchType = p.getPurchaseType(purchase) | local purchType = p.getPurchaseType(purchase) | ||
if purchType == 'Item Bundle' then | if purchType == 'Item Bundle' then | ||
local upgBundles = { | local upgBundles = { | ||
Line 125: | Line 151: | ||
'melvorAoD:Combat_Supply_I', | 'melvorAoD:Combat_Supply_I', | ||
'melvorAoD:Combat_Supply_II', | 'melvorAoD:Combat_Supply_II', | ||
'melvorAoD:Combat_Supply_III' | 'melvorAoD:Combat_Supply_III', | ||
'melvorItA:Abyssal_Resupply', | |||
'melvorItA:Blighted_Resupply', | |||
'melvorItA:Withering_Resupply' | |||
} | } | ||
if Shared.contains(upgBundles, purchase.id) then | if Shared.contains(upgBundles, purchase.id) then | ||
return 'upgrade' | |||
else | else | ||
return 'item' | |||
end | end | ||
else | else | ||
return string.lower(purchType) | |||
end | end | ||
end | |||
-- getPurchaseIcon: Accepts the same arguments as Icons.Icon(), except the first parameter is a | |||
-- shop purchase rather than the icon/linked page name | |||
function p.getPurchaseIcon(iconArgs) | |||
local purchase = iconArgs[1] | |||
local purchaseName = p.getPurchaseName(purchase) | |||
local iconType = p.getPurchaseIconType(purchase) | |||
-- Amend iconArgs before passing to Icons.Icon() | -- Amend iconArgs before passing to Icons.Icon() | ||
iconArgs[1] = purchaseName | iconArgs[1] = purchaseName | ||
Line 145: | Line 183: | ||
-- for those costs. If there are no costs, returns the value specified by valueIfNone instead. | -- for those costs. If there are no costs, returns the value specified by valueIfNone instead. | ||
-- Costs are in the format: | -- Costs are in the format: | ||
-- { items = { ... }, | -- { items = { ... }, currencies = { ... } } | ||
function p.getCostString(costs, valueIfNone) | function p.getCostString(costs, valueIfNone, entryDecorator, entrySeparator) | ||
local function formatLine(text) | |||
if entryDecorator == nil then | |||
return text | |||
else | |||
return entryDecorator(text) | |||
end | |||
end | |||
local entrySep = entrySeparator | |||
if type(entrySeparator) ~= 'string' then | |||
entrySep = '<br>' | |||
end | |||
local costArray = {} | local costArray = {} | ||
if type(costs.currencies) == 'table' and not Shared.tableIsEmpty(costs.currencies) then | |||
for i, currCost in ipairs(costs.currencies) do | |||
local currID = currCost.id or currCost.currencyID | |||
if currCost.min ~= nil then | |||
-- Cost is a range | |||
table.insert(costArray, formatLine(Icons._Currency(currID, currCost.min, currCost.max))) | |||
else | |||
table.insert(costArray, formatLine(Icons._Currency(currID, currCost.quantity))) | |||
end | |||
end | |||
end | |||
if type(costs.items) == 'table' and not Shared.tableIsEmpty(costs.items) then | if type(costs.items) == 'table' and not Shared.tableIsEmpty(costs.items) then | ||
for i, itemCost in ipairs(costs.items) do | for i, itemCost in ipairs(costs.items) do | ||
local item = GameData.getEntityByID('items', itemCost.id) | local item = GameData.getEntityByID('items', itemCost.id) | ||
if item ~= nil then | if item ~= nil then | ||
table.insert(costArray, Icons.Icon({item.name, type='item', qty=itemCost.quantity})) | table.insert(costArray, formatLine(Icons.Icon({item.name, type='item', qty=itemCost.quantity}))) | ||
end | end | ||
end | end | ||
end | end | ||
if Shared.tableIsEmpty(costArray) then | if Shared.tableIsEmpty(costArray) then | ||
return valueIfNone | return valueIfNone | ||
else | else | ||
return table.concat(costArray, | return table.concat(costArray, entrySep) | ||
end | end | ||
end | end | ||
Line 182: | Line 234: | ||
local reqArray = {} | local reqArray = {} | ||
for i, req in ipairs(reqs) do | for i, req in ipairs(reqs) do | ||
if req.type == 'AllSkillLevels' then | if req.type == 'AbyssalLevel' then | ||
local skillName = p.getSkillName(req.skillID) | |||
if skillName ~= nil then | |||
table.insert(reqArray, Icons._SkillReq(skillName, req.level, nil, 'melvorItA:Abyssal')) | |||
end | |||
elseif req.type == 'AbyssDepthCompletion' then | |||
local depth = GameData.getEntityByID('abyssDepths', req.depthID) | |||
if depth ~= nil then | |||
local depthStr = 'Complete ' .. Icons.Icon({depth.name, type='combatArea'}) | |||
if req.count > 1 then | |||
depthStr = depthStr .. ' ' .. Num.formatnum(req.count) .. ' times' | |||
end | |||
table.insert(reqArray, depthStr) | |||
end | |||
elseif req.type == 'AllSkillLevels' then | |||
local reqText = 'Level ' .. req.level .. ' in all skills' | local reqText = 'Level ' .. req.level .. ' in all skills' | ||
if req.exceptions ~= nil and not Shared.tableIsEmpty(req.exceptions) then | if req.exceptions ~= nil and not Shared.tableIsEmpty(req.exceptions) then | ||
Line 196: | Line 262: | ||
table.insert(reqArray, reqText) | table.insert(reqArray, reqText) | ||
elseif req.type == 'ArchaeologyItemsDonated' then | elseif req.type == 'ArchaeologyItemsDonated' then | ||
table.insert(reqArray, 'Donate ' .. | table.insert(reqArray, 'Donate ' .. Num.formatnum(req.count) .. ' Artefacts to the Museum in ' .. Icons.Icon({'Archaeology', type='skill'})) | ||
elseif req.type == 'CartographyPOIDiscovery' then | elseif req.type == 'CartographyPOIDiscovery' then | ||
local map = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, req.worldMapID) | local map = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, req.worldMapID) | ||
Line 221: | Line 287: | ||
local dungStr = 'Complete ' .. Icons.Icon({dung.name, type='dungeon'}) | local dungStr = 'Complete ' .. Icons.Icon({dung.name, type='dungeon'}) | ||
if req.count > 1 then | if req.count > 1 then | ||
dungStr = dungStr .. ' ' .. | dungStr = dungStr .. ' ' .. Num.formatnum(req.count) .. ' times' | ||
end | end | ||
table.insert(reqArray, dungStr) | table.insert(reqArray, dungStr) | ||
Line 229: | Line 295: | ||
if item ~= nil then | if item ~= nil then | ||
table.insert(reqArray, 'Find ' .. Icons.Icon({item.name, type='item'})) | table.insert(reqArray, 'Find ' .. Icons.Icon({item.name, type='item'})) | ||
end | |||
elseif req.type == 'MasteryLevel' then | |||
local skill = GameData.getSkillData(req.skillID) | |||
local recipeKey = p.getSkillRecipeKey(req.skillID) | |||
if skill ~= nil then | |||
local action = GameData.getEntityByID(skill[recipeKey], req.actionID) | |||
if action ~= nil then | |||
table.insert(reqArray, Icons._MasteryReq(action.name, req.level, true)) | |||
end | |||
end | end | ||
elseif req.type == 'MonsterKilled' then | elseif req.type == 'MonsterKilled' then | ||
Line 251: | Line 326: | ||
end | end | ||
elseif req.type == 'SlayerTask' then | elseif req.type == 'SlayerTask' then | ||
table.insert(reqArray, 'Complete ' .. | local taskCategory = GameData.getEntityByID('slayerTaskCategories', req.category) | ||
if taskCategory ~= nil then | |||
table.insert(reqArray, 'Complete ' .. Num.formatnum(req.count) .. ' ' .. taskCategory.name .. ' or higher Slayer Tasks') | |||
end | |||
elseif req.type == 'TownshipBuilding' then | elseif req.type == 'TownshipBuilding' then | ||
local tsData = GameData.getSkillData('melvorD:Township') | local tsData = GameData.getSkillData('melvorD:Township') | ||
Line 257: | Line 335: | ||
local building = GameData.getEntityByID(tsData.buildings, req.buildingID) | local building = GameData.getEntityByID(tsData.buildings, req.buildingID) | ||
if building ~= nil then | if building ~= nil then | ||
table.insert(reqArray, 'Have ' .. | table.insert(reqArray, 'Have ' .. Num.formatnum(req.count) .. ' ' .. building.name .. ' actively built in Township') | ||
end | end | ||
end | end | ||
elseif req.type == 'TownshipTask' then | elseif req.type == 'TownshipTask' then | ||
table.insert(reqArray, 'Complete ' .. | table.insert(reqArray, 'Complete ' .. Num.formatnum(req.count) .. ' Township Tasks') | ||
else | else | ||
table.insert(reqArray, Shared.printError('Unknown requirement: ' .. (req.type or 'nil'))) | table.insert(reqArray, Shared.printError('Unknown requirement: ' .. (req.type or 'nil'))) |