17,101
edits
(Update for v1.1) |
(Fix tool tables, and refactor while we're at it) |
||
Line 13: | Line 13: | ||
-- TODO Move tool tables to Module:Shop | -- TODO Move tool tables to Module:Shop | ||
function p. | function p.getToolTable(searchString, modifiers, skillID) | ||
local skillName = Constants.getSkillName(skillID) | |||
local toolArray = Shop.getPurchases( | local toolArray = Shop.getPurchases( | ||
function(purch) | function(purch) | ||
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, | return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, searchString) ~= nil | ||
end) | end) | ||
if skillName == nil or Shared.tableIsEmpty(toolArray) then | |||
return '' | |||
end | |||
if modifiers == nil then | |||
modifiers = {} | |||
end | |||
local modTotal = {} | |||
for i, modDef in ipairs(modifiers) do | |||
modTotal[modDef.name] = 0 | |||
end | |||
local | local headerRowSpan = (Shared.tableIsEmpty(toolArray) and 1) or 2 | ||
local resultPart = {} | |||
table.insert(resultPart, '{| class="wikitable"') | |||
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '" colspan="2"| Name') | |||
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '"| ' .. Icons.Icon({skillName, type='skill', notext=true})..' Level') | |||
table.insert(resultPart, '\r\n!rowspan="' .. headerRowSpan .. '"| Cost') | |||
for i, modDef in ipairs(modifiers) do | |||
modTotal[modDef.name] = 0 | |||
table.insert(resultPart, '\r\n!colspan="2"| ' .. modDef.header) | |||
end | |||
if headerRowSpan > 1 then | |||
table.insert(resultPart, '\r\n|-' .. string.rep('\r\n!This Axe\r\n!Total', Shared.tableCount(modifiers))) | |||
end | |||
for i, tool in ipairs(toolArray) do | for i, tool in ipairs(toolArray) do | ||
local toolName = Shop._getPurchaseName(tool) | |||
local toolCost = Shop.getCostString(tool.cost, false) | |||
local toolCostSort = Shop._getPurchaseSortValue(tool) | |||
table.insert(resultPart, '\r\n|-') | |||
table.insert(resultPart, '\r\n|style="min-width:25px" data-sort-value="' .. toolName .. '"| ' .. Icons.Icon({toolName, type='upgrade', size='50', notext=true})) | |||
table.insert(resultPart, '\r\n| ' .. toolName) | |||
local level = 1 | local level = 1 | ||
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then | if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then | ||
for i, purchReq in ipairs(tool.purchaseRequirements) do | |||
if purchReq.type == 'SkillLevel' and purchReq.skillID == skillID then | |||
level = purchReq.level | |||
break | |||
end | |||
end | |||
end | end | ||
table.insert(resultPart, '\r\n|style="text-align:right"| '..level) | |||
table.insert(resultPart, '\r\n|style="text-align:right" data-sort-value="' .. toolCostSort .. '"| ' .. toolCost) | |||
local cellStart = '\r\n|style="text-align:right"| ' | |||
local | if tool.contains ~= nil and tool.contains.modifiers ~= nil then | ||
if tool.contains.modifiers | for j, modDef in ipairs(modifiers) do | ||
local modName = modDef.name | |||
local modVal = tool.contains.modifiers[modName] | |||
if modVal ~= nil then | |||
if type(modVal) == 'table' and type(modVal[1]) == 'table' and modVal[1].skillID ~= nil then | |||
modVal = modVal[1].value | |||
end | |||
modTotal[modName] = modTotal[modName] + modVal | |||
else | |||
modVal = 0 | |||
end | |||
table.insert(resultPart, cellStart .. (modVal == 0 and '' or modDef.sign) .. modVal .. modDef.suffix) | |||
table.insert(resultPart, cellStart .. (modTotal[modName] == 0 and '' or modDef.sign) .. modTotal[modName] .. modDef.suffix) | |||
end | |||
end | end | ||
end | end | ||
table.insert(resultPart, '\r\n|}') | |||
return | return table.concat(resultPart) | ||
end | |||
function p.getAxeTable(frame) | |||
local modifiers = { | |||
{ name = 'decreasedSkillIntervalPercent', header = 'Cut Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceToDoubleItemsSkill', header = 'Double Items Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedBirdNestDropRate', header = Icons.Icon({'Bird Nest', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' }, | |||
{ name = 'increasedChanceForAshInWoodcutting', header = Icons.Icon({'Ash', 'Drop Chance', type='item', nolink=true}), sign = '+', suffix = '%' } | |||
} | |||
return p.getToolTable('_Axe$', modifiers, 'melvorD:Woodcutting') | |||
end | end | ||
function p.getPickaxeTable(frame) | function p.getPickaxeTable(frame) | ||
local | local modifiers = { | ||
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedChanceForQualitySuperiorGem', header = 'Superior Gem Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedMeteoriteOre', header = 'Increased ' .. Icons.Icon({'Meteorite Ore', type='item', notext=true}), sign = '+', suffix = '' } | |||
} | |||
return p.getToolTable('_Pickaxe$', modifiers, 'melvorD:Mining') | |||
end | end | ||
function p.getRodTable(frame) | function p.getRodTable(frame) | ||
local | local modifiers = { | ||
{ name = 'decreasedSkillIntervalPercent', header = 'Catch Time Decrease', sign = '-', suffix = '%' }, | |||
{ name = 'increasedChanceForOneExtraFish', header = '+1 Fish Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedChanceToFindLostChest', header = Icons.Icon({'Lost Chest', type='item', notext=true}) .. ' Chance', sign = '+', suffix = '%' }, | |||
{ name = 'increasedFishingCookedChance', header = 'Cooked Fish Chance', sign = '+', suffix = '%' } | |||
} | |||
return p.getToolTable('_Rod$', modifiers, 'melvorD:Fishing') | |||
end | end | ||