Module:Skills/Gathering: Difference between revisions

Fix tool tables, and refactor while we're at it
(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.getAxeTable(frame)
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, '_Axe$') ~= nil
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, searchString) ~= nil
end)
end)


local result = '{| class="wikitable"'
if skillName == nil or Shared.tableIsEmpty(toolArray) then
result = result..'\r\n!colspan="4"| !!colspan="2"|Cut Time Decrease'
return ''
result = result..'\r\n|- class="headerRow-0"'
end
result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Woodcutting', type='skill', notext=true})..' Level'
if modifiers == nil then
result = result..'!!Cost!!This Axe!!Total'
modifiers = {}
end
 
local modTotal = {}
for i, modDef in ipairs(modifiers) do
modTotal[modDef.name] = 0
end


local total = 0
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
result = result..'\r\n|-'
local toolName = Shop._getPurchaseName(tool)
result = result..'\r\n|style="min-width:25px" data-sort-value="'..tool.customName..'"|'..Icons.Icon({tool.customName, type='upgrade', size='50', notext=true})
local toolCost = Shop.getCostString(tool.cost, false)
result = result..'||'..tool.customName
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
--Gonna be lazy and assume there's only the one skill level and it's the one we care about
for i, purchReq in ipairs(tool.purchaseRequirements) do
level = tool.unlockRequirements.skillLevel[1].level
if purchReq.type == 'SkillLevel' and purchReq.skillID == skillID then
level = purchReq.level
break
end
end
end
end
result = result..'||style="text-align:right"|'..level
table.insert(resultPart, '\r\n|style="text-align:right"| '..level)
result = result..'||style="text-align:right" data-sort-value="'..tool.cost.gp..'"|'..Icons.GP(tool.cost.gp)
table.insert(resultPart, '\r\n|style="text-align:right" data-sort-value="' .. toolCostSort .. '"| ' .. toolCost)


-- TODO TotH tools have other modifiers which should be included
local cellStart = '\r\n|style="text-align:right"| '
local cutTime = 0
if tool.contains ~= nil and tool.contains.modifiers ~= nil then
if tool.contains.modifiers.decreasedSkillIntervalPercent ~= nil then
for j, modDef in ipairs(modifiers) do
cutTime = tool.contains.modifiers.decreasedSkillIntervalPercent[1].value
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
total = total + cutTime
result = result..'||style="text-align:right"|-'..cutTime..'%'
result = result..'||style="text-align:right"|-'..total..'%'
end
end


result = result..'\r\n|}'
table.insert(resultPart, '\r\n|}')
return result
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 toolArray = Shop.getPurchases(
local modifiers = {
function(purch)
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '-', suffix = '%' },
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, '_Pickaxe$') ~= nil
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' },
end)
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' },
 
{ name = 'increasedChanceForQualitySuperiorGem', header = 'Superior Gem Chance', sign = '+', suffix = '%' },
local result = '{| class="wikitable"'
{ name = 'increasedMeteoriteOre', header = 'Increased ' .. Icons.Icon({'Meteorite Ore', type='item', notext=true}), sign = '+', suffix = '' }
result = result..'\r\n!colspan="4"| !!colspan="2"|Mine Time Decrease!!colspan="2"|2x Ore Chance'
}
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Mining', type='skill', notext=true})..' Level'
result = result..'!!Cost!!This Pick!!Total!!This Pick!!Total'
 
local total = 0
local total2 = 0
 
for i, tool in ipairs(toolArray) do
result = result..'\r\n|-'
result = result..'\r\n|style="min-width:25px" data-sort-value="'..tool.customName..'"|'..Icons.Icon({tool.customName, type='upgrade', size='50', notext=true})
result = result..'||'..tool.customName
local level = 1
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then
--Gonna be lazy and assume there's only the one skill level and it's the one we care about
level = tool.unlockRequirements.skillLevel[1].level
end
result = result..'||style="text-align:right"|'..level
result = result..'||style="text-align:right" data-sort-value="'..tool.cost.gp..'"|'..Icons.GP(tool.cost.gp)
 
-- TODO TotH tools have other modifiers which should be included
local cutTime = 0
if tool.contains.modifiers.decreasedSkillIntervalPercent ~= nil then
cutTime = tool.contains.modifiers.decreasedSkillIntervalPercent[1].value
end
total = total + cutTime
 
result = result..'||style="text-align:right"|-'..cutTime..'%'
result = result..'||style="text-align:right"|-'..total..'%'
 
local OreDouble = (tool.contains.modifiers.increasedChanceToDoubleOres or 0)
total2 = total2 + OreDouble
 
result = result..'||style="text-align:right"|+'..OreDouble..'%'
result = result..'||style="text-align:right"|+'..total2..'%'
end


result = result..'\r\n|}'
return p.getToolTable('_Pickaxe$', modifiers, 'melvorD:Mining')
return result
end
end


function p.getRodTable(frame)
function p.getRodTable(frame)
local toolArray = Shop.getPurchases(
local modifiers = {
function(purch)
{ name = 'decreasedSkillIntervalPercent', header = 'Catch Time Decrease', sign = '-', suffix = '%' },
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, '_Fishing_Rod$') ~= nil
{ name = 'increasedChanceForOneExtraFish', header = '+1 Fish Chance', sign = '+', suffix = '%' },
end)
{ name = 'increasedChanceToFindLostChest', header = Icons.Icon({'Lost Chest', type='item', notext=true}) .. ' Chance', sign = '+', suffix = '%' },
 
{ name = 'increasedFishingCookedChance', header = 'Cooked Fish Chance', sign = '+', suffix = '%' }
local result = '{| class="wikitable"'
}
result = result..'\r\n!colspan="4"| !!colspan="2"|Catch Time Decrease'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Fishing', type='skill', notext=true})..' Level'
result = result..'!!Cost!!This Rod!!Total'
 
local total = 0
 
for i, tool in Shared.skpairs(toolArray) do
result = result..'\r\n|-'
result = result..'\r\n|style="min-width:25px" data-sort-value="'..tool.customName..'"|'..Icons.Icon({tool.customName, type='upgrade', size='50', notext=true})
result = result..'||'..tool.customName
local level = 1
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then
--Gonna be lazy and assume there's only the one skill level and it's the one we care about
level = tool.unlockRequirements.skillLevel[1].level
end
result = result..'||style="text-align:right"|'..level
result = result..'||style="text-align:right" data-sort-value="'..tool.cost.gp..'"|'..Icons.GP(tool.cost.gp)
 
-- TODO TotH tools have other modifiers which should be included
local cutTime = 0
if tool.contains.modifiers.decreasedSkillIntervalPercent ~= nil then
cutTime = tool.contains.modifiers.decreasedSkillIntervalPercent[1].value
end
total = total + cutTime
result = result..'||style="text-align:right"|-'..cutTime..'%'
result = result..'||style="text-align:right"|-'..total..'%'
end


result = result..'\r\n|}'
return p.getToolTable('_Rod$', modifiers, 'melvorD:Fishing')
return result
end
end