Anonymous

Module:Shop: Difference between revisions

From Melvor Idle
4,560 bytes added ,  14 November 2022
getToolTable: Move from Module:Skills/Gathering; getCookingUtilityTable: Use getToolTable & implement additional modifier columns
(p.getCookingUtilityTable -> Fix increasedChanceToDoubleItemsSkill modifier which was always showing 0%. We still need to add increasedChanceToDoubleItemsSkill to Cooking Fire, decreasedPassiveCookInterval/decreasedSkillIntervalPercent to all 3 types and increasedChanceAdditionalSkillResource to non-Cooking Fire)
(getToolTable: Move from Module:Skills/Gathering; getCookingUtilityTable: Use getToolTable & implement additional modifier columns)
Line 823: Line 823:
end
end


function p.getCookingUtilityTable(frame)
function p.getToolTable(toolName, searchString, modifiers, skillID)
local category = nil
local skillName = nil
if frame ~= nil then category = frame.args ~= nil and frame.args[1] or frame end
if type(skillID) == 'string' then
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'}
skillName = Constants.getSkillName(skillID)
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then
end
return 'ERROR: Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or ')
local toolArray = p.getPurchases(
function(purch)
return purch.category == 'melvorD:SkillUpgrades' and string.find(purch.id, searchString) ~= nil
end)
 
if Shared.tableIsEmpty(toolArray) then
return ''
end
if modifiers == nil then
modifiers = {}
end
end
 
local categoryShort = string.match(category, '[^%s]+$')
local modTotal = {}
local bonusSkillID = Constants.getSkillID('Cooking')
for i, modDef in ipairs(modifiers) do
local bonusColMod, bonusColName = nil, nil
modTotal[modDef.name] = 0
if category == 'Cooking Fire' then
bonusColMod = 'increasedSkillXP'
bonusColName = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP'
else
bonusColMod = 'increasedChanceToDoubleItemsSkill'
bonusColName = 'Double Items Chance'
end
end
local modsPerfectChance = {'increasedChancePerfectCookFire', 'increasedChancePerfectCookFurnace',
 
'increasedChancePerfectCookPot', 'increasedChancePerfectCookGlobal'}
local headerRowSpan = (Shared.tableIsEmpty(toolArray) and 1) or 2
local totalBonusVal, totalPerfectChance = 0, 0
local utilityList = p.getPurchases(function(purch) return purch.category == 'melvorD:SkillUpgrades' and string.find(p._getPurchaseName(purch), category .. '$') ~= nil end)
local resultPart = {}
local resultPart = {}
table.insert(resultPart, '{| class="wikitable"')
-- Table header
table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '" colspan="2"| Name')
table.insert(resultPart, '{| class="wikitable stickyHeader"')
table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '"| ' .. (skillName == nil and 'Requirements' or Icons.Icon({skillName, type='skill', notext=true}) .. ' Level'))
table.insert(resultPart, '|- class="headerRow-0"')
table.insert(resultPart, '\n!rowspan="' .. headerRowSpan .. '"| Cost')
table.insert(resultPart, '!colspan="4"| !!colspan="2"|' .. bonusColName .. '!!colspan="2"|Bonus Perfect Chance')
for i, modDef in ipairs(modifiers) do
table.insert(resultPart, '|- class="headerRow-1"')
modTotal[modDef.name] = 0
table.insert(resultPart, '!colspan="2"|Name!!Level!!Cost' .. string.rep('!!This ' .. categoryShort .. '!!Total', 2))
table.insert(resultPart, '\n!colspan="2"| ' .. modDef.header)
end
if headerRowSpan > 1 then
table.insert(resultPart, '\n|-' .. string.rep('\n!This ' .. toolName .. '\n!Total', Shared.tableCount(modifiers)))
end
 
for i, tool in ipairs(toolArray) do
local toolName = p._getPurchaseName(tool)
local toolCost = p.getCostString(tool.cost, false)
local toolCostSort = p._getPurchaseSortValue(tool) or 0
table.insert(resultPart, '\n|-')
table.insert(resultPart, '\n|style="min-width:25px" data-sort-value="' .. toolName .. '"| ' .. Icons.Icon({toolName, type='upgrade', size='50', notext=true}))
table.insert(resultPart, '\n| data-sort-value="' .. toolName.. '"|' .. Icons.getExpansionIcon(tool.id) .. toolName)
local level, levelStyle = nil, nil
if skillID == nil then
level = 'None'
levelStyle = '|class="table-na"'
else
level = 1
levelStyle = '|style="text-align:right"'
end
if tool.purchaseRequirements ~= nil and not Shared.tableIsEmpty(tool.purchaseRequirements) then
if skillID == nil then
-- Return all requirements
level = p.getRequirementString(tool.purchaseRequirements)
if level ~= 'None' then
levelStyle = ''
end
else
-- Return level requirement for just the specified skill
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, '\n' .. levelStyle .. '| '..level)
table.insert(resultPart, '\n|style="text-align:right" data-sort-value="' .. toolCostSort .. '"| ' .. toolCost)


-- Row for each upgrade
local cellStart = '\n|style="text-align:right"'
for i, utility in ipairs(utilityList) do
if tool.contains ~= nil and tool.contains.modifiers ~= nil then
        local utilityName = p._getPurchaseName(utility)
for j, modDef in ipairs(modifiers) do
-- First determine bonus XP/doubling chance and perfect chance
local modName = modDef.name
local bonusVal, perfectChance = 0, 0
local modVal = tool.contains.modifiers[modName]
if type(utility.contains) == 'table' then
if modVal ~= nil then
if type(utility.contains.modifiers) == 'table' then
if type(modVal) == 'table' and type(modVal[1]) == 'table' and modVal[1].skillID ~= nil and (modDef.skillID == nil or modDef.skillID == modVal[1].skillID) then
for modName, modVal in pairs(utility.contains.modifiers) do
modVal = modVal[1].value
if modName == bonusColMod and type(modVal) == 'table' then
-- Bonus XP/doubling
for _, subMod in ipairs(modVal) do
if subMod.skillID ~= nil and subMod.skillID == bonusSkillID then
bonusVal = bonusVal + subMod.value
end
end
elseif Shared.contains(modsPerfectChance, modName) then
-- Perfect chance
perfectChance = perfectChance + modVal
end
end
modTotal[modName] = modTotal[modName] + modVal
else
modVal = 0
end
end
local cellStartVal = cellStart .. ((modVal == 0 and ' class="table-na"') or '')
local cellStartTot = cellStart .. ((modTotal[modName] == 0 and ' class="table-na"') or '')
table.insert(resultPart, cellStartVal .. '| ' .. (modVal == 0 and '' or modDef.sign) .. modVal .. modDef.suffix)
table.insert(resultPart, cellStartTot .. '| ' .. (modTotal[modName] == 0 and '' or modDef.sign) .. modTotal[modName] .. modDef.suffix)
end
end
end
end
totalBonusVal = totalBonusVal + bonusVal
end
totalPerfectChance = totalPerfectChance + perfectChance
 
table.insert(resultPart, '\n|}')
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', '_Axe$', modifiers, 'melvorD:Woodcutting')
end


table.insert(resultPart, '|-')
function p.getPickaxeTable(frame)
table.insert(resultPart, '|style="min-width:25px"|' .. Icons.Icon({utilityName, type='upgrade', size='50', notext=true}))
local modifiers = {
table.insert(resultPart, '|data-sort-value="'..utilityName..'|'..p._getPurchaseExpansionIcon(utility) .. utilityName)
{ name = 'decreasedSkillIntervalPercent', header = 'Mining Time Decrease', sign = '-', suffix = '%' },
table.insert(resultPart, '|style="text-align:right"|' .. p.getRequirementString(utility.purchaseRequirements))
{ name = 'increasedChanceToDoubleOres', header = '2x Ore Chance', sign = '+', suffix = '%' },
table.insert(resultPart, '|style="text-align:right"|' .. p.getCostString(utility.cost, false))
{ name = 'increasedChanceForOneExtraOre', header = '+1 Ore Chance', sign = '+', suffix = '%' },
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. bonusVal .. '%')
{ name = 'increasedChanceForQualitySuperiorGem', header = 'Superior Gem Chance', sign = '+', suffix = '%' },
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalBonusVal .. '%')
{ name = 'increasedMeteoriteOre', header = 'Increased ' .. Icons.Icon({'Meteorite Ore', type='item', notext=true}), sign = '+', suffix = '' }
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. perfectChance .. '%')
}
table.insert(resultPart, '|style="text-align:right"|' .. '+' .. totalPerfectChance .. '%')
 
return p.getToolTable('Pickaxe', '_Pickaxe$', modifiers, 'melvorD:Mining')
end
 
function p.getRodTable(frame)
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', '_Rod$', modifiers, 'melvorD:Fishing')
end
 
function p.getCookingUtilityTable(frame)
local category = nil
if frame ~= nil then category = frame.args ~= nil and frame.args[1] or frame end
local validCategories = {'Cooking Fire', 'Furnace', 'Pot'}
if category == nil or not Shared.contains({'Cooking Fire', 'Furnace', 'Pot'}, category) then
return 'ERROR: Invalid category specified. Must be one of the following: ' .. mw.text.listToText(validCategories, ', ', ' or ')
end
end
table.insert(resultPart, '|}')


return table.concat(resultPart, '\r\n')
local categoryShort = string.match(category, '[^%s]+$')
local modifiers = {
['Cooking Fire'] = {
{ name = 'increasedSkillXP', skillID = 'melvorD:Cooking', header = 'Bonus ' .. Icons.Icon({'Cooking', type='skill', notext=true}) .. ' XP', sign = '+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChancePerfectCookFire', header = 'Fire Perfect Cook Chance', sign ='+', suffix = '%' },
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' }
},
['Furnace'] = {
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' }
},
['Pot'] = {
{ name = 'increasedChanceToDoubleItemsSkill', skillID = 'melvorD:Cooking', header = '2x Items Chance', sign = '+', suffix = '%' },
{ name = 'decreasedPassiveCookInterval', header = 'Passive Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'decreasedSkillIntervalPercent', skillID = 'melvorD:Cooking', header = 'Active Cook Time Decrease', sign = '-', suffix = '%' },
{ name = 'increasedChanceAdditionalSkillResource', skillID = 'melvorD:Cooking', header = '+1 Item Chance', sign = '+', suffix = '%' }
}
}
 
return p.getToolTable(categoryShort, categoryShort .. '$', modifiers[category], nil)
end
end


return p
return p