Anonymous

Module:Common: Difference between revisions

From Melvor Idle
Update for v1.3
(Move getSkillRecipeKey from other modules)
(Update for v1.3)
Line 54: Line 54:
["Herblore"] = 'recipes',
["Herblore"] = 'recipes',
["Astrology"] = 'recipes',
["Astrology"] = 'recipes',
["Harvesting"] = 'veinData'
["Harvesting"] = 'veinData',
["Township"] = 'buildings'
}
}
return recipeIDs[localSkillID]
return recipeIDs[localSkillID]
Line 172: Line 173:
-- 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 = { ... }, gp = 0, sc = 0, rc = 0 }
-- { 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
if costs.gp ~= nil and costs.gp > 0 then
table.insert(costArray, Icons.GP(costs.gp))
end
if costs.sc ~= nil and costs.sc > 0 then
table.insert(costArray, Icons.SC(costs.sc))
end
if costs.rc ~= nil and costs.rc > 0 then
table.insert(costArray, Icons.RC(costs.rc))
end
end
if Shared.tableIsEmpty(costArray) then
if Shared.tableIsEmpty(costArray) then
return valueIfNone
return valueIfNone
else
else
return table.concat(costArray, '<br/>')
return table.concat(costArray, entrySep)
end
end
end
end
Line 209: Line 224:
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._AbyssalSkillReq(skillName, req.level))
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='abyssDepth'})
if req.count > 1 then
depthStr = depthStr .. ' ' .. Shared.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 278: Line 307:
end
end
elseif req.type == 'SlayerTask' then
elseif req.type == 'SlayerTask' then
table.insert(reqArray, 'Complete ' .. Shared.formatnum(req.count) .. ' ' .. req.tier .. ' Slayer Tasks')
local taskCategory = GameData.getEntityByID('slayerTaskCategories', req.category)
if taskCategory ~= nil then
table.insert(reqArray, 'Complete ' .. Shared.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')